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

Doesn't wake #8

Closed ToracX closed 1 year ago

ToracX commented 2 years ago

Having a bit of trouble. It is sleeping fine but not waking up. Any tips? Checked all connections ground etc.

tomjorquera commented 2 years ago

Sorry to hear you have troubles @ToracX. Like it says in the README, this lib is mostly a hacky workaround, so issues like your can definitely happens.

Can you maybe share your code and setup?

tomjorquera commented 2 years ago

Hey @ToracX, I know it's been some time, but another user suggested some changes that may (or may not) solve your issue. It's a little hard to say because I could not reproduce so I cannot test it myself, but if you're up to it the current modifications live a the clear-clocks branch https://github.com/tomjorquera/pico-micropython-lowpower-workaround/tree/clear-clocks

If by chance you have time to test and give feedback on the changes it will be appreciated!

ToracX commented 2 years ago

Hi, Thanks for the work. Currently my project is running with your code. Only to wake it I have to restart the pico by code. When I have time I will try to revisit the code. May take some time.

FabriceAuz commented 2 years ago

Hi, I have the same problem on a T-Pico C3 board, on the RP2040 processor. It has 2 buttons, connected to GPIO 6 and 7. It's weird because the first time I tested the dormant mode, it worked: I got the message

Button 6 event!

But I never saw this message anymore again. I have tried the clear-clocks modification, but no change.

My code:

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 = 0
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(4)
    print("before dormant")
    lowpower.dormant_until_pins([6, 7])
    print("after dormant")

I also wanted to check if the variables contents remain after deep sleep, but as it doesn't wake up, I can't...

FabriceAuz commented 2 years ago

I answer to myself... Now I see that it wakes up, but no message are displayed. This new code works: I can see the number of led blinks increase each time I press one of the 2 buttons.

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_pins([7,6])
    print("after dormant")
    c += 1

Does anyone know why there is no message printed in the console?

tomjorquera commented 2 years ago

@FabriceAuz I don't have a lot of bandwidth right now, but I will try to take a look when I have more. In the meantime please keep me informed in case you make further progress.

An idea on the top of my head in the meantime: I wonder if the print could try to use systems that are not actually fully reinitialized by the time we reach the print. If that's true, possibly waiting just a little after waking up could make the symptom disappear.

FabriceAuz commented 2 years ago

Thank you Tom. That's what I thought also, I did this, with no luck:

    lowpower.dormant_until_pins([7,6])
    sleep(0.5)
    print("after dormant")
    sleep(0.5)
funjspi commented 1 year ago

This is what I'm using to accomplish this, seems to work OK.

was_sleeping = False

  while True:
      if was_sleeping == True:
          print("Woke up!")
          was_sleeping = False
      blink_n_times(4)
      print("going to sleep...")
      was_sleeping = True
      lowpower.dormant_until_pin(DORMANT_PIN)

EDIT: Nevermind... It worked the first time or two, then it doesn't. Seems that after it goes dormant, it loses the ability to print via USB serial connection? The light flashes like it should, so i know the code is working.

lesept777 commented 1 year ago

Thanks for this test. Do you see the same with lowpower.dormant_until_pins, because I need 2 wake up buttons?

funjspi commented 1 year ago

no I only have 1 button wired up, so didn't test it with "dormant_until_pins.

so far i have had it running on 2 AAA batteries for several days. Several times a day I push the button to verify it is still working and it can still wake/sleep on battery power. Every time I push the button it logs temp and voltage to a txt file. After I get a RTC module and some temp/humidity sensors, I want to make a solar powered weather station, maybe adding LORA to it later to transmit data back to my home server.

In a use case like this, there is no need for the "print()" function, so i removed it from my code. I wasn't able to figure out why the print was failing after sleeping, but the LED blinking is a good method to tell if the script is running so I decided to not bother with it.

Hope that helps!

Yoda-Soda commented 1 year ago

no I only have 1 button wired up, so didn't test it with "dormant_until_pins.

so far i have had it running on 2 AAA batteries for several days. Several times a day I push the button to verify it is still working and it can still wake/sleep on battery power. Every time I push the button it logs temp and voltage to a txt file. After I get a RTC module and some temp/humidity sensors, I want to make a solar powered weather station, maybe adding LORA to it later to transmit data back to my home server.

In a use case like this, there is no need for the "print()" function, so i removed it from my code. I wasn't able to figure out why the print was failing after sleeping, but the LED blinking is a good method to tell if the script is running so I decided to not bother with it.

Hope that helps!

It's normal for the pico to lose serial connection with your computer after going into dormant mode thus you will stop seeing any print() functions to screen.

tomjorquera commented 1 year ago

Thanks for your inputs @funjspi and @Yoda-Soda ! I've merged the changes into the main branch. So we should be all good for now