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

    Can you use Pin.callback(...) to invoke deepsleep.go_to_sleep(...)?

    Scheduled Pinned Locked Moved SiPy
    sipyexpansionboarddeepsleepcallback
    3 Posts 2 Posters 1.2k Views 2 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.
    • DDecoeneD Offline
      DDecoene
      last edited by

      Hello,

      Is it possible to invoke deepsleep.go_to_sleep() form a Pin.callback()?

      Look at this code:

      from machine import Pin, Timer
      from deepsleep import DeepSleep
      import deepsleep
      
      
      def handler(button):
         ds.enable_pullups('P18')  # can also do ds.enable_pullups(['P17', 'P18'])
         ds.enable_wake_on_fall('P18') # can also do ds.enable_wake_on_fall(['P17', 'P18'])
         print("Button pushed")
         ds.go_to_sleep(20)
      
      
      ds = DeepSleep()
      
      # get the wake reason and the value of the pins during wake up
      wake_s = ds.get_wake_status()
      print(wake_s)
      
      if wake_s['wake'] == deepsleep.PIN_WAKE:
         print("Pin wake up")
      elif wake_s['wake'] == deepsleep.TIMER_WAKE:
         print("Timer wake up")
      else:  # deepsleep.POWER_ON_WAKE:
         print("Power ON reset")
      
      
      button=Pin("G17",Pin.IN, pull=Pin.PULL_UP)
      irq=button.callback(trigger=button.IRQ_FALLING, handler=handler)
      
      print('booted---')
      
      

      This code does invoke the deepsleep but the SiPy does not wake up anymore (only pressing the reset button helps)

      It did work at some point though, just bringing 'P18' low to wake it up did not work, but let's solve that in another post.

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        jmarcelino @DDecoene
        last edited by jmarcelino

        @ddecoene
        Unfortunately G17 is the pin used to communicate between the SiPy and the the deep sleep shield so setting it as a pull up and/or pressing the button affects that communication and so the wake isn’t properly set anymore.

        I guess you could try disabling the pull up and also waiting for the button to released before calling the ds. functions but not sure if it would be reliable.

        1 Reply Last reply Reply Quote 0
        • DDecoeneD Offline
          DDecoene
          last edited by

          Hello,

          Thank you for pointing that out.

          I changed the pins to G30 (sleep) and G13 (wakeup) and now the system works fine.

          So, the new code is:

          from machine import Pin, Timer
          from deepsleep import DeepSleep
          import deepsleep
          
          
          def handler(button):
              ds.enable_pullups('G31')  # can also do ds.enable_pullups(['P17', 'P18'])
              ds.enable_wake_on_fall('G31') # can also do ds.enable_wake_on_fall(['P17', 'P18'])
              print("Button pushed")
              ds.go_to_sleep(20)
          
          
          ds = DeepSleep()
          
          # get the wake reason and the value of the pins during wake up
          wake_s = ds.get_wake_status()
          print(wake_s)
          
          if wake_s['wake'] == deepsleep.PIN_WAKE:
              print("Pin wake up")
          elif wake_s['wake'] == deepsleep.TIMER_WAKE:
              print("Timer wake up")
          else:  # deepsleep.POWER_ON_WAKE:
              print("Power ON reset")
          
          
          button=Pin("G30",Pin.IN, pull=Pin.PULL_UP)
          irq=button.callback(trigger=button.IRQ_FALLING, handler=handler)
          
          print('booted---')
          
          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