How to use the real-time clock functionality in Raspberry Pi 5 | #MagPiMonday

In the latest issue of The MagPi, Alasdair Allan shows you how to use the real-time clock (RTC) functionality in Raspberry Pi 5. Happy #MagPiMonday!

Raspberry Pi RTC Battery
The RTC battery features a lithium-manganese rechargeable battery. Use the J5 connector to attach the RTC battery to Raspberry Pi 5

Raspberry Pi 5 includes an RTC module. This can be battery powered via the J5 (BAT) connector on the board located to the right of the USB-C power connector.

You can set a wake alarm which will switch the board to a very low-power state (approximately 3mA). When the alarm time is reached, the board will power back on. This can be useful for periodic jobs like time-lapse imagery.

How to use the real-time clock functionality in Raspberry Pi 5 | #MagPiMonday
The J5 connection (at the bottom of the image) is used to connect the RTC battery to Raspberry Pi 5

To support the low-power mode for wake alarms you should edit the bootloader config:

$ sudo -E rpi-eeprom-config --edit

… adding the following two lines.

POWER_OFF_ON_HALT=1 
WAKE_ON_GPIO=0

Reboot Raspberry Pi so the updated EEPROM takes effect:

$ sudo reboot

You can test the functionality with:

 $ echo +600 | sudo tee /sys/class/rtc/rtc0/
wakealarm 
 $ sudo halt

That will halt the board into a very low-power state, then wake and restart after 10 minutes.

The RTC also provides the time on boot e.g. in dmesg:

 [    1.295799] rpi-rtc soc:rpi_rtc: setting 
system clock to 2023-08-16T15:58:50 UTC (1692201530)

…which may be useful if you don’t have an internet connection for getting time through NTP.

Adding a backup battery

The official battery part is a rechargeable lithium manganese coin cell, with a pre-fitted two-pin JST plug and an adhesive mounting pad. This is suitable for powering the Raspberry Pi 5 RTC when the main power supply for the board is disconnected, with a power-off current draw measuring in single-digit µA, giving a retention time that can be measured in months.

How to use the real-time clock functionality in Raspberry Pi 5 | #MagPiMonday
Edit the EEPROM configuration file to enable RTC support

Enabling trickle charging

Trickle charging of the battery is disabled by default. There are sysfs files that show the current trickle charging voltage and limits:

 /sys/devices/platform/soc/soc:rpi_rtc/rtc/
rtc0/charging_voltage:0 
 /sys/devices/platform/soc/soc:rpi_rtc/rtc/
rtc0/charging_
voltage_max:4400000 
 /sys/devices/
platform/soc/soc:rpi_rtc/
rtc/rtc0/charging_
voltage_min:1300000
How to use the real-time clock functionality in Raspberry Pi 5 | #MagPiMonday
The J5 socket may have a small plastic cover. Remove this to attach the RTC battery to Raspberry Pi 5

You can check these values with cat, for example:

 cat /sys/devices/platform/
soc/soc:rpi_rtc/rtc/rtc0/
charging_voltage

…returns: “0”, the current charging value. If you add rtc_bbat_vchg to /boot/firmware/config.txt using:

sudo nano /boot/firmware/config.txt

… and add:

dtparam=rtc_bbat_vchg=3000000

…and reboot. Use cat to investigate the values and you’ll see:

 /sys/devices/platform/soc/soc:rpi_rtc/rtc/
rtc0/charging_voltage:3000000
 /sys/devices/platform/soc/soc:rpi_rtc/rtc/
rtc0/charging_voltage_max:4400000
 /sys/devices/platform/soc/soc:rpi_rtc/rtc/
rtc0/charging_voltage_min:1300000

The battery will be trickle charging. Remove the dtparam line from config.txt to stop the trickle charging.

Print Friendly, PDF & Email

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Server Status

Aradippou Chat 1 Chat 2 Larnaca Limassol Nicosia

Chat Links

Official Links.

1. Chat 1.
2. Chat 2.

Alternative Mirror Links.

1. KiwiIRC 1.
2. KiwiIRC 2.

Other Web Clients.

1. IrcCloud.

Recent Posts

Related Posts:

Advertisement

Archives

Super Club Radio

Mighty Deals

CyIRC

CyIRC Tweets

Scroll Up
Fatal error: Uncaught WMAC\JSMin_UnterminatedStringException: WMAC\JSMin: Unterminated String at byte 1180: "+o.accessToken}}).then(e=>{if(!e.ok)throw e;return e});return a.catch(e=>{console.error(`Failed to logout chatrix session. deviceId: ${o.deviceId}`)}),a}})(); in /home/bszucbfe/public_html/wp-content/plugins/clearfy/components/minify-and-combine/includes/classes/ext/php/jsmin.php:215 Stack trace: #0 /home/bszucbfe/public_html/wp-content/plugins/clearfy/components/minify-and-combine/includes/classes/ext/php/jsmin.php(157): WMAC\JSMin->action(2) #1 /home/bszucbfe/public_html/wp-content/plugins/clearfy/components/minify-and-combine/includes/classes/ext/php/jsmin.php(96): WMAC\JSMin->min() #2 /home/bszucbfe/public_html/wp-content/plugins/clearfy/components/minify-and-combine/includes/classes/class-main.php(375): WMAC\JSMin::minify('(function(){"us...') #3 /home/bszucbfe/public_html/wp-includes/class-wp-hook.php(324): WMAC_PluginMain->jsSnippetcacher('(function(){"us...', '/home/bszucbfe/...') #4 /home/bszucbfe/public_h in /home/bszucbfe/public_html/wp-content/plugins/clearfy/components/minify-and-combine/includes/classes/ext/php/jsmin.php on line 215