DS3231 RTC with a Raspberry Pi Pico
The DS3231 is an I2C real-time clock whose integrated temperature-compensated crystal oscillator (TCXO) holds time to ±2 ppm, about a minute a year, between 0 and 40 °C.

The DS3231 gives the Raspberry Pi Pico a battery-backed clock on I2C0 (SDA GP4, SCL GP5) at the fixed address 0x68, powered from 3V3. The RP2040 has a real-time counter of its own, but it loses the time whenever the Pico loses power; the DS3231's coin cell keeps it.
Wiring the DS3231 RTC to the Raspberry Pi Pico
Pin by pin.
| DS3231 RTC | Raspberry Pi Pico |
|---|---|
| VCC | 3V3 |
| GND | GND |
| SCL | GP5 |
| SDA | GP4 |
What to know on the Raspberry Pi Pico
- The RP2040's Real Time Counter is on-chip with no backup supply. The DS3231 keeps counting on its VBAT cell and is accurate to ±2 ppm from 0 to 40 °C.Raspberry Pi Pico datasheet, release 21, p. 4; Analog Devices DS3231 datasheet 19-5170 rev 10, p. 1
- The chip runs from 2.3 V to 5.5 V, so the Pico's 3V3 powers it and the module's pull-ups hold SDA and SCL at 3.3 V.Analog Devices DS3231 datasheet 19-5170 rev 10, p. 2
- SQW/INT is open drain. To use an alarm as an interrupt, wire it to a free GPIO set INPUT_PULLUP; any RP2040 GPIO can take attachInterrupt().Analog Devices DS3231 datasheet 19-5170 rev 10, p. 9
- Many DS3231 modules carry an AT24C32 EEPROM that answers at 0x57, the MAX30102's address; do not put both on the Pico's one bus without checking.Microchip AT24C32 datasheet (address pins A0 to A2, held high on the module); Maxim MAX30102 datasheet (address 0x57)
DS3231 RTC code for the Raspberry Pi Pico
Compiled for rp2040:rp2040:rpipico on 2026-10-30.
// DS3231 RTC on Raspberry Pi Pico: wiring and a free simulation at https://www.tinkered.ai/components/ds3231-rtc/raspberry-pi-pico
#include <Wire.h>
#include <RTClib.h>
RTC_DS3231 rtc;
void setup() {
Serial.begin(9600);
if (!rtc.begin()) { // ACKs at 0x68
Serial.println("DS3231 not found");
while (1) delay(10);
}
if (rtc.lostPower()) { // first boot / dead coin cell
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // set from compile time
}
}
void loop() {
DateTime now = rtc.now();
Serial.print(now.year()); Serial.print('-');
Serial.print(now.month()); Serial.print('-');
Serial.print(now.day()); Serial.print(' ');
Serial.print(now.hour()); Serial.print(':');
Serial.print(now.minute());Serial.print(':');
Serial.print(now.second());
Serial.print(" ");
Serial.print(rtc.getTemperature()); Serial.println(" C");
delay(1000);
}
DS3231 RTC on the Raspberry Pi Pico: questions
Why use a DS3231 when the RP2040 has an RTC?
The RP2040's Real Time Counter (Pico datasheet, p. 4) stops when the board loses power. The DS3231 runs on its coin cell and drifts ±2 ppm from 0 to 40 °C (Analog Devices datasheet, p. 1).
Does the DS3231 work at 3.3 V on a Pico?
Yes. VCC is rated 2.3 V to 5.5 V (Analog Devices datasheet, p. 2); power it from 3V3 so SDA and SCL stay at the Pico's level.
How do I set the DS3231's time from the Pico?
The sketch calls rtc.adjust(DateTime(F(__DATE__), F(__TIME__))) when lostPower() is true, which sets the compile time on the first boot or after the cell dies.
Keep going
This guide as plain Markdown. /components/ds3231-rtc/raspberry-pi-pico.md