Lightsleep with wake from interrupt - how?
Lightsleep with wake from interrupt - how?
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
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
- CmdrDeLiver
- Posts: 27
- Joined: Thu Dec 05, 2019 6:30 pm
Re: Lightsleep with wake from interrupt - how?
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
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
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Lightsleep with wake from interrupt - how?
This appeared to work inasmuch as it wakes from the sleep and toggles the LED:
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.
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()
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Lightsleep with wake from interrupt - how?
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
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
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Lightsleep with wake from interrupt - how?
I take your point. I don't know how to fix that: the docs are evidently wrong as there is no machine.SLEEP constant.... program is not continuing after the last executed statement (lightsleep)
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
- CmdrDeLiver
- Posts: 27
- Joined: Thu Dec 05, 2019 6:30 pm
Re: Lightsleep with wake from interrupt - how?
Damien was the last to receive git blame on that code. Is there a way to tag him?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Lightsleep with wake from interrupt - how?
I have raised an issue.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Lightsleep with wake from interrupt - how?
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
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
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Lightsleep with wake from interrupt - how?
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.
Index to my micropython libraries.
Re: Lightsleep with wake from interrupt - how?
I realize that but thought I maybe missing something.