Sorry – I’ve had to pull a lot of useful hyperlinks below due to first time post restrictions. I’ll see if I can edit them back in.
I’ve been playing around with lightsleep and deepsleep from the micropython machine lib on 0.0.11 of the Pimoroni Pico MicroPython for RP2350 / Pico2 boards.
tldr:
I’ve found that niether lightsleep nor deepsleep appear to work on the current release (the pico never wakes up), but work on the automatic pre-releases of micropython (v1.25.0-preview.217.gb4f53a0e5 (2025-01-19). I’m wondering if there’s a way I’m missing to build firmware from this pre-release branch (if I can find it) and include all the good screen driver tools for Pimoroni.
More info:
I’ve done a fair bit of googling, and it seems that there is general confusion around these features generally with 2350 chips and the main (non Pimoroni) micropython library. Without wanting to get bogged down in this confusion I’ve done some exploration.
I have found that v1.25.0-preview.217.gb4f53a0e5 (2025-01-19) has operational lightsleep and deepsleep functions, although lacks the Pimoroni screen drivers.
I forked both the micropython and pimoroni-pico-rp2350 repos from pimoroni and created two builds of pimoroni-pico-rp2350, and did the following:
I did one build where I just build based on the existing branch and repo of micropython that 0.0.11 (built from feature/wireless) used, in case this repo had been updated since last release.
I then did another build testing the inclusion of this commit from micropython/micropython as I skimmed the commits for references to sleep and thought it could be an easy win. No joy (although I love how easy you guys have made it to swap micropython repos, thanks!).
I then did another build where I pulled micropython/micropython’s master into my forks master, effectively making a build that should be up to date with micropython/micropython. However this still didn’t work.
If I get time, my next steps are:
Work out where micropython/micropython is generating v1.25 (I’ve not had a look at the GHA yet, but I am assuming this comes from the latest master commit)
Attempt a build from micropython/micropython and check this works
If this works, potentially look into a git diff on my forked micropython branch, which is the micropython/repo merged with the pimoroni/micropython repo, and see if I can spot anything (I’ve not worked in C before).
I’ll probably have a bit more of a look at this at some time that isn’t the early hours, but I’d welcome any thoughts on this regarding the pimoroni repos, as lightsleep and deepsleep are both very useful for battery-powered eink displays.
I’m hoping I’ve not got the wrong end of the stick here in terms of how pimoroni drivers are built, but let me know if I have!
When you report about the stock micropython having “operational lightsleep and deepsleep functions”, what does this specifically mean? Did you measure current? Did you check if e.g. WLAN still works after wakeup?
The reason I am asking is because I currently work on implementing this for CircuitPython and it turns out that there a number of challenges. E.g. the CYW-chip does not like clock-changes at all, but switching to low-power modes for light/deep-sleep does change clocks. A test program like yours works fine (and I use a very similar one), but this is not using the CYW-chip at all.
So if you find some time, please
measure current during normal, sleep, lightsleep and deepsleep
start a WLAN-connection before entering sleep-modes
check the status of the WLAN-connection after sleep-modes
Regarding the last item: I believe that WLAN needs to be disabled before light/deep-sleep and reenabled afterwards (with a reconnect from the Python code). But I am still working on this.
By operational, I mean it enters a state where no code is executed for x time, and resumes the program afterwards. I don’t have a way to measure current currently – however I have noted the usb port disconnects on deep sleep.
I’ve had a bit of a play around with this on a repo I already have a wifi service in. Branch is here. Simply flash the v1.25.0-preview.217.gb4f53a0e5 (2025-01-19) hardware, add a secrets.py file matching the secrets-example.py if you want to have a play around.
The network works fine after light and deep sleep but I do note that wifi is not automatically disconnected during either light or deep sleep – check_network_connectivity_with_reconnecting and check_network_connectivity_without_reconnecting in the branch above have the same outcome
Thanks for the reply. I suggest that you buy a cheap INA219 breakout. This will measure current down to 400µA, which is below the range you can expect with the Pico. You can expect up to 200 samples per second (i.e. every 5ms), which does not pick up every small peak (e.g. during WLAN operation), but will give a valid measurement while testing light and deep sleep modes. Example code is also available, so setting this up is not too much work.
Otherwise, I had a look at the MicroPython code for the sleep-modes. It bails out if it detects WLAN-activity, but I am not sure what qualifies for “WLAN-activity”. In addition, the only difference between lightsleep and deepsleep in MicroPython is a hard reset after deepsleep, which explains the USB-port dispconnect you are experiencing.
Very interesting. I’m going to park this side quest for now then, as this is a small (optional) component to the project I’m looking at.
Once I have the rest of the coding done, I’ll look to revisit this topic and will post any updates of note, as I’m keen not to fall down a rabbit hole!