-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
lightsleep() not working properly Pi Pico WH v1.24.0 #16180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Which is much more simple use case, do not works. There is no sleep at all while executing tested on a Pico W and 1.24 and 1.25 latest snapshot |
@RYoder97 I just tried Micropython 1.23.0 and |
I'm sorry, forgive me because I'm new to Micropython still... |
@RYoder97 this is just a proof of concept to reproduce the bug, it's to prove that on 1.24.0 and more recent lightsleep never do anything |
Ah okay! So I'm not going crazy! I tried 1.22.2 and 1.23.0 and it works. However, you still need to specify a time otherwise the Pi Pico will be permanently asleep. This is less than ideal, but a workaround would be to set the time for a long time, or, set it for a long time and put it to sleep again after it wakes up. If a contributor is able to update the source code for the next release though, it would be greatly appreciated. |
I hit something similar before I saw this issue. For me its ok as is with 1.24.0 on pico 1. On a Pico 2 the 1st lightsleep does not work. if I comment out the time.sleep(0.1) in the example below, then both lightsleeps work fine. Hope this helps pin it down. import machine led = machine.Pin("LED", machine.Pin.OUT) while True: |
I am seeing same issue on Rpi PICO-W (rp2040) .. lightsleep is broken starting with 1.24 up to latest commit (tested a few days ago so not sure if something got fixed since then) |
I did some investigation into this and reported my findings in discussion https://github.com/orgs/micropython/discussions/12573. The main point I noted there is the micropython documentation for machine.lightsleep() is clear that it can return early.
Between 1.23.0 and 1.24.0 commit 74fb42a added use of rp2040 hardware timer 2. When hardware timer 2 expires lightsleep() will return. My testing, as I reported in the discussion indicates lightsleep() average sleep is about 60 milliseconds. Users who need to sleep for an exact amount of time need to call lightsleep() in a loop.
|
Thanks for looking into it, cpottle9, and everyone else too for their time considering these issues. The work by cpottle9 raises some interesting questions. I do not know as much as others do about the code but, sticking to the original issue on the pico w :
He also highlighted:
So are we suggesting that lightsleep is/will be intentionally different for a Pico and a PicoW?
To me, this suggests that you can voluntarily set up such things if you want to interrupt the sleep, if you don't it will wake up when you asked it.
There seems to me to be some overlapping issues here that are making even understanding the implications of the differences between different hardware and different software versions more difficult. Obviously, sorry if I am missing something and wasting peoples time. |
@ssotheremail, first I am a user of micropython and PICO W like you. I will do my best to answer you questions. @projectgus would provide better answers.
|
Quick update. I submitted a pull request to issue #16181 that addresses the problem of lightsleep returning early. I posted on the raspberry pi forum https://forums.raspberrypi.com/viewtopic.php?t=380979 expressing my opinions about lightsleep on PICO. |
Apologies, I missed this issue when it was opened. Thanks @cpottle9 for the investigation and the heads-up. There's a more detailed explanation in the PR, but one of the root causes here is that before v1.24 the MicroPython soft timer expiring did not wake the rp2 from lightsleep. Commit 74fb42a (released in V1.24) accidentally changed this so that soft timer did wake the rp2 from lightsleep, and on the PICO_W board there is a wakeup for lwIP every 64ms. So, effectively, this limited the max lightsleep time to 64ms. Draft PR with the fix, so soft timer doesn't wake from lightsleep any more, is #16431. I don't expect that PR will resolve everything reported here, in particular a pin irq not waking from |
There is an older issue tracking this at #7035 . I've just left a comment there and opened another draft PR. I think the still-open issues #16181 and #7035 are tracking everything reported in this issue. Does that seem correct? (EDIT: Rephrased this.) |
Thanks for all this work. Just had a quick check with RPI_PICO2-20241218-v1.25.0-preview.125.gd10cda66d.uf2 in case the fixes have come through and the same versions for pico and pico w (cant see previews for pico 2 w). |
ok, as its nearly Christmas, I have finally put the effort into fixing my micropython build problems on my pi 5 (I still cant do pico2W but never mind for now.....) I have managed to build 1.25.0.preview130 for the others so now: Child to Adult: How many sleeps till Christmas? Sorry. |
Sorry for the confusing messaging, I've edited my previous post to clarify what I meant. At the moment no fixes have been merged, so the preview builds won't be any different. If you care in particular about lightsleep with a timeout then I suggest watching #16181. When that issue closes then the next preview build after that should have the relevant fix in it. |
Port, board and/or hardware
Raspberry Pi Pico WH
MicroPython version
MicroPython v1.24.0 on 2024-10-25; Raspberry Pi Pico W with RP2040
Reproduction
Attempt following code, both with lightsleep() having no ms argument and one with:
Expected behaviour
Expect LED to react to button press when asleep and execute wake_up function. LED is on by default. LED should toggle/turn off when button is pressed down, both when machine is asleep and not asleep.
Observed behaviour
USB power tester indicates that the board sleeps only when NO MILLISECONDS ARGUMENT IS SPECIFIED.
When milliseconds ARE SPECIFIED, board does not appear to sleep as power consumption does not drop according to the USB tester. The board continues to work at full power, and the LED reacts to the button.
When NO MILLISECONDS ARE SPECIFIED, board appears to go to sleep (reducing power from >10ma to 0-1ma. But button does not do anything to LED.
Additional Information
I have tried adding the
wake
argument tobutton.irq
, but Micropython says that extra keyword arguments are present.I understand sleeping may have issues on the Pico W models. I have also tried turning off WiFi/setting the pin associated with Wifi to "low". That does not seem to have any impact whatsoever, since my code never explicitly turns Wifi on
https://forums.raspberrypi.com/viewtopic.php?p=2266590#p2266590
Code of Conduct
Yes, I agree
The text was updated successfully, but these errors were encountered: