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!
Writing code for a 'Mother clock'
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Writing code for a 'Mother clock'
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.
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.
Index to my micropython libraries.
Re: Writing code for a 'Mother clock'
Perfect! This is exactly what I needed. Thank you.
EDIT: I'll pop it on github once I've got it running
EDIT: I'll pop it on github once I've got it running
Re: Writing code for a 'Mother clock'
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
On the off chance someone wants a to do something similar:
Github repository: https://github.com/veebch/clock
Video Explainer: https://youtu.be/ZhPZBuXZctg