Volt Docs

Reference

DS3231

Real-time clock with battery backup.

Connects over
I²C
Address
0x68
Made by
Maxim Integrated (Analog Devices)
Datasheet
datasheets.maximintegrated.com

Use it

main.volt
hardware {
    device ds3231: DS3231
}

every 1s {
    let value: int = ds3231.hours()
    log("ds3231", "hours={value}")
}

On its own, the declaration puts the DS3231 on the first I²C bus (SDA 21, SCL 22 on the ESP32) at 0x68. To choose the pins or the address, declare the bus and attach the device: device ds3231: DS3231 on i2c0 at 0x68 with i2c i2c0(sda: 21, scl: 22).

Methods

  • ds3231.hours() -> int

    Hour 0-23

  • ds3231.minutes() -> int

    Minute 0-59

  • ds3231.seconds() -> int

    Second 0-59

  • ds3231.year() -> int

    Year 2000-2099

  • ds3231.month() -> int

    Month 1-12

  • ds3231.date() -> int

    Day 1-31

  • ds3231.temperature() -> float

    RTC temperature °C

Wiring

PinConnect to
VCC3.3V or 5V
GNDGround
SDAPull-up to VCC (often on breakout board)
SCLPull-up to VCC
SQWOptional 1 Hz square-wave or alarm interrupt output
32KOptional 32.768 kHz output

Specifications

Voltage
2.3V – 5.5V
Current
150 μA active, 1 μA standby (battery)
Accuracy
±2 ppm (0–40°C) ≈ ±1 minute / year
Temp sensor
Built-in ±3°C
Battery life
8–10 years on CR2032

Tips

  • TCXO (temperature-compensated XO) — orders of magnitude more accurate than DS1307.
  • Battery (CR2032) keeps time across power cycles.
  • Built-in temperature sensor is for clock compensation but exposed as a regular read.

Alternatives worth knowing:

  • DS1307: Cheaper but drifts ~20 s/month vs. DS3231's ~1 s/month. Skip it.
  • PCF8523: NXP equivalent — slightly lower accuracy, very low power.