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

    Using Adafruit's PIR Sensor

    Scheduled Pinned Locked Moved WiPy 2&3
    1 Posts 1 Posters 94 Views 1 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.
    • techykermitT Offline
      techykermit
      last edited by techykermit

      I just wrote this in another topic:
      "I have a bunch of PyComs lying around and I tested this with one of my devices and Adafruit's PIR sensor. Worked fantastically"

      Sadly, it turns out that this is not the case.
      Here is what I have:
      I have a PIR sensor from Adafruit that I can read from with this code:

      def read_pir(): #Function for reading status from the PIR device
          pir = Pin("P2", mode=Pin.IN, pull=Pin.PULL_UP)
          if pir() == 1: #If the PIR sensor is detecting any motion
              motion = True
          else: #If the PIR sensor is not detecting any motion
              motion = False
          return motion #Return the read values
      

      However, what I need to do next is to make my PyCom wake up from deepsleep every time the sensor detects motion. I have tried this code:

      import machine
      pir = machine.Pin("P2", mode=Pin.IN, pull=Pin.PULL_UP)
      machine.pin_sleep_wakeup((pir,), mode=machine.WAKEUP_ANY_HIGH, enable_pull=True)  
      

      I have also tried:

      import machine
      pir = machine.Pin("P2", mode=Pin.IN, pull=Pin.PULL_UP)
      machine.pin_sleep_wakeup(["P2"], mode=machine.WAKEUP_ANY_HIGH, enable_pull=True)  
      

      But what I find strange is that (even if nothing is connected to P2), it wakes up from deepsleep immediately after I put it in deepsleep. That is obviously not the expected behaviour, I want the device to sleep until the sensor detects any motion.

      What happens is that when I run this code:

      import machine
      from machine import Pin
      pir = Pin("P2", mode=Pin.IN, pull=Pin.PULL_UP)
      machine.pin_sleep_wakeup((pir,), mode=machine.WAKEUP_ANY_HIGH, enable_pull=True)
      machine.deepsleep(10000000)
      

      The device restarts with a DEEPSLEEP_RESET immediately after I run the file, and like I said, this happens even when nothing isn't connected to the pin.

      Is there any way I can solve this?

      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