RTC_edited.jpg

Real Time Clock Configuration

Real Time Clock

based on the PCF8523, an I2C device at location 0x68. Follow the steps below to configure the RTC.

Step 1 - Install Updates

pi@raspberrypi ~ $ sudo apt-get update
pi@raspberrypi ~ $ sudo apt-get upgrade
pi@raspberrypi ~ $ sudo reboot

Step 2 - Enable a RTC device tree

pi@raspberrypi ~ $sudo nano /boot/config.txt

Edit the pi configuration and add an overlay for the PCF8523:

pi@raspberrypi ~ $dtoverlay=i2c-rtc,pcf8523

Step 3 - Turn off the fake hardware clock

pi@raspberrypi ~ $ sudo apt-get -y remove fake-hwclock

pi@raspberrypi ~ $ sudo update-rc.d -f fake-hwclock remove

pi@raspberrypi ~ $ sudo systemctl disable fake-hwclock

Step 4 - Enable the real hardware RTC

pi@raspberrypi ~ $ sudo nano /lib/udev/hwclock-set

Comment out these three lines:

#if [ -e /run/systemd/system ] ; then
# exit 0
#fi

Comment out these two lines

#/sbin/hwclock --rtc=$dev --systz --badyear

#/sbin/hwclock --rtc=$dev --systz

Step 5 - Set the clock

When you initially get the clock working, the clock will have the wrong date and time.

Read the current hardware clock data and time

pi@raspberrypi ~ $ sudo hwclock -D -r

Set the correct Raspberry Pi date and time

pi@raspberrypi ~ $ date --set="20200413 21:14"

Write the correct date and time to the hardware RTC

pi@raspberrypi ~ $ sudo hwclock -w