Enable RTC and Set Time
Now that we have RTC wired up, the operating system can be configured to use it. This is pretty simple on modern Pi OS versions. The general steps are:
- Enable the appropriate I2C device tree overlay
- Disable time sync service (optional)
Enable RTC
Enabling use of the RTC is a simple matter of enabling a device tree overlay. In this case, the i2c-rtc overlay is used. The only special thing needed is to specify the actual RTC being used. To enable the overlay, edit the config.txt file:
sudo nano /boot/firmware/config.txt
and add one of the following lines to the end, depending on the RTC being used.
For the PCF8523:
dtoverlay=i2c-rtc,pcf8523
For the DS3231:
dtoverlay=i2c-rtc,ds3231
For the DS1307:
dtoverlay=i2c-rtc,ds1307
Save the changes and run sudo reboot to reboot the Pi so the changes take affect. After rebooting, run i2cdetect -y 1 again to verify that UU now shows up where 0x68 should be:
Setting Time
There are two time sources to consider:
- System Clock - the time according to the operating system
- use the date command to check/set this
- Hardware Clock - the time according to the RTC
- use the hwclock command to check/set this
At boot, the system clock is set to the hardware (RTC) clock.
If the Pi has internet access, it will use NTP to sync and set the Pi's time every time it boots up. This will update the RTC as well. See the next section for how to disable this behavior.
There is also a command line tool called hwclock which can be used to manually check and set the RTC. It can be installed using:
sudo apt install util-linux-extra
The current time of the RTC can be read using:
sudo hwclock -r
To manually set the RTC use:
sudo hwclock --set --date='2010-01-02 12:23:42'
where the date and time are set using the text string with YEAR-MONTH-DAY HOUR:MINUTE:SECOND syntax as shown after the --date parameter. Update this for whatever date/time you want.
NOTE: This only sets the RTC time. To set the system time to the updated RTC time, use:
sudo hwclock -s
This generally only needs to be done once, or anytime the RTC time needs adjusting.
If you are getting an error message like this when trying to read/write to the RTC, make sure you have a good coin cell battery installed.
Disabling Time Sync Service
If you want to disable the time sync service so that the Pi does not attempt to set the time via the internet, run the following:Â
sudo systemctl disable systemd-timesyncd
Now the Pi should be entirely relying the attached RTC for setting system time.
Page last edited April 02, 2026
Text editor powered by tinymce.