My micropython environment is as follows:I'm running a TOTP implementation on my Pico-W (the code) to maintain a backup of my 2 factors, after the last time my phone had a breakdown.
At startup, I synchronize the RTC to pool.ntp.org using ntptime (missing from docs.micropython.org!!) via the WiFi, to get everything initialized.
As per my understanding of how TOTP works, the rollover is aligned to every half minute on the clock. My implementation gives a timer bar to visualize the switchover on the display. Updates aren't needed constantly, so to keep things less hectic, I use sleep_ms(250) to idle between update loops. However, this (or smaller numbers) still lead to somewhat erratic visual updates atleast once every 5 to 8 seconds.
What I'm trying to figure out is a way to ensure that the updates happen as close to a second apart as possible. My go-to solution would be to reduce the sleep down from 250ms down to a shorter timeframe. However, my basic understanding of computing makes me feel that there is probably a better way to do this, probably something that triggers updates 100ms or so before the second changes.
However I have no idea how and where to start from. Any suggestions? Even suggestions on how to frame the problem correctly are welcome.
Code:
MicroPython v1.23.0-preview.322.g5114f2c1e on 2024-03-30; Raspberry Pi Pico W with RP2040Type "help()" for more information.>>> machine.freq()125000000
At startup, I synchronize the RTC to pool.ntp.org using ntptime (missing from docs.micropython.org!!) via the WiFi, to get everything initialized.
As per my understanding of how TOTP works, the rollover is aligned to every half minute on the clock. My implementation gives a timer bar to visualize the switchover on the display. Updates aren't needed constantly, so to keep things less hectic, I use sleep_ms(250) to idle between update loops. However, this (or smaller numbers) still lead to somewhat erratic visual updates atleast once every 5 to 8 seconds.
What I'm trying to figure out is a way to ensure that the updates happen as close to a second apart as possible. My go-to solution would be to reduce the sleep down from 250ms down to a shorter timeframe. However, my basic understanding of computing makes me feel that there is probably a better way to do this, probably something that triggers updates 100ms or so before the second changes.
However I have no idea how and where to start from. Any suggestions? Even suggestions on how to frame the problem correctly are welcome.
Statistics: Posted by samveen — Tue Apr 09, 2024 10:32 am