Writing code for a 'Mother clock'

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
martch
Posts: 4
Joined: Sat Nov 27, 2021 9:13 am

Writing code for a 'Mother clock'

Post by martch » Sat Jan 22, 2022 7:27 pm

I have a pretty straightforward task but before I launch myself at some awful infinite loop, I thought I'd ask my elders and betters.

I am programming a pico to:

- (according to an attached RTC) send a pulse to an old slave clock every minute, on the minute (to advance the minute hand).
- In the wee hours, check in with a radio clock (dcf77), update the RTC and, if needed adjust the clock.

Threads seem like the obvious way to go, but other suggestions are welcome/ encouraged. Actually, reassuring me that threads are the way to go is also good.

Thanks!

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Writing code for a 'Mother clock'

Post by pythoncoder » Sun Jan 23, 2022 2:11 pm

The Pico only supports two threads, which are implemented on the two cores.

However I don't think this is the best approach - the processing load of what you aim to do is tiny. One way is to use uasyncio - which is the approach I normally advocate. But even that may be over complex.

In this case a timer interrupt can generate the once per minute pulses. You'd need to maintain a count of pulses. When you do a radio update, compare the number of pulses with the number that should have been sent. If they don't match, the period of the timer could be adjusted for the next 24hrs: change the period just after a pulse has been sent.
Peter Hinch
Index to my micropython libraries.

martch
Posts: 4
Joined: Sat Nov 27, 2021 9:13 am

Re: Writing code for a 'Mother clock'

Post by martch » Sun Jan 23, 2022 4:41 pm

Perfect! This is exactly what I needed. Thank you.

EDIT: I'll pop it on github once I've got it running

martch
Posts: 4
Joined: Sat Nov 27, 2021 9:13 am

Re: Writing code for a 'Mother clock'

Post by martch » Sat Feb 05, 2022 11:19 am

For the sake of simplicity, I went for a loop :)

On the off chance someone wants a to do something similar:

Github repository: https://github.com/veebch/clock

Video Explainer: https://youtu.be/ZhPZBuXZctg

Post Reply