Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Pytrack get_wake_reason: detect power on

    Scheduled Pinned Locked Moved Expansion Board
    pytracksleepwake upwake reason
    6 Posts 2 Posters 1.3k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F Offline
      fstaine
      last edited by

      Hi,
      I am working with a Pytrack and a Fipy, and I must detect when the board is powered-on.

      When I get the pytrack.get_wake_reason, I get correct values when awaken by button, accelerometer and timer after a pytrack.go_to_sleep().
      However, after a power down (unplug the USB), the wake reason is kept from the last powerdown (WAKE_REASON_ACCELEROMETER for example) for a short persiod, and after a long disconnection (like >1 hour), the pytrack.get_wake_reason method gives me strange values, like 51 (0b110011).

      How can I detect when the board is powered-on ?

      Thanks

      1 Reply Last reply Reply Quote 0
      • catalinC Offline
        catalin
        last edited by

        hi @fstaine, I trying to investigate this, I see there is an inconsistency.

        Catalin,

        Have you checked out our docs for the answer? (Now with an easy search function) https://docs.pycom.io
        Check out our newly revamped device management platform, Pybytes! https://pybytes.pycom.io/

        1 Reply Last reply Reply Quote 0
        • catalinC Offline
          catalin
          last edited by catalin

          hi @fstaine,

          Could you test the attached pytrack firmware version; if the board is powered on, it should have both the get_wake_reason() and get_sleep_remaining() reset to zero. Is this behaviour ok?

          pytrack_v11_dev05Jun.dfu

          Catalin,

          Have you checked out our docs for the answer? (Now with an easy search function) https://docs.pycom.io
          Check out our newly revamped device management platform, Pybytes! https://pybytes.pycom.io/

          F catalinC 2 Replies Last reply Reply Quote 0
          • F Offline
            fstaine @catalin
            last edited by

            hi @catalin

            I tried with the given firmware:

            • I get correct values for Accelerometer (1), push button (2) and timer (4) on get_wake_reason() (as before)
            • I get 0 from get_wake_reason() after a power on (Yay !)
            • I don't know how to test WAKE_REASON_INT_PIN...

            Concerning get_sleep_remaining(), the board never returns when I call the method from the serial REPL (in fact, calibrate_rtc() blocks at self._write(bytes([CMD_CALIBRATE]), wait=False) )

            When I do from a scipt, I get the correct values (Havn't tested the values when a timer wasn't set with the previous firmware though...)

            Thank's a lot for the fix ! I go change my ugly hack in my code :)

            catalinC 1 Reply Last reply Reply Quote 0
            • catalinC Offline
              catalin @catalin
              last edited by

              Just for further references, there a workaround solution with code here: https://forum.pycom.io/topic/3312/lopy-pytrack-deepsleep-wake-then-lock-until-power-removed/2

              Mainly it's:

              wake = py.get_wake_reason()
              
              print("Waked by ", end='')
              # display the wake reason code
              if wake == 1:
                  print("Accelerometer")
                  led.h(led.RED)
              elif wake == 2:
                  print("Button")
                  led.h(led.GREEN)
              elif wake == 4:
                  print("Timer")
                  led.h(led.CYAN)
              elif wake == 8:
                  print("Interrupt Pin")
                  led.h(led.ORANGE)
              else:
                  print("No Wake")
              

              Catalin,

              Have you checked out our docs for the answer? (Now with an easy search function) https://docs.pycom.io
              Check out our newly revamped device management platform, Pybytes! https://pybytes.pycom.io/

              1 Reply Last reply Reply Quote 0
              • catalinC Offline
                catalin @fstaine
                last edited by catalin

                @fstaine
                WAKE_REASON_INT_PIN: can be generated from PIC_RC1(pin6 on External IO Header) https://docs.pycom.io/chapter/datasheets/boards/pytrack.html

                <later edit:> Please take a look here function pytrack.setup_int_pin_wake_up([rising_edge = True]).

                Catalin,

                Have you checked out our docs for the answer? (Now with an easy search function) https://docs.pycom.io
                Check out our newly revamped device management platform, Pybytes! https://pybytes.pycom.io/

                1 Reply Last reply Reply Quote 0

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • 1 / 1
                • First post
                  Last post

                Pycom on Twitter

                Pycom