I thought I’d gotten over my RTC problems but it seems it’s not to be.
I’m able to run the set_time.py sketch (once I was using the right set_time.py file) and it appeared to be working (once I’d fixed the QWST connector that hadn’t been soldered on my Badger2040. Nothing like surprise surface-mount soldering to brighten your day…) But now that I’m at the stage where I’m ready to try running my sketch directly on the device (instead of through Thonny) I find that the time coming from the RV3028 is actually nonsense.
First screenshot, showing the RTC initialisation -
Between these two sketches the Badger remained plugged-in to my PC and connected to Thonny, so I don’t even think it would have gone onto the battery backup. The second image does show a valid time, although not the current time, and when I re-ran the sketch it reported ‘19/06/2098 63:05:47’ so I’m pretty sure the valid time was just luck. I did try with and without the call to .setup() in check_time.py but the result was still way off.
So what is going on here? Is the battery in my brand-new RV3028 so flat that it’s losing time while it’s powered externally? Or is there some more setup that I’m missing somewhere?
This is code I run on my Pico that works for me. It’s a dual display setup. The following code was clipped and pasted from a much bigger file. It won’t run on its own without a bit of editing. Hopefully I snagged all the important stuff. It was my best guess at what was needed to make it work.
From a little trial and error it appears that update_time() needs to be called every time the sketch runs, and set_backup_switchover_mode() only needs to be run once per-device as part of the initial setup.
Usually, I can gleam what code I need from the examples. Some breakouts have a Function Reference list, which helps a lot. But those are more on the Python side versus Micro Python. It can be a challenge sometimes. If I get really stuck, I do a @hel or @gadgetoid. They both work for Pimoroni.
Another option is to e-mail Tech Support directly. Contact Us for Raspberry Pi Technical Support - Pimoroni