Real Time Clock on Raspberry Pi
Configuring DS3231 Real-Time Clock controller on Raspberry Pi
Updated: June 15, 2019
Install software to confirm tha I2C devices are visible to RPi and running
sudo apt-get install python-smbus i2c-tools
Run the following commands and check if RTC (0x68), EEPROM (0x57) are visible
sudo i2cdetect -y 1
Add support for the RTC by adding a device tree overlay. Run
sudo nano /boot/config.txt
add the following line to the end of the file
dtoverlay=i2c-rtc,ds3231
Save the file and restart the RPi
sudo reboot
Log back in in and run
sudo i2cdetect -y 1
to see the UU show up where 0x68 was
Disable the “fake hwclock” which interferes with the ‘real’ hwclock
sudo apt-get -y remove fake-hwclock sudo update-rc.d -f fake-hwclock remove
Run
sudo nano /lib/udev/hwclock-set
Comment out these three lines:
#if [ -e /run/systemd/system ] ; then # exit 0 #fi
Check if you can read time from RTC (however incorrect the time can be)
sudo hwclock -D -r
Run
date
to see if RPi has updated time from internet
Run the following command to write the correct time into RTC
sudo hwclock -w
From this point the RTS module will take care of the time as long as it has the battery in it
To set the time and date you can also use
sudo date --set '2019-01-01 18:30:00'