Pi Pico - Sleep & Dormant states

Thanks a lot @James46717 , let see if that do so good! I will see if some of the folks who reported issues before can test the changes.

Don’t we all? :smile:

2 Likes

Hi, I have tried this on a Lilygo T-Pico C3 (on the RP2040 side) but I can’t get the prints when the microcontroller wakes up.
I copied the above code in a lowpower.py file, and imported it in my sketch as follows

from machine import Pin
from time import sleep

import lowpower

btn6 = Pin(6, Pin.IN, Pin.PULL_DOWN)
btn6.irq(lambda e: print("button 6 event!"), Pin.IRQ_RISING)
btn7 = Pin(7, Pin.IN, Pin.PULL_DOWN)
btn7.irq(lambda e: print("button 7 event!"), Pin.IRQ_RISING)

c = 1
LED_BUSY = 25
busy_led = Pin(LED_BUSY, Pin.OUT)

def blink_n_times(n):
    for _ in range(n):
        busy_led.value(1)
        sleep(0.5)
        busy_led.value(0)
        sleep(0.5)

while True:
    print('count: '+str(c))
    blink_n_times(c)
    print("before dormant")
    lowpower.dormant_until_pin(6)
#     lowpower.dormant_until_pin(7)
    sleep(0.5)
    print("after dormant")
    sleep(0.5)
    c += 1

But, I never get the “after dormant” nor “button 6 event” message after pushing the buttons. However, the led blink count increases each time. However, it seems the RP2040 is sleeping and then awakes when I push the button.
But how can I recover the prints?

1 Like

Welcome Fabrice!!

If you keep the RP2040 from entering any sleep mode do you see the interrupts firing?

I’d definitely check out the project where Jim applies low power modes on the Pico: Simple Relay Timer - Tutorial Australia

It might be possible that the UART peripheral isn’t awakened, though I haven’t had an extensive look through Jim’s amazing port.

Liam

Hi Liam, thanks for your answer.
Yes I can see the messages from the interrupts.

I tried to add sleep(1) after the dormant instruction with no luck.

I am using now the deep sleep implementation of Tom Jorquera (see message above) which enables to wake up from several pins:
lowpower.dormant_until_pins([7,6])
I get wake-up fine but no prints either.