- class platypush.plugins.gpio.sensor.distance.GpioSensorDistancePlugin(trigger_pin: int, echo_pin: int, measurement_interval: float = 0.15, timeout: float = 2.0, warmup_time: float = 2.0, *args, **kwargs)¶
You can use this plugin to interact with a distance sensor on your Raspberry Pi (tested with a HC-SR04 ultrasound sensor).
pip install RPi.GPIO)
platypush.message.event.distance.DistanceSensorEventwhen a new distance measurement is available
- __init__(trigger_pin: int, echo_pin: int, measurement_interval: float = 0.15, timeout: float = 2.0, warmup_time: float = 2.0, *args, **kwargs)¶
trigger_pin – GPIO PIN where you connected your sensor trigger PIN (the one that triggers the sensor to perform a measurement).
echo_pin – GPIO PIN where you connected your sensor echo PIN (the one that will listen for the signal to bounce back and therefore trigger the distance calculation).
measurement_interval – When running in continuous mode (see
platypush.plugins.gpio.sensor.distance.GpioSensorDistancePlugin.start_measurement()) this parameter indicates how long should be waited between two measurements (default: 0.15 seconds)
timeout – The echo-wait will terminate and the plugin will return null if no echo has been received after this time (default: 1 second).
warmup_time – Number of seconds that should be waited on plugin instantiation for the sensor to be ready (default: 2 seconds).
Distance measurement as a scalar (in mm):
- start_measurement(duration: Optional[float] = None)¶
Start the measurement thread. It will trigger
platypush.message.event.distance.DistanceSensorEventevents when new measurements are available.
duration – If set, then the thread will run for the specified amount of seconds (default: None)
Stop the running measurement thread.