gpio.sensor.distance

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)[source]

Bases: GpioPlugin, GpioSensorPlugin

You can use this plugin to interact with a distance sensor on your Raspberry Pi (tested with a HC-SR04 ultrasound sensor).

Requires:

  • RPi.GPIO (pip install RPi.GPIO)

Triggers:

__init__(trigger_pin: int, echo_pin: int, measurement_interval: float = 0.15, timeout: float = 2.0, warmup_time: float = 2.0, *args, **kwargs)[source]
Parameters:
  • 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).

get_measurement()[source]

Extends GpioSensorPlugin.get_measurement()

Returns:

Distance measurement as a scalar (in mm):

start_measurement(duration: Optional[float] = None)[source]

Start the measurement thread. It will trigger platypush.message.event.distance.DistanceSensorEvent events when new measurements are available.

Parameters:

duration – If set, then the thread will run for the specified amount of seconds (default: None)

stop_measurement()[source]

Stop the running measurement thread.