The DS3231 is a low-cost, extremely accurate I²C real-time clock (RTC) with an integrated temperature-compensated crystal oscillator (TCXO) and crystal.
For Ubuntu 22.04, and any other distro that doesn’t have usercfg.txt:
- Install the DS3231 module to the Raspberry Pi’s GPIO.
- Open the config.txt file located on the boot partition. (
/boot/firmware/config.txt
inside Raspberry Pi orD:\config.txt
(drive letter might be different) in Windows.) - Add the following text below the bottommost
[all]
to your config.txt:dtoverlay=i2c-rtc,ds3231
. - Test the RTC by entering this command
sudo hwclock -r
. A time string should appear.
For Ubuntu 20.04, and any other distro that have usercfg.txt:
- Install the DS3231 module to the Raspberry Pi’s GPIO.
- Open the usercfg.txt file located on the boot partition. (
/boot/firmware/usercfg.txt
inside Raspberry Pi orD:\usercfg.txt
(drive letter might be different) in Windows.) - Add the following text to your usercfg.txt:
dtoverlay=i2c-rtc,ds3231
. - Test the RTC by entering this command
sudo hwclock -r
. A time string should appear.
For Raspberry Pi OS (formerly Raspbian):
- Install the DS3231 module to the Raspberry Pi’s GPIO.
- Open the config.txt file located on the boot partition. (
/boot/config.txt
inside Raspberry Pi orD:\config.txt
(drive letter might be different) in Windows.) - Uncomment the
dtparam=i2c_arm=on
on the config.txt by removing the # in front of the line. Or useraspi-config
to enable I²C. - Add the following text below the
[all]
to your config.txt:dtoverlay=i2c-rtc,ds3231
. - Test the RTC by entering this command
sudo hwclock -r
. A time string should appear.
Tested on Raspberry Pi 4 Model B.