There are plenty of articles on the installation of a DS1307 RTC module.

There are equally as many articles listing various installation/configuration problems.

The basic hardware issues relates to signal voltage difference on I2C bus, the Pi uses 3.3V whereas the DS1307 module uses 5V. You may decide to remove the pulp resistors from the DS1307.
Same DS1307 modules cater for both, a CR2032 battery and a rechargeable battery. You may have to remove the charge resistor if you are using a non-rechargeable battery. 

The article describes the configuration steps for systemd based Raspbian (not Wheezy or anything earlier)
Thanks to KD8TWG and Adafruit for some of the information shown on this page.

Step 1 - edit /boot/config.txt and add

dtoverlay=i2c-rtc,ds1307

You should also ensure that the I2C bus is enabled (dtparam=i2c_arm=on) in config.txt.

Step 2 - execute "i2cdetect -y 1"

You should see "UU" at address 0x68. you may also see "50" if the RTC module contains an EEPROM chip.

Step 3 - disable fake hwclock

apt-get -y remove fake-hwclock
update-rc.d -f fake-hwclock remove
systemctl disable fake-hwclock

Step 4 - change /lib/udev/hwclock-set by commenting out the following lines:

#if [ -e /run/systemd/system ] ; then
#    exit 0
#fi

also comment out these lines: 

#/sbin/hwclock --rtc=$dev --systz --badyear
#/sbin/hwclock --rtc=$dev --systz 

Step 5 - timesyncd service which must be disabled or the system clock will not be synced to RTC module on boot.

systemctl stop systemd-timesyncd.service
systemctl disable systemd-timesyncd.service

To set the correct time:

Sync system time (e.g. via ntp)
then use "hwclock -w" to write system time to RTC module

The RTC clock can be read at any time with "hwclock -r" and the system time can be synced to the RTC time with "hwclock -s".

For more information on the hwclock command: "man hwclock"

 

 

The Official Raspberry Pi 7" Touchscreen is very cost effective device which can turn a RaPi into a very sophisticated GUI for all sorts of home projects.

This article is about using the touchscreen as a dedicated interface to home-brew code on a head-less RaPi, that is, a Pi which does not utilise the X-Windows GUI.

After a bit of research I have found a great library which provides elegant user interface objects, it's called LittlevGL and comes free of charge. The library is written in C and designed to work with embedded devices. Here is a link to the library website.

The library comes with pretty good install instructions and it's easy to get the demo graphics to display.

I have followed these steps and added the Makefile from the pc_simulator project on GitHub.

The LCD interface of the screen is connected to the onboard DSI connector and the driver is already part of Raspbian and LittlevGL uses the frame buffer device /dev/fb0 to drive the screen. 
The touch interface is connected to the RaPi via I2C interface but Raspbian provides the hardware level interface and presents the touch events at /dev/input/event0.

The following settings are required in the config files:

lv_conf.h 

#define LV_HOR_RES (800)
#define LV_VER_RES (480)
#define LV_COLOR_DEPTH 24 

lv_drv_config.h:

#define USE_FBDEV 1
#define FBDEV_PATH "/dev/fb0"
#define USE_EVDEV 1
#define EVDEV_NAME "/dev/input/event0"

lv_ex_conf.h:

#define USE_LV_DEMO 1

This should sufficient to get the screen output working. First with the "Hello World" example and then with the demo_create() function. 
To get touch input working add the following lines after lv_init() in main().

evdev_init();
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read = evdev_read;
lv_indev_drv_register(&indev_drv);

The porting guide provides some information on adding touch input but is missing a couple of very crucial bits of information.

With those modifications the touch screen should now be functional.

One final step is required to eliminate the blinking cursor which keep re-appearing on the screen:

add the following into /boot/cmdline.txt

vt.global_cursor_default=0 

 

Many of my RaPi's are configured for a daily reboot to increase reliability. Despite many precautions and care being taken during coding some programs (including mine) suffer from [minor] memory leaks. Whilst these leaks don't cause any immediate issues, if the are run for months/years without restarting they have the potential to bring the system down or compromise functionality/security.

There are a number of different ways to configure cron for a reboot, I have found this method the neatest and cleanest:

Create a file named "mycron" (or whatever your like) in the /etc/cron.d/ folder. 

sudo nano /etc/cron.d/mycron

Paste the following lines in the file:

# m h dom mon dow user command
15  2 * * * root /sbin/shutdown -r now

Save the file with Ctrl-O and then exit with Ctrl-X.

There is no need to reboot or restart cron, the new file will be picked up automatically on the next cron run.
Reboot will occur daily at 2:15AM.

A selection of commands to manage services from Raspian/Debian Jessie onwards:

Print active services:

sudo systemctl list-units -t service

Print all services:

sudo systemctl list-units -t service --all

Print status of a single service:

sudo systemctl status cron

Start/Stop/Restart/Reload service:

sudo systemctl start ssh
sudo systemctl stop ssh
sudo systemctl restart ssh
sudo systemctl reload ssh

Enable/Disable service:

sudo systemctl enable ssh
sudo systemctl disable ssh

Help is available via man systemctl

Note: Pre Jessie (e.g. Wheezy) was using "service myservice start", "service myservice stop", "update-rc.d myservice defaults", etc.

Links:

https://blog.sleeplessbeastie.eu/2015/04/27/how-to-manage-system-services-on-debian-jessie/

https://wiki.archlinux.org/index.php/systemd

https://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet

https://www.freedesktop.org/wiki/Software/systemd/Incompatibilities/

Credit to Milosz Galazka

Git code repository is required by other installation procedures:

sudo apt-get install git

Apple File Protocol to provide file access via network:

sudo apt-get install netatalk