machine.wake_reason() returns empty

  • When i use the wake_reason() function to know witch button was pressed to wakeup from deepsleep the only return i get is (1, []). How do i fix this?

  • @Gijs It seems that your code worked with mode=machin.WAKEUP_ANY_HIGH. I had to comment out the while loop, unless it would get stuck there every time!

  • Global Moderator

    I am currently working to publish this as an example for using deepsleep:

    import machine
    import time
    (wake_reason, gpio_list) = machine.wake_reason()
    print("Device running for: " + str(time.ticks_ms()))
    print("Remaining sleep time: " + str(machine.remaining_sleep_time()) + "ms" )
    if wake_reason == machine.PWRON_WAKE:
        print("Woke up by reset button")
        #stop the sleep loop here
        while True:
    elif wake_reason == machine.PIN_WAKE:
        print("Woke up by external pin (external interrupt)")
        print(*gpio_list, sep=", ")
    elif wake_reason == machine.RTC_WAKE:
        print("Woke up by RTC (timer ran out)")
    elif wake_reason == machine.ULP_WAKE:
        print("Woke up by ULP (capacitive touch)")
    machine.pin_sleep_wakeup(('P3', 'P4'), mode=machine.WAKEUP_ANY_HIGH, enable_pull=True)
    machine.deepsleep(1000*60) #sleep for 1 minute
    print("This will never be printed")

    Now I can only reproduce this when i change the pin interrupt to

    machine.pin_sleep_wakeup(('P3', 'P4'), mode=machine.WAKEUP_ALL_LOW, enable_pull=True)

    But then it immediately wakes from sleep, as the pins are (obviously) both pulled low and it does not really sleep

    Let me know, I am interested in how that works for you!

Log in to reply

Pycom on Twitter