Setting the Date and Time

The Real Time Clock (RTC) module NXP PCF2129T is installed in the RevPi Flat and connected via the I2C bus. If you want to set the date and time on the RevPi Flat, you can use two tools that we provide in the image of the RevPi Flat. Below we will show you how to use them to access the RTC.

First of all, you should know the following about the power supply of the RTC:
If the power supply fails or is switched off, a “supercap” – super capacitor – supplies the RTC module with power to maintain the time and date. This works similarly to a battery and discharges in the same way, but much faster than a battery. The time and date can hereby be maintained for approximately 24 hours without external power supply to the RevPi Flat. You can find more on this topic here.

Access via “timedatectl

With “timedatectl” you can query and change the system clock and its settings as well as enable or disable services for time synchronization. We recommend “timedatectl” over “hwclock” because it ties to “systemd-timesyncd”, which is enabled by default in Raspbian and thus in the KUNBUS image for the RevPi Flat.

How to make different settings:

Call up the current time and date on your system that includes RTC time:

sudo timedatectl status

Set the date and time for RTC where the format for time should be specified as HH:MM:SS (hour, minutes and seconds):

sudo timedatectl set-time 15:58:30

Set the date and time in the format YYYY-MM-DD HH:MM:SS:

sudo timedatectl set-time “2020-08-20 16:33:56”

Check the current time of the hardware clock (RTC):

sudo timedatectl | grep “RTC time”

Set the hardware clock to a local time zone:

sudo timedatectl set-local-rtc 1

Set the hardware clock to UTC:

sudo timedatectl set-local-rtc 0

Access via “hwclock

You can query and set the hardware clock (RTC) on the RevPi Flat with “hwclock”. You can display the current time, set the hardware clock to a specific time or the system time, and set the system time from the hardware clock.

How to make different settings:

Display current date and local time from the hardware clock:

sudo hwclock

Set the hardware clock from the current system time:

sudo hwclock – w

Set the RTC to the time specified with –date:

sudo hwclock –set –date “dd mmm yyyy HH:MM”

Example: Set the hardware clock to a specific date and time:

sudo hwclock –set –date “1 Aug 2020 21:17” –utc

Synchronize date and time
Perform two-way synchronization of the hardware clock and the current system time:

sudo hwclock –systohc

Synchronize the hardware clock with the system time:

sudo hwclock –systohc –localtime

Troubleshooting

Not sure if the RTC is working when the device boots?
Use the following command to check if the RTC devices have been successfully detected and initialized by the Linux kernel:

dmesg | grep rtc

[ 1.550198] rtc-pcf2127-i2c 1-0051: rtc core: registered rtc-pcf2127-i2c as rtc0

[ 2.848319] rtc-pcf2127-i2c 1-0051: setting system clock to 2020-08-24 12:14:24 UTC (1598271264)