Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MotionSensor #99

Open
sentairanger opened this issue Feb 17, 2023 · 3 comments
Open

Add MotionSensor #99

sentairanger opened this issue Feb 17, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@sentairanger
Copy link

I would like to see MotionSensor (PIR sensor) added to picozero similar to MotionSensor on gpiozero.

@martinohanlon
Copy link
Collaborator

Based on picozero.DigitalInputDevice I think the implementation would look like this.

class MotionSensor(DigitalInputDevice):
    def __init__(self, pin, pull_up=False, bounce_time=0.02): 
        super().__init__(pin=pin, pull_up=pull_up, bounce_time=bounce_time)

MotionSensor.motion_detected  = MotionSensor.is_active
MotionSensor.when_motion = MotionSensor.when_activated
MotionSensor.when_no_motion = MotionSensor.when_deactivated

This implementation would be different to gpiozero. gpiozero uses the concept of a SmoothedInputDevice which takes the average of continuous readings to smooth the input, presumably to stop false triggers (although in practice I dont think this really helps, PIRs always being a bit "jittery").

@sentairanger
Copy link
Author

Would it help to add an interrupt request to reduce jitter? I will try this code out and make changes if needed. I'll report back if I can reduce jitter.

@martinohanlon
Copy link
Collaborator

Not sure what you mean by interupt request. DigitalInputDevice already used interupts and implements debouncing -https://github.com/RaspberryPiFoundation/picozero/blob/master/picozero/picozero.py#L1589

@martinohanlon martinohanlon added the enhancement New feature or request label Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants