RTC Pi on a Raspberry Pi with Raspbian wheezy

Created 02/10/2015 | A tutorial showing how to use the RTC Pi on a Raspberry Pi.

This page details how to setup the RTC Pi on the Raspbian “wheezy” image from http://www.raspberrypi.org/downloads

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:  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 3: Enable I2C by running:

sudo nano /etc/modprobe.d/raspi-blacklist.conf

Find the I2C line where the I2c is black listed

blacklist i2c-bcm2708

Comment it out by replacing it with the line below

#blacklist i2c-bcm2708

Step 4: set the bash shell to root by typing (sudo bash) and then run:

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device (if you have a version 1 Raspberry Pi or)
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device (if you have a version 2 Raspberry Pi)

Type (exit) to drop out of the root bash shell.

Step 5: You can check the current time on the RTC Pi with:

sudo hwclock -r

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

Step 6: 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:

date -s "2 OCT 2006 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

Step 7: Now you have the RTC Pi running with the current date and time the next step is to make it load when the Raspberry Pi boots.

Edit the modules file:

sudo nano /etc/modules

Add rtc-ds1307 at the end of the file and save it.

Step 8: Next you want to add the RTC Pi at boot by editing /etc/rc.local

sudo nano /etc/rc.local

Add the following at the bottom of the page above exit 0.

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device (if you have a version 1 Raspberry Pi or)
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device (if you have a version 2 Raspberry Pi)
sudo hwclock -s

Save the file and reboot your Raspberry Pi.

sudo reboot

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

Shop

Support

Click to contact us.
X

Have any Questions?

Send us any questions about this page or product and we will reply within 24 hours.

Submit your Message

X

Have any Questions?

Thank you for contacting us.

We will respond to your enquiry in the next 24 hours.

You can find answers to many questions and additional product support in our Knowledge Base and the Community Forum.