The Raspberry Pi 5 introduces a brand new feature – the integrated Real-Time Clock (RTC). This small but significant addition brings with it a host of capabilities, and in this blog post, we'll delve into how you can get started with using the RTC on the Raspberry Pi 5.
Unlocking RTC Capabilities:
The RTC module on the Raspberry Pi 5 is conveniently located near the USB-C power connector, easily powered by a battery through the J5 (BAT) connector. This integration opens up a world of possibilities for tasks that require precise timing and scheduling.
Wake Alarms and Low-Power State:
One standout feature is the ability to set wake alarms, allowing the board to enter an ultra-low-power state, consuming only around 3mA. This functionality is particularly valuable for tasks like periodic time-lapse photography. Enabling low-power mode involves a simple modification to the bootloader configuration.
sudo -E rpi-eeprom-config --edit
Add the following lines to the configuration:
POWER_OFF_ON_HALT=1
WAKE_ON_GPIO=0
Test the wake alarm functionality using the commands:
echo +600 | sudo tee /sys/class/rtc/rtc0/wakealarm
sudo halt
These commands showcase the board's ability to transition into an extremely low-power state, then wake up and restart after a 10-minute interval.
RTC Functionality Without a Backup Battery:
Importantly, the RTC functionality remains accessible even without a backup battery connected to the J5 connector. This feature proves valuable in scenarios where an internet connection for time synchronization through NTP is unavailable.
Choosing the Right Battery:
When opting for a battery, caution is advised against using a primary lithium cell due to potential issues with the trickle charge circuit. The recommended choice is a rechargeable lithium-manganese cell, designed for longevity and optimal performance. This rechargeable battery, equipped with a two-pin JST plug and an adhesive mounting pad, ensures the RTC continues to function seamlessly when the primary power supply is disconnected.
Enabling Trickle Charging:
While trickle charging is disabled by default, it can be activated by adding a line to the /boot/firmware/config.txt file:
dtparam=rtc_bbat_vchg=3000000
After a reboot, you'll observe the charging voltage changes, indicating that the battery is now receiving trickle charging. If you wish to disable trickle charging, simply remove the dtparam line from the config.txt file.