How to enable RTC

From Geekworm Wiki
Jump to navigation Jump to search

Directions:

1. This guide describes how to set up the RTC function on X728 and X729 shield, we only tested it on Raspberry Pi OS.

2. Since different modules may use different clock ICs, there may be slight differences in configuration, but for X728 and X729, they use the same clock IC.

3. You must enable I2C interface before enable RTC, refer to How to enable I2C


Steps:

1. To enable RTC module, first add dtoverlay=i2c-rtc,ds1307 to /boot/config.txt under [all] or the end of file and reboot:

sudo nano /boot/config.txt

Save and exit. In nano, you do that by hitting CTRL + X, answering Y and hitting Enter when prompted.

2. Run the commands to 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
sudo systemctl disable fake-hwclock

3. Then run the following command to comment out 7-12 line in file /lib/udev/hwclock-set:

sudo nano /lib/udev/hwclock-set
 1 #!/bin/sh
 2 # Reset the System Clock to UTC if the hardware clock from which it
 3 # was copied by the kernel was in localtime.
 4 
 5 dev=$1
 6 
 7 #if [ -e /run/systemd/system ] ; then
 8 #    exit 0
 9 #fi
10 #
11 #/sbin/hwclock --rtc=$dev --systz
12 #/sbin/hwclock --rtc=$dev --hctosys
13 ?

PS: Inserting a `# `at the beginning of a line means to comment the line

4. Reboot the Raspberry Pi

sudo reboot

5. Run the command to verify the time is correct. Plug in Ethernet or WiFi to let the Pi sync the right time from the Internet

date

6. Run the command to write the time

 sudo hwclock -w

7. Run the command to read the time

 sudo hwclock -r

Once the time is set, make sure the batteries are inserted so that the time is saved. You only have to set the time once. That's it! Next time you boot the time will automatically be synced from the shield.