DS3232 RTC Doesn't adjust to DST

For RTC breakouts, etc., use the Other Products from Adafruit forum

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
findly120
 
Posts: 3
Joined: Thu Jun 10, 2021 12:56 pm

DS3232 RTC Doesn't adjust to DST

Post by findly120 »

I have your DS3231 Precision RTC, PRODUCT ID: 3013 connected to a RPi-4. I'm using the Python code example from your web page.
---
# 1 2 3 4 5 6 7 8 9
# Yr Mn Dy Hr Mn Se Wd Yd Dst
rtc.datetime = time.struct_time((2023, 5, 1, 11, 32, 0, 1, 121, 0))
cu = rtc.datetime
print(cu)
---
No mater what I set the DST value to ( 0, 1, or -1) the clock always returns a -1 value for DST.
also the day of the year isn't returned correctly.

Output---
time.struct_time(tm_year=2023, tm_mon=5, tm_mday=1, tm_hour=11, tm_min=32, tm_sec=0, tm_wday=1, tm_yday=-1, tm_isdst=-1)

I'm using this a a data logger so I need the dst value to be correct. I can live without the day of year.

Many Thanks,
Gordon Conley

User avatar
millercommamatt
 
Posts: 837
Joined: Tue Jul 31, 2018 4:57 pm

Re: DS3232 RTC Doesn't adjust to DST

Post by millercommamatt »

You have the day of week set incorrectly which might explain it. time_struct doesn't do any input validation so you can pass it incorrect and nonsensical values.

Why not set the time with something like time.localtime() or time.gmtime()?

Personally, I always use UTC time since it removes all ambiguity about what the time actually is.

User avatar
findly120
 
Posts: 3
Joined: Thu Jun 10, 2021 12:56 pm

Re: DS3232 RTC Doesn't adjust to DST

Post by findly120 »

millercommamatt, Thanks for the reply. I've tried your suggestions both of gmt & local time.

The day-of-week comes back the same as when I set it using Unix time, but neither returns the DST value.

I should qualify that I can set the initial time but once the data logger is deployed will not have network access.
The reason I found this error was I pulled a device from the field that hadn't been network connected since last winter.
I could log all events using gmt.time but it would be good to know when DST changes..

gmt.time -- rtc.datetime = time.gmtime()
RESULT..
time.struct_time(tm_year=2023, tm_mon=5, tm_mday=5, tm_hour=0, tm_min=48, tm_sec=40, tm_wday=4, tm_yday=-1, tm_isdst=-1)

local.time -- rtc.datetime = time.localtime()
RESULT..
time.struct_time(tm_year=2023, tm_mon=5, tm_mday=4, tm_hour=19, tm_min=51, tm_sec=33, tm_wday=3, tm_yday=-1, tm_isdst=-1)

time.structure -- rtc.datetime = time.struct_time((2023, 5, 5, 16, 7, 0, 3, 121, 1))
RESULT..
time.struct_time(tm_year=2023, tm_mon=5, tm_mday=5, tm_hour=16, tm_min=7, tm_sec=0, tm_wday=3, tm_yday=-1, tm_isdst=-1)

Thanks.

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

Return to “Clock Kits (discontinued)”