HCL:Raspberry Pi3 RTC

Jump to: navigation, search

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.


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.


After a reboot you will see the module with the dmesg output.

[    4.526184] rtc-ds1307 1-0068: rtc core: registered ds3231 as rtc0


The time on the RTC module can be checked with the hwclock tool.

#> 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


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.

Description=read rtc and write to system clock

ExecStart=/sbin/hwclock --hctosys --utc


Enable the service and restart the system.

#> systemctl status hwclock-start