Knowledge Base

The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.

RTC Pi on a Raspberry Pi Raspbian Stretch

A tutorial showing how to use the RTC Pi on a Raspberry Pi under Raspbian Stretch.
Created: 12/11/2015 | Last Updated: 02/02/2019

This page details how to setup the RTC Pi on the Raspbian Jessie or Stretch image from

Step 1: With your Raspberry Pi switched off install the RTC Pi on the Raspberry Pi GPIO port and insert a CR2032 coin battery into the battery holder.  Using the RTC Pi without a battery installed may damage the RTC Pi and will stop it from appearing on the I2C bus.

Step 2: Follow the instructions on how to install and configure I2C on Raspbian Linux.

Step 3: Install i2c-tools using:

sudo apt-get install i2c-tools

Step 4:  Once you have installed I2C check that the RTC Pi has been detected using:

sudo i2cdetect -y 0  # (if using v1 Raspberry Pi or)
sudo i2cdetect -y 1  # (if using v2 Raspberry Pi)

The RTC Pi should appear on channel 68 as shown in the screen shot below.  If the RTC Pi does not appear check that the battery is installed correctly and is fully charged:

I2C Detection of the RTC Pi


Step 5: Edit config.txt to add the following: dtoverlay=i2c-rtc,ds1307

sudo nano /boot/config.txt

At the end of the file add


Step 6: Add the module to /etc/modules:

sudo nano /etc/modules

Add at the end of the file


Save your changes

Step 7: Next edit edit /lib/udev/hwclock-set

sudo nano /lib/udev/hwclock-set

Commend out the following lines with #

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

Reboot the Raspberry Pi.

sudo reboot

If this is the first time you have run the RTC Pi it will display a date of January 1st 2000.

Step 8: If the Raspberry Pi is connected to the internet the correct date and time should be set automatically otherwise you can set the current date and time using:

sudo date -s "2 OCT 2015 18:00:00"

You can check the current linux date with the command (date).  To save the date onto the RTC Pi use the following command:

sudo hwclock -w

Verify the date has been saved onto the RTC Pi with:

sudo hwclock -r

If everything worked correctly the RTC Pi should be initialised on boot and the current date and time will be loaded into Linux.

Was this article helpful? Yes / No