RTC not keeping time. DS3231 STEMMA QT

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
JuanFR
 
Posts: 1
Joined: Fri May 20, 2022 11:31 pm

RTC not keeping time. DS3231 STEMMA QT

Post by JuanFR »

I'm trying to set the time on the DS3213 STEMMA QT breakout connected to a kb2040.
I've set it up with circuitpython, no code on it yet, and i'm using serial console in Mu to set the time.
It has a brand new CR1220 that shows 3.2v over the VIN and VBAT pins when not connected to anything, no soldering done to the board yet.
This is what i'm using in REPL to set the time, but every time power is disconnected the time appears to be reset.

Code: Select all

import rtc
import time
r = rtc.RTC()
r.datetime = time.struct_time((2023, 3, 15, 17, 12, 00, 3, 74, -1))
time.localtime()
i then get the correct output showing the time as:

Code: Select all

struct_time(tm_year=2023, tm_mon=3, tm_mday=15, tm_hour=17, tm_min=12, tm_sec=19, tm_wday=2, tm_yday=74, tm_isdst=-1)
but after disconnecting the usb and rebooting the kb2040 i check the time in REPL with :

Code: Select all

import rtc
import time
r = rtc.RTC()
time.localtime()
i get

Code: Select all

struct_time(tm_year=2020, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=38, tm_wday=2, tm_yday=1, tm_isdst=-1)
I've tried this on a macropad 2040 and a kb2040, am i doing something wrong or is my DS3231 dead?
Last edited by adafruit_support_carter on Fri Mar 17, 2023 1:37 pm, edited 1 time in total.
Reason: added [code] tags

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: RTC not keeping time. DS3231 STEMMA QT

Post by adafruit_support_carter »

You're accessing the internal RTC:
https://docs.circuitpython.org/en/lates ... module-rtc
which probably does not have any power backup, and resets with each power cycle/reset.

See here for general code example for accessing the DS3231.
https://github.com/adafruit/Adafruit_Ci ... pletest.py

Also checkout guide:
https://learn.adafruit.com/adafruit-ds3 ... cuitpython

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”