Page 1 of 2

Lightsleep with wake from interrupt - how?

Posted: Sat Mar 06, 2021 5:42 am
by John57
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

Re: Lightsleep with wake from interrupt - how?

Posted: Fri Mar 12, 2021 3:22 pm
by CmdrDeLiver
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

Re: Lightsleep with wake from interrupt - how?

Posted: Sat Mar 13, 2021 4:25 pm
by pythoncoder
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.

Re: Lightsleep with wake from interrupt - how?

Posted: Sun Mar 14, 2021 1:41 am
by John57
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

Re: Lightsleep with wake from interrupt - how?

Posted: Sun Mar 14, 2021 1:59 pm
by pythoncoder
... 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.

Re: Lightsleep with wake from interrupt - how?

Posted: Mon Mar 15, 2021 12:46 am
by CmdrDeLiver
Damien was the last to receive git blame on that code. Is there a way to tag him?

Re: Lightsleep with wake from interrupt - how?

Posted: Mon Mar 15, 2021 9:12 am
by pythoncoder
I have raised an issue.

Re: Lightsleep with wake from interrupt - how?

Posted: Tue Mar 16, 2021 5:49 am
by John57
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

Re: Lightsleep with wake from interrupt - how?

Posted: Tue Mar 16, 2021 1:07 pm
by pythoncoder
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 ;)

Re: Lightsleep with wake from interrupt - how?

Posted: Wed Mar 17, 2021 1:00 am
by John57
I realize that but thought I maybe missing something.