I’m creating an analogue clock on a 64x64 led display powered by an Interstate 75W and micropython. It’s working great, but when I get the current time using…
(year, month, day, weekday, hours, minutes, seconds, subseconds) = RTC.datetime()
subseconds is always 0. Is there a way to get the current time more accurately than to the nearest second? I’m not bothered on how close it gets to the real time, that would require a more complicated NTP algorithm, but to make the second hand move more smoothly I need to know how far through each second we are.
Thanks in advance,
The RTC of the Pico does not support subseconds (see 4.8.1 of the datasheet of the RP2040). In fact, I don’t know of any RTC that does. But external RTCs would give you sub-second timers. But this is not an option for the Interstate 75 W (you need an input-pin for that).
So the best you can do in between full seconds is to measure time yourself.
Thanks, that’s a shame. I do have a hack that involves storing ‘ticks_ms’ as soon as the clock is set, and calculating the sub seconds from that ((‘ticks_ms() - base_ticks) % 1000). It’s not completely aligned to when the rtc seconds rollover though, so time jumps backwards a bit sometimes.
Yea, this will never be perfect. I once programmed a countdown-timer based on ticks, and this was never exact.
What you could do: instead of jumping back in time slow down the second hand (or accelerating it in the other case). Makes the code probably complicated and ugly and might not be worth it. But I could imagine that if you calculate the angular speed once a minute based on your offset from the rtc-time, it should not be noticeable.
I have an RV3028 RTC Breakout wired up to my Interstate 75. It’s soldered to a Proto board and then plugs into the QW/ST port with a modified QWICC cable. I also have an LTR-559 and BME280 on the same proto board.
If you can solder, just snip the plug off of one end of a QWICC cable and solder that to the RV3028. If not there is Breakout Garden cable adapter that can be just plugged together with no soldering needed.
STEMMA QT / Qwiic to Breakout Garden Adapter (pimoroni.com)
The RV3028 won’t help either. It also does not support sub-seconds.
Ok, wasn’t sure, but just wanted to point out you can add an external i2c RTC via the QWIC connector. My bad, I could have worded it better.
Thanks everyone, good to know I was on the right track. I will play around with angular velocity and see if I can get that to work more smoothly than my current solution.