I'm trying to implement a script on a Pico 2 W that should wait the allotted time, wake up, do some stuff and then go back to sleep, but `machine.Timer` and `machine.lightsleep()` don't delay the running of the `do some stuff` at all.
With this code `do_stuff()` runs right away with no delay. And, yes, it doesn't matter what sleep_time is set to.
My understanding was that `deepsleep()` didn't work on the Pico 2, but I had thought that Timers and lightsleep() did, but I guess I was wrong.
Code:
timer = machine.Timer()def _timer_cb(t: machine.Timer): global timer_fired timer_fired = Truewhile True: try: sleep_time = next_start() timer.init(mode=timer.ONE_SHOT, period=(sleep_time * 1000), callback=_timer_cb) machine.lightsleep() do_stuff() except KeyboardInterrupt: timer.deinit() dont_do_stuff()My understanding was that `deepsleep()` didn't work on the Pico 2, but I had thought that Timers and lightsleep() did, but I guess I was wrong.
Statistics: Posted by TomCamp — Sun Nov 23, 2025 4:06 am — Replies 0 — Views 38