The Pico-RTC-DS3231 is an RTC expansion module specialized for Raspberry Pi Pico. It incorporates high precision RTC chip DS3231 and uses an I2C bus for communication.
More external sensors are allowed to be connected thanks to the stackable design.
The DS3231 is a low-cost, extremely accurate I2C real-time clock (RTC) with an integrated temperaturecompensated crystal oscillator (TCXO) and crystal.
The device incorporates a battery input, and maintains accurate timekeeping when main power to the device is interrupted. The integration of the crystal resonator enhances the long-term accuracy of the device as well as reduces the piece-part count in a manufacturing line.
The DS3231 is available in commercial and industrial temperature ranges, and is offered in a 16-pin, 300-mil SO package.
The RTC maintains seconds, minutes, hours, day, date, month, and year information. The date at the end of the month is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with an AM/PM indicator.
Two programmable time-of-day alarms and a programmable square-wave output are provided. Address and data are transferred serially through an I2C bidirectional bus.
A precision temperature-compensated voltage reference and comparator circuit monitors the status of VCC to detect power failures, to provide a reset output, and to automatically switch to the backup supply when necessary.
Additionally, the RST pin is monitored as a pushbutton input for generating a μP reset.
- Standard Raspberry Pi Pico header, supports Raspberry Pi Pico series
- Onboard high precision RTC chip DS3231, with backup battery holder
- Real-Time Clock Counts Seconds, Minutes, Hours, Date of the Month, Month, Day of the Week, and Year with Leap-Year Compensation Valid Up to 2100
- Optional format: 24-hour OR 12-hour with an AM/PM indicator
- 2x programable alarm clock
- Operating voltage: 3.3V
- Backup battery voltage: 2.3V~5.5V
- Operating temperature: -40°C ~ 86°C
- Power consumption: 100nA(sustains data and clock information)
This is the Micropython example from the link underneath
#!/usr/bin/python # -*- coding: utf-8 -*- from machine import Pin, I2C import time import binascii I2C_PORT = 0 I2C_SDA = 20 I2C_SCL = 21 ALARM_PIN = 3 class ds3231(object): # 13:45:00 Mon 24 May 2021 # the register value is the binary-coded decimal (BCD) format # sec min hour week day month year NowTime = b'\x00\x45\x13\x02\x24\x05\x21' w = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; address = 0x68 start_reg = 0x00 alarm1_reg = 0x07 control_reg = 0x0e status_reg = 0x0f def __init__(self,i2c_port,i2c_scl,i2c_sda): self.bus = I2C(i2c_port,scl=Pin(i2c_scl),sda=Pin(i2c_sda)) def set_time(self,new_time): hour = new_time + new_time minute = new_time + new_time second = new_time + new_time week = "0" + str(self.w.index(new_time.split(",",2))+1) year = new_time.split(",",2) + new_time.split(",",2) month = new_time.split(",",2) + new_time.split(",",2) day = new_time.split(",",2) + new_time.split(",",2) now_time = binascii.unhexlify((second + " " + minute + " " + hour + " " + week + " " + day + " " + month + " " + year).replace(' ','')) #print(binascii.unhexlify((second + " " + minute + " " + hour + " " + week + " " + day + " " + month + " " + year).replace(' ',''))) #print(self.NowTime) self.bus.writeto_mem(int(self.address),int(self.start_reg),now_time) def read_time(self): t = self.bus.readfrom_mem(int(self.address),int(self.start_reg),7) a = t&0x7F #second b = t&0x7F #minute c = t&0x3F #hour d = t&0x07 #week e = t&0x3F #day f = t&0x1F #month print("20%x/%02x/%02x %02x:%02x:%02x %s" %(t,t,t,t,t,t,self.w[t-1])) def set_alarm_time(self,alarm_time): # init the alarm pin self.alarm_pin = Pin(ALARM_PIN,Pin.IN,Pin.PULL_UP) # set alarm irq self.alarm_pin.irq(lambda pin: print("alarm1 time is up"), Pin.IRQ_FALLING) # enable the alarm1 reg self.bus.writeto_mem(int(self.address),int(self.control_reg),b'\x05') # convert to the BCD format hour = alarm_time + alarm_time minute = alarm_time + alarm_time second = alarm_time + alarm_time date = alarm_time.split(",",2) + alarm_time.split(",",2) now_time = binascii.unhexlify((second + " " + minute + " " + hour + " " + date).replace(' ','')) # write alarm time to alarm1 reg self.bus.writeto_mem(int(self.address),int(self.alarm1_reg),now_time) if __name__ == '__main__': rtc = ds3231(I2C_PORT,I2C_SCL,I2C_SDA) rtc.set_time('13:45:50,Monday,2021-05-24') rtc.read_time() rtc.set_alarm_time('13:45:55,Monday,2021-05-24')
When run I saw this in the REPL
2021/05/24 13:45:50 Monday