RTC Pi on a Raspberry Pi Raspbian Stretch
Created 12/11/2015 | A tutorial showing how to use the RTC Pi on a Raspberry Pi under Raspbian Jessie or Stretch.
This page details how to setup the RTC Pi on the Raspbian Jessie or Stretch image from https://www.raspberrypi.org/downloads/raspbian/
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:
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
Reboot the Raspberry Pi.
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.