Wake up (from Deep sleep) example in documentation
-
Could it be that there are some errors in the example script in the documentation available at link:
import machine import time wake_reason = machine.wake_reason() print("Device running for: " + str(time.ticks_ms()) + "ms") if wake_reason == machine.PWRON_RESET: print("Woke up by reset button") elif wake_reason == machine.PIN_WAKE: print("Woke up by external pin (external interrupt)") elif wake_reason == machine.ULP_WAKE: print("Woke up by ULP (capacitive touch)") elif wake_reason == machine.TOUCHPAD_WAKE: print("Woke up by touchpad") machine.deepsleep(1000*60) #sleep for 1 minute print("This will never be printed")I think there is some mixup between machine.wake_reason() and machine.reset_cause().
When the F1 is woken up from deep sleep because the reset button is pressed, the wake_reason=0 and reset_cause=1
When the F1 is woken up from deep sleep by an external pin (wake_on_ext0), the wake_reason=2 and reset_cause=4
And since the constant machine.PWRON_RESET=2, this script will give the message “Woke up by reset button” when it was actually woken up by an external pin. And when it is woken up by the reset button, it will not produce a message. Because in that case wake_reason=0, so it fulfils none of the if conditions.The meaning of machine.wake_reason() and machine.reset_cause() codes (and the definition of the constants) can be obtained by:
>>> import machine >>> help(machine) object <module 'umachine'> is of type module __name__ -- umachine mem8 -- <8-bit memory> mem16 -- <16-bit memory> mem32 -- <32-bit memory> freq -- <function> reset -- <function> (I dropped some lines here) reset_cause -- <function> HARD_RESET -- 2 PWRON_RESET -- 1 WDT_RESET -- 3 DEEPSLEEP_RESET -- 4 SOFT_RESET -- 5 wake_reason -- <function> PIN_WAKE -- 2 EXT0_WAKE -- 2 EXT1_WAKE -- 3 TIMER_WAKE -- 4 TOUCHPAD_WAKE -- 5 ULP_WAKE -- 6 >>>I also do not understand why the example script reads as:
elif wake_reason == machine.ULP_WAKE: print("Woke up by ULP (capacitive touch)")I would think that when the F1 is woken up by the ULP, that has nothing to do with ‘capacitive touch’. Or do I get it wrong?