The main documentation repository for the 🍭☁️
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RTC (Real Time Clock)

Setup a good time source. The built in RTC for Allwinner chips lacks a battery on the Orange Pi boards and has a higher drain than others. Go with the others for the better power use

Inspiration / Further Reading



  • Use cheapest for ultra portable builds
  • Use most accurate for mostly permanent builds (RV/similar)
  • Use most common rarely used (unless you have good reason, don’t)


Key Note

This guide assumes the PCF8523. You’ll need to adjust lightly for the DS3231 or DS1307.

Initial Setup

armbian-config # enable i2c busses
systemctl reboot # reboot to enable bus(es)
apt install i2c-tools # install tools
i2cdetect -l # check to ensure busses are present
i2cdetect -y 1 # 0 for orange pi zero ; 1 for recent pi's
modprobe rtc-pcf8523 # load the proper rtc module (adafruit cheap model)
echo pcf8523 0x68 > /sys/class/i2c-adapter/i2c-1/new_device # setup device so it's seen
dmesg | grep rtc # verify the kernel sees the rtc
ls /dev/rtc* # should have rtc1
hwclock -r -f /dev/rtc1 # See if anything is on the rtc
hwclock -f /dev/rtc1 --systohc -D --noadjfile --utc # set / init the rtc
hwclock -r -f /dev/rtc1 # read the value from the rtc
hwclock -w -f /dev/rtc1 # write the current time to the rtc
apt remove --purge fake-hwclock # purge the fake hwclock as we have a real one now
systemctl disable fake-hwclock # Disable any dangling services

Udev Rules

# setup udev rule to setup the new rtc as the primary for the board
# `udevadm info -a -p /sys/class/rtc/rtc1` gets the details for the below entries
cat > /etc/udev/rules.d/99-rtc1.rules <<EOF
KERNEL=="rtc1", SUBSYSTEM=="rtc", DRIVER=="", ATTR{name}=="rtc-pcf8523 0-0068", SYMLINK="rtc", MODE="0666"

External RTC On Boot

A systemd unit that brings the external RTC online during boot

cat > /etc/systemd/system/rtc1-online.service <<EOF
Description=Setup rtc1 as primary clock

ExecStart=/bin/sh -c '/sbin/modprobe rtc-pcf8523  \
&& echo pcf8523 0x68 > /sys/class/i2c-adapter/i2c-1/new_device \
&& /sbin/hwclock -s -f /dev/rtc1'


systemctl daemon-reload
systemctl enable rtc1-online

Set RTC on shutdown

A systemd unit that sets the current time to the rtc on shutdown to minimize clock drift during next boot

cat > /etc/systemd/system/rtc1-shutdown-fix.service <<EOF
Description=Set rtc1 on shutdown

ExecStart=/sbin/hwclock --systohc -D --noadjfile --utc -f /dev/rtc1


systemctl daemon-reload
systemctl enable rtc1-shutdown-fix

Misc Notes

date # Wait for this to get sync'd via whatever ntp you're doing
hwclock -r -f /dev/rtc1 # Verify this isn't right
hwclock -w -f /dev/rtc1 # Write ntp system time -> rtc
hwclock -r -f /dev/rtc1 # Verify the write worked
ls -l /dev/rtc* # Check rtc dev node is present
hwclock -r -f /dev/rtc1 # read time from external rtc
hwclock -r -f /dev/rtc0 # read time from internal rtc