I just got my PICO Breakout Garden and plugged an RV3028 RTC Breakout in.
I ran the demo for it and it worked just fine. Seems to have set it to GMT time though?
I’d like to set it to local time instead and could use some help.
The demo file is as follows.
from pimoroni_i2c import PimoroniI2C
from breakout_rtc import BreakoutRTC
import time
PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5} # i2c pins 4, 5 for Breakout Garden
PINS_PICO_EXPLORER = {"sda": 20, "scl": 21} # Default i2c pins for Pico Explorer
i2c = PimoroniI2C(**PINS_BREAKOUT_GARDEN)
rtc = BreakoutRTC(i2c)
if rtc.is_12_hour():
rtc.set_24_hour()
rtc.enable_periodic_update_interrupt(True)
while True:
if rtc.read_periodic_update_interrupt_flag():
rtc.clear_periodic_update_interrupt_flag()
if rtc.update_time():
rtc_date = rtc.string_date()
rtc_time = rtc.string_time()
print("Date: ", rtc_date, ", Time: ", rtc_time, sep="")
time.sleep(0.1)
Reading it without updating first would be an option too. I can easily set it on a Pi.
I’ve not had chance to plug one of these into a Pico yet, but it looks like you should be able to set the RTC time with rtc.set_time(sec, min, hour, weekday, date, month, year) (there are also micropython bindings for set_seconds, set_minutes etc if you just want to set one of the parameters?)
What do you enter for year? Or have I messed up one of the other entries?
rtc.set_time(00, 00, 09, 02, 06, 07, 00)
gets me
Date: 06/07/2048, Time: 09:00:20AM
and
rtc.set_time(00, 00, 09, 02, 06, 07, 21)
gets me
Date: 06/07/2069, Time: 09:00:00AM
Using 2021 for year gets me
ValueError: year out of range. Expected 0 to 99
EDIT: Is the following correct?
rtc.set_time(sec, min, hour, weekday, date, month, year)
sec = 0-59
min = 0-59
hour = 0-23
weekday = 1-7
date = 1-31
month = 1-12
year = 0-99
Once I run rtc.set_time its all down hill from there. I get the wrong year 2069 and running the stock demo file won’t reset it / update it to UTC? Even taking the battery out didn’t help? Running the demo just got me
Date: 01/01/2000, Time: 00:00:01 and it wouldn’t update? I’ve tried two different RV3028’s that worked as advertised on my Raspberry Pi Breakout Garden. I’ll have to plug this one into my raspberry Pi and run set_time.py to get it back to the correct time.
It looks like a library bug. rtc.set_time constrains the year to the range [00-99], but then calls the corresponding RV3028 driver routine, which treats it as a 16-bit unsigned int and subtracts 2000 from it.
When you take all that into account, the results you got are actually inevitable: