Real-time Clock (RTC) module on a Raspberry Pi

Chip Cuccio, <This email address is being protected from spambots. You need JavaScript enabled to view it.>
updated to version 1.1, Apr 19 2017, by kd5dkq, R. Mark Boddy

Introduction:

I started with w0chp's, Chip Cuccio, great instructions here: http://wx.w0chp.net/setup/RPi2-B_RTC.html and made a couple of changes so they'd work in April 2017. Thanks Chip for the great start!

There is no hardware-based real-time clock in raspberry pis. For sensitive data (such as DB’s and WX data), an RTC in kind of important. This also mitigates time-keeping issues when there’s a loss of power, network connectivity, etc. Here’s the the steps I took in order to get my RTC module working…

Assumptions:

This quick and dirty guide assumes:

  • You have an understanding of UN*IX like OS’s
  • Your Raspberry Pi is a version 2
  • You have a DS3231-based RTC module already :-)
  • Your RPi2 is running Raspbian

Steps:

  1. Plug the RTC module into the GPIO (see https://nicegear.co.nz/obj/images/pi-rtc-module-mounting.png)
  2. The i2c adapter is NOT loaded by default in the 2015-02-02 Rasbian distribution, unlike in earlier versions. To enable it, type: sudo raspi-config then select option 5 (Interface Options), then select P5 I2C, then select Yes to enable
  3. run: echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
  4. Add these 2 lines to /etc/rc.local (before the exit 0 statement):
         echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
         hwclock -s
    NOTE: I also added hwclock -s to the ntp init script in the start() switch.
  5. Consider removing the raspian fake clock:
         sudo update-rc.d -f fake-hwclock remove
  6. Sync system time with RTC module (hwclock)
    sudo hwclock --systohc --localtime
  7. reboot
  8. See if sysclock and hwclock are sync’d
    date
    sudo hwclock --show

As time goes on these instructions too will fail...please send updates and changes to kd5dkq at arrl dot net.
73 de kd5dkq

Information on the Raspberry Pi

Enabling the I2C bus in Raspian for the Raspberry Pi