Lightsleep with wake from interrupt - how?

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
John57
Posts: 10
Joined: Sat Mar 06, 2021 5:26 am

Lightsleep with wake from interrupt - how?

Post by John57 » Sat Mar 06, 2021 5:42 am

Hello,

I can activate machine.lightsleep() and it appears to work. However I cannot find a way to enable a gpio interrupt to terminate the sleep.

There is a function in the library (gpio.c) called gpio_set_dormant_irq_enabled but it doesnt appear to have an associated python method.

Other micropython boards use the Pin.irq to define what level of sleep it can interrupt but not in the pico code using a wake argument.

Does anyone know how to wake from sleep (not including timers).

I want to wake the board using a gpio button interrupt, or an attached sensor (also on gpio).

Regards John

User avatar
CmdrDeLiver
Posts: 27
Joined: Thu Dec 05, 2019 6:30 pm

Re: Lightsleep with wake from interrupt - how?

Post by CmdrDeLiver » Fri Mar 12, 2021 3:22 pm

John,

Looking through the source, I found what might be a hint. I'm not sure if this is at all helpful. Find "wake". You might also search that repository for something like rp2 (the port) and sleep or wake. If you find an answer, I'd be interested. My RP2s are still in the packaging.

https://github.com/micropython/micropyt ... ne.Pin.rst

Mike

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Lightsleep with wake from interrupt - how?

Post by pythoncoder » Sat Mar 13, 2021 4:25 pm

This appeared to work inasmuch as it wakes from the sleep and toggles the LED:

Code: Select all

from machine import Pin, lightsleep
p25 = Pin(25, Pin.OUT)
p0 = Pin(0, Pin.IN, Pin.PULL_UP)
def foo(_):
    p25(not p25())  # Toggle the LED

p0.irq(foo, trigger=Pin.IRQ_FALLING)
while True:
    lightsleep()
I couldn't detect the drop in current due to lightsleep. This is almost certainly due to my test setup: I only have one Pico and it is connected to various hardware which will be drawing power. I must order a couple more.
Peter Hinch
Index to my micropython libraries.

John57
Posts: 10
Joined: Sat Mar 06, 2021 5:26 am

Re: Lightsleep with wake from interrupt - how?

Post by John57 » Sun Mar 14, 2021 1:41 am

Thanks for the Comments (sorry for the delay - been holidaying on a beach out of town).

I have searched for sleep through the pico library and port code already, but cant remember whether i searched for wake.

However I also saw the interrupts were seen after lightsleep calls but if you put a statement after the lightsleep (eg print) then the print statement does not execute on the interrupt , indicating that program is not continuing after the last executed statement (lightsleep). I still hoped that the interrupt would fire and it does.

Cheers

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Lightsleep with wake from interrupt - how?

Post by pythoncoder » Sun Mar 14, 2021 1:59 pm

... program is not continuing after the last executed statement (lightsleep)
I take your point. I don't know how to fix that: the docs are evidently wrong as there is no machine.SLEEP constant.
Peter Hinch
Index to my micropython libraries.

User avatar
CmdrDeLiver
Posts: 27
Joined: Thu Dec 05, 2019 6:30 pm

Re: Lightsleep with wake from interrupt - how?

Post by CmdrDeLiver » Mon Mar 15, 2021 12:46 am

Damien was the last to receive git blame on that code. Is there a way to tag him?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Lightsleep with wake from interrupt - how?

Post by pythoncoder » Mon Mar 15, 2021 9:12 am

I have raised an issue.
Peter Hinch
Index to my micropython libraries.

John57
Posts: 10
Joined: Sat Mar 06, 2021 5:26 am

Re: Lightsleep with wake from interrupt - how?

Post by John57 » Tue Mar 16, 2021 5:49 am

Thanks for that.

What I seems to be missing is an option to activate a particular interrupt that will cause a wake from sleep, or that any interrupt will cause a wake from sleep.

The lastest code version of the code does now include some linkages to the gpio_set_dormant_irq_enabled function, where none was there before. But still not sure how this is used.

I can paste the simple code that I have been using to test this if wanted. It is basically an interrupt for a button press, and a main loop where sleep is activated after a number of iterations, immediately followed by a print statement, which should be run on waking up.

John

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Lightsleep with wake from interrupt - how?

Post by pythoncoder » Tue Mar 16, 2021 1:07 pm

The Raspberry Pi Pico port is very new; it seems that the wake from lightsleep functionality is missing. I think we have to wait until the maintainers get the chance to deal with the issue - they have quite a few others to contend with, so patience is in order ;)
Peter Hinch
Index to my micropython libraries.

John57
Posts: 10
Joined: Sat Mar 06, 2021 5:26 am

Re: Lightsleep with wake from interrupt - how?

Post by John57 » Wed Mar 17, 2021 1:00 am

I realize that but thought I maybe missing something.

Post Reply