ADC Meter icon ADC Meter — ADC VU meter displaying 0-3.3/5V as a 0-255 linear meter; configurable board/port, sampling interval and color; pausable real-time readings. Try it →
 

Ping

Read HC-SR04 style ultrasonic distance sensors connected to an EZB. Each sensor uses two ports, trigger and echo. Distances are a number from 0 to 255, larger meaning farther. The wait commands pause the script until something comes closer or moves away.

Where to find it: type Ping. in a Python script, or open the ARCx API view of the script editor and expand Ping


Commands

Command What it does
Ping.Get Reads the distance from an HC-SR04 ultrasonic ping sensor on the first EZB, as a value from 0 to 255 (larger is farther).
Ping.WaitForBetween Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads a distance from low to high, inclusive, checking about every 100 ms.
Ping.WaitForEquals Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads exactly the given distance, checking about every 100 ms.
Ping.WaitForHigher Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads a distance above the given one, checking about every 100 ms.
Ping.WaitForLower Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads a distance below the given one, checking about every 100 ms.

Details

Ping.Get

Reads the distance from an HC-SR04 ultrasonic ping sensor on the first EZB, as a value from 0 to 255 (larger is farther). Readings are cached for 200 ms. Raises an error if the EZB is not connected or its firmware does not support ping sensors.

Ping.Get(triggerPort, echoPort)
Ping.Get(triggerPort, echoPort, ezbIndex)
Value Type What it is
triggerPort int The digital port the sensor's trigger pin is wired to, such as d0.
echoPort int The digital port the sensor's echo pin is wired to, such as d1.
ezbIndex int Optional. Which EZB to use, 0 being the first one.

Gives back: int. The distance value, 0 to 255.

Ping.WaitForBetween

Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads a distance from low to high, inclusive, checking about every 100 ms. Raises an error if the EZB is not connected or its firmware does not support ping sensors.

Ping.WaitForBetween(triggerPort, echoPort, low, high)
Ping.WaitForBetween(triggerPort, echoPort, low, high, ezbIndex)
Value Type What it is
triggerPort int The digital port the sensor's trigger pin is wired to, such as d0.
echoPort int The digital port the sensor's echo pin is wired to, such as d1.
low int The smallest distance to accept, 0 to 255.
high int The largest distance to accept, 0 to 255.
ezbIndex int Optional. Which EZB to use, 0 being the first one.

Gives back: int. The distance that was read, 0 to 255, or -1 if the script was stopped first.

Ping.WaitForEquals

Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads exactly the given distance, checking about every 100 ms. Raises an error if the EZB is not connected or its firmware does not support ping sensors.

Ping.WaitForEquals(triggerPort, echoPort, distance)
Ping.WaitForEquals(triggerPort, echoPort, distance, ezbIndex)
Value Type What it is
triggerPort int The digital port the sensor's trigger pin is wired to, such as d0.
echoPort int The digital port the sensor's echo pin is wired to, such as d1.
distance int The distance to wait for, 0 to 255.
ezbIndex int Optional. Which EZB to use, 0 being the first one.

Gives back: int. The distance that was read, 0 to 255, or -1 if the script was stopped first.

Ping.WaitForHigher

Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads a distance above the given one, checking about every 100 ms. Raises an error if the EZB is not connected or its firmware does not support ping sensors.

Ping.WaitForHigher(triggerPort, echoPort, distance)
Ping.WaitForHigher(triggerPort, echoPort, distance, ezbIndex)
Value Type What it is
triggerPort int The digital port the sensor's trigger pin is wired to, such as d0.
echoPort int The digital port the sensor's echo pin is wired to, such as d1.
distance int Wait for a reading above this distance, 0 to 255.
ezbIndex int Optional. Which EZB to use, 0 being the first one.

Gives back: int. The distance that was read, 0 to 255, or -1 if the script was stopped first.

Ping.WaitForLower

Pauses the script until the HC-SR04 ultrasonic ping sensor on the first EZB reads a distance below the given one, checking about every 100 ms. Raises an error if the EZB is not connected or its firmware does not support ping sensors.

Ping.WaitForLower(triggerPort, echoPort, distance)
Ping.WaitForLower(triggerPort, echoPort, distance, ezbIndex)
Value Type What it is
triggerPort int The digital port the sensor's trigger pin is wired to, such as d0.
echoPort int The digital port the sensor's echo pin is wired to, such as d1.
distance int Wait for a reading below this distance, 0 to 255.
ezbIndex int Optional. Which EZB to use, 0 being the first one.

Gives back: int. The distance that was read, 0 to 255, or -1 if the script was stopped first.