tomjorquera / pico-micropython-lowpower-workaround

Workaround for low power support in micropython for the Raspberry pico
GNU Lesser General Public License v3.0
58 stars 12 forks source link

No wake-up when lowpower_dormant is preceded by network.connect #16

Open thermophilus opened 1 year ago

thermophilus commented 1 year ago

The pico W wakes up from dormancy upon PIR trigger on GPIO 0. However, when this code is preceded by a network connection wlan.connect(ssid, password), the pico W does not wake-up anymore:

program detects time difference between PIR signals on GPIO 0 from pico W. If difference becomes too long (>20, line 50) program goes into dormancy. Wake-up is by PIR on GPIO 0.

activity is monitored by flashing of the PICO LED

problem 1: if preceded by a network connection (uncomment wlan.connect line 27), dormancy is initiated but now PIR signal on GPIO 0 does not wake-up the pico W.

problem 2: after dormancy, print commands to the REPL do not work anymore

from machine import Pin import time import network import lowpower

def detect_motion(pin): global Motion Motion=True

pin = Pin(0, Pin.IN, Pin.PULL_DOWN) led = Pin("LED", Pin.OUT) Motion=False; led.off() pin.irq(trigger=Pin.IRQ_RISING, handler=detect_motion) DORMANT_PIN = 0 # 0 ook voor Motion

wlan = network.WLAN(network.STA_IF) wlan.active(True) ssid = 'ssid' password = 'password' ###########################

wlan.connect(ssid, password)

###########################

while True:

t1 = time.time()
while True:

    led.on()
    time.sleep(0.2)
    led.off()
    time.sleep(0.2)

    if Motion:
        Motion=False
        t1 = time.time()

    t2 = time.time()
    diff = t2-t1
    #print("diff = ", diff)
    #time.sleep(0.1)

    if diff > 20:
        print("dormancy")
        lowpower.dormant_until_pin(DORMANT_PIN)
        #print("after after dorm") #does not work
tomjorquera commented 10 months ago

Hey @thermophilus thanks for the bug report and sorry for the very late answer.

I don't have any PicoW (yet) to try to reproduce your first described issue sadly. I will keep your ticket open in case I (or others!) have the opportunity to work on it.

Regarding the second problem with the REPL, I am afraid I don't have any lead on how to mitigate the issue sadly. It may be inherent to dormancy, "disconnecting" the pico from the REPL.