Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • YouTube
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

SG Community Forum

  1. Home
  2. Comments & Feedback
  3. Wake up (from Deep sleep) example in documentation

Wake up (from Deep sleep) example in documentation

Scheduled Pinned Locked Moved Comments & Feedback
2 Posts 2 Posters 257 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jandls
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    1
    • cehlersC Offline
      cehlersC Offline
      cehlers
      wrote on last edited by
      #2

      Thanks a lot for the feedback, @jandls. This was taken straight from the old Pycom documentation and hasn’t been reviewed/updated yet.

      F1 introduction video: https://youtu.be/8fsoL0ga_lo

      1 Reply Last reply
      0

      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • YouTube