HCL:Raspberry Pi3 RTC
One of the main issues with the Raspberry Pi is the lack of a Real-Time-Clock (RTC) that gives the system the correct time directly after a reboot. Usually the system needs network access to get the correct time via NTP, but without access to an NTP server, during a network outage or stand-alone setup, the system will start with a pre-defined date and time after each reboot.
DS3231
The solution for this is really simple and also quite cheap. There is a small RTC module with the DS3231 I2C chip that can be directly connected to the GPIO socket.
Mounting the Module
The module gets mounted to the GPIO socket pins 1,3,5,7,9 as shown in the picture below.
Device Tree (DT) overlay
The RTC module needs to be activated with a Device Tree (DT) overlay. The configuration for this is located at /boot/efi/extraconfig.txt
.
dtoverlay=i2c-rtc,ds3231
After a reboot you will see the module with the dmesg
output.
[ 4.526184] rtc-ds1307 1-0068: rtc core: registered ds3231 as rtc0
On next boots, your dmesg
will show the time is taken from RTC to set the system time:
[ 23.364623] rtc-ds1307 1-0068: setting system clock to 2021-01-29T12:59:55 UTC (1611925195)
timedatectl
timadatectl
shows current time from the system and from RTC:
Local time: jeu. 2021-01-28 16:42:22 UTC Universal time: jeu. 2021-01-28 16:42:22 UTC RTC time: jeu. 2021-01-28 16:42:22 Time zone: UTC (UTC, +0000) System clock synchronized: yes NTP service: active RTC in local TZ: no
hwclock
Another tool is hwclock
to check the time on the RTC module.
#> hwclock --show 2019-01-30 17:29:41.818087+0100
To write the system time that the system got over NTP to the RTC module run --systohc
.
#> hwclock --systohc
systemd (Leap only)
The load of the time from the RTC to the system is automatic on Tumbleweed and nothing needs to be done.
On older Leap, you may need to load the time from the RTC via a systemd service, create the file /usr/lib/systemd/system/hwclock-start.service
with the following content.
[Unit] Description=read rtc and write to system clock After=sysinit.target [Service] Type=oneshot ExecStart=/sbin/hwclock --hctosys --utc [Install] WantedBy=basic.target
Enable the service and restart the system.
#> systemctl status hwclock-start