Document ID: bdb6dc5437e596107e4497ce608d68e0

Introduction:

There is no hardware-based real-time clock in raspis. 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 understading of UN*IX like OS’s

  • Your Rasperry 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 8 (Advanced Options), then select A7 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
    1. 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):

    hwclock --systohc --localtime
  7. reboot

  8. See if sysclock and hwclock are sync’d

    date
    hwclock --show