Add hardware clock (RTC hwclock) DS3231 to Raspberry Pi

Lack of hardware clock on Raspberry Pi is not that big of a deal if you are online all the time. For a few $ you can add this feature to your pi.

I ordered mine on eBay for less than $2, so I can recommend the seller here:

New DS3231 Precision RTC Module Memory Module for Arduino Raspberry Pi

RTC module is quite small, smaller than I thought it would be:

ds3231_1 ds3231_2

It also fits perfectly in my Raspberry Pi case.

ds3231_3

Now for the configuration part:

# Load the module
modprobe i2c-bcm2708
# use -0 for Model A or -1 for Model B
echo ds3231 0x68 | tee/sys/class/i2c-adapter/i2c-1/new_device
# Test RTC module
hwclock
Mine reported strange date and time:
Wed 15 Mar 2000 08:39:04 AM CET -0.469524 seconds
Now sync the system date to your RTC module:
hwclock -w
Mon 18 May 2015 05:40:57 PM CEST  -0.784936 seconds
Now to read the time from RTC chip on boot, edit /etc/rc.local and add this before “exit 0” line.
echo ds3231 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
hwclock -s
To disable fake-hwclock and NTP daemon from starting at boot use:
update-rc.d ntp disable
update-rc.d fake-hwclock disable
 You can use this to manually sync with Internet time again:
ntpd -gq
hwclock -w

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.