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:
-
Plug the RTC module into the GPIO (see https://nicegear.co.nz/obj/images/pi-rtc-module-mounting.png)
-
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. -
run:
echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
-
Add these 2 lines to
/etc/rc.local
(before theexit 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 thestart()
switch.
-
-
Consider removing the raspian fake clock:
sudo update-rc.d -f fake-hwclock remove
-
Sync system time with RTC module (hwclock):
hwclock --systohc --localtime
-
reboot
-
See if sysclock and hwclock are sync’d
date hwclock --show