Changes

Jump to navigation Jump to search

How to enable RTC

1,951 bytes added, 00:54, 23 July 2023
no edit summary
'''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 <code>dtoverlay=i2c-rtc,ds1307</code> 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 <code>/lib/udev/hwclock-set</code>:
sudo nano /lib/udev/hwclock-set
<!--
[[File:X728-7.png|none]]
-->
<syntaxhighlight lang="python" line highlight="7-12">
#!/bin/sh
# Reset the System Clock to UTC if the hardware clock from which it
# was copied by the kernel was in localtime.

dev=$1

#if [ -e /run/systemd/system ] ; then
# exit 0
#fi
#
#/sbin/hwclock --rtc=$dev --systz
#/sbin/hwclock --rtc=$dev --hctosys
?</syntaxhighlight>

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.

Navigation menu