RTC DS1307

The Raspberry PI HAT - Real Time Clock is a battery backed real-time clock board for the Raspberry Pi A+, Raspberry Pi B+, Raspberry Pi 2 Model B, Raspberry Pi 3 Model A, Raspberry Pi 3 Model B, and Raspberry Pi 4 Model B.

Despite the Raspberry Pi is a great low cost computer with thousands of different uses it comes without a real-time clock. In order to keep updated the date and time the Raspberry Pi connects to an Internet Time Server and synchronizes them using the Network Time Protocol (NTP). If the Raspberry Pi is not connected to the net, every time you switch it off, it forgets the date and time and you have to manually set them again next time you switch your Raspberry Pi on.

The Raspberry PI HAT - Real Time Clock is a battery backed real-time clock board for the Raspberry Pi A+, Raspberry Pi B+ and Raspberry Pi 2 Model B and Raspberry Pi 3 Model B. It keeps the date and time while the Raspberry Pi is switched off. When Raspberry Pi switched back on, it can synchronizes the date and time from the Real Time Clock.

The Raspberry PI HAT - Real Time Clock uses the DS1307 RTC real time clock and a CR2032 battery to maintain the date and time when the main system power is not available. The Raspberry PI HAT - Real Time Clock also includes an I2C logic level converter making the Raspberry Pi's I2C bus, 5V devices tolerant.

Warning: Do not connect the Raspberry PI HAT - Real Time Clock to your Raspberry Pi when powered without the battery installed. This can damage the DS1307 RTC chip.

The Raspberry PI HAT - Real Time Clock uses a CR2032 button battery (battery included).

 

Installing Raspberry PI HAT - Real Time Clock on a Raspberry Pi with Raspian Linux 3.18 or later

Step 1: With your Raspberry Pi switched off install the Raspberry PI HAT - Real Time Clock on the Raspberry Pi GPIO port and insert a CR2032 coin battery into the battery holder.

Step 2: Run the Raspberry Pi config utility and enable I2C

sudo raspi-config

Select "Advanced Options" and then "I2C - Enable/Disable automatic loading". A prompt will appear asking Would you like the ARM I2C interface to be enabled?, select Yes, exit the utility and reboot your Raspberry Pi.

sudo reboot

Step 3: Install i2c-tools using:

sudo apt-get install i2c-tools

Step 4: Once you have installed I2C check that the Raspberry PI HAT - Real Time Clock has been detected using:

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

sudo i2cdetect -y 1 (if using v2 Raspberry Pi)

The Raspberry PI HAT - Real Time Clock should appear on channel 68 as shown in the screen shot below. If the Raspberry PI HAT - Real Time Clock does not appear check that the battery is installed correctly and is fully charged:

RTC Screen Shot

Step 5: Edit the file config.txt:

sudo nano /boot/config.txt

At the end of the file add

dtoverlay=i2c-rtc,ds1307

Save your changes.

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

sudo nano /etc/modules

Add at the end of the file

rtc-ds1307

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

fi

Save your changes.

Reboot the Raspberry Pi.

sudo reboot

If this is the first time you have run the Raspberry PI HAT - Real Time Clock 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 "6 OCT 2015 18:00:00"

You can check the current linux date with the command (date). To save the date onto the Raspberry PI HAT - Real Time Clock use the following command:

sudo hwclock -w

Verify the date has been saved onto the Raspberry PI HAT - Real Time Clock with:

sudo hwclock -r

If everything worked correctly the Raspberry PI HAT - Real Time Clock should be initialized on boot and the current date and time will be loaded into Linux.

Schematics

You can download schematics from github at:

https://github.com/nationelectronics/

To download the schematics to your Raspberry Pi type in terminal:

git clone https://github.com/nationelectronics/nationelectronics_schematics.git

Purchase options

You can buy this item here:

http://www.nationelectronics.com/raspberry-pi-extensions/20-raspberry-pi-hat-real-time-clock-v11-0648260628208.html

or at Amazon:

https://www.amazon.com/dp/B01LRC3AF6

Other resources

Enabling The I2C Interface On The Raspberry Pi

Maxin Integrated DS1307, Serial, I2C, Real-Time Clock DATASHEET