python this gpiozero method is not working right of the bat

104 Views Asked by At
from gpiozero import MotionSensor

While true:

    MotionSensor(17).when_motion()
    print("motion detected")

returns error:

Traceback (most recent call last):
  File "/home/pi/oracle/old/cardtest.py", line 7, in <module>
    pir.when_motion()
TypeError: 'NoneType' object is not callable

considering it's the simplest context you can type it's a little weird

i need to use when_motion and not wait_for_motion because it stops my loop.

currently i'm trying to listen from 3 motion sensors and an PN5180 rfid card reader simultaneously

doing some research i stumble upon the concept of asychronous code but i'd like to verify if there simpler solution before i dive into this (it's my very first project)

EDIT

okay no error now when deleting ()

While true:

    MotionSensor(17).when_motion = print("motion detected")

but the loop is printing "motion detected" directly and constantly without any motion occuring (tested on 3 PIR)

0

There are 0 best solutions below