0
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)

Dornito
  • 31
  • 3
  • I don't think this should be in a loop - it just sets up an event handler. In the example on the gpiozero docs [here](https://gpiozero.readthedocs.io/en/stable/recipes.html#motion-sensor), it adds event handlers for motion detected and motion not detected and then uses `pause()` at the end to pause the program but still let the event handlers run. – cguk70 May 13 '22 at 16:07
  • oh i see! it makes more sens but i need a loop to use my rfid reader and i'd like my sensor to detect motions only at a certain state of my program maybe i should do something like when_motion = afonction def afonction(): if states ==1 do something – Dornito May 13 '22 at 16:27

0 Answers0