Power down your Pi before you connect something onto the GPIO pins!
Adafruit PCF8523 | - | direct connect |
Adafruit DS3231 | - | breakout |
$ sudo apt-get install python-smbus i2c-tools -y
Check if you see the RTC clock with address 0x68 in the matrix:
$ sudo i2cdetect -y 1
$ sudo nano /boot/config.txt
Edit the pi configuration and add the RTC chip to the end of the file:
dtoverlay=i2c-rtc,ds3231
Or
dtoverlay=i2c-rtc,pcf8523
Save and Reboot
$ sudo i2cdetect -y 1
There should now be UU where 0x68 used to be.
$ sudo apt-get -y remove fake-hwclock -y
$ sudo update-rc.d -f fake-hwclock remove
$ sudo nano /lib/udev/hwclock-set
Find:
if [ -e /run/systemd/system ] ; then
exit 0
fi
Comment out or delete:
#if [ -e /run/systemd/system ] ; then
# exit 0
#fi
$ sudo systemctl stop systemd-timesyncd.service
$ sudo systemctl disable systemd-timesyncd.service
$ date
If this gives the correct time/date, set the Hardware Clock from the System Clock, and update the
timestamps in /etc/adjtime :
$ sudo hwclock --systohc
This does the same as hwclock -w
You only have to do this once, as long as the battery is full and working.
When the battery is replaced
you need to do this again, because the RTC has lost all it's memory.
$ date && sudo hwclock -r
Monitor the driftbetween your system clock and the rtc module:
$ sudo hwclock -c
The above command will not return to the prompt, it will run continuously
printing the clock drift every 10 seconds, until you interrupt it with Ctrl-C
That's it!