sensor-hcsr04

CLI reference

glasgow run sensor-hcsr04

Measure distance using HC-SR04 compatible ultrasound sensors.

usage: glasgow run sensor-hcsr04 [-h] [-V SPEC] [--trig PIN] [--echo PIN]
                                 [-S SUPERSAMPLE] [-t TIMEOUT]
                                 [--speed-of-sound SPEED_OF_SOUND]
                                 OPERATION ...
-h, --help

show this help message and exit

-V <spec>, --voltage <spec>

configure I/O port voltage to SPEC (e.g.: ‘3.3’, ‘A=5.0,B=3.3’, ‘A=SA’)

--trig <pin>

bind the applet I/O line ‘trig’ to PIN (default: ‘A0’, required)

--echo <pin>

bind the applet I/O line ‘echo’ to PIN (default: ‘A1’, required)

-S <supersample>, --supersample <supersample>

number of samples to take for supersampling, as a power of two; use 0 to disable, 4 to average 16 samples (default: 2)

-t <timeout>, --timeout <timeout>

timeout for each measurement, in seconds (default: 1.040)

--speed-of-sound <speed_of_sound>

speed of sound for conversion to distance (default: 343.2)

glasgow run sensor-hcsr04 log

usage: glasgow run sensor-hcsr04 log [-h] [-i INTERVAL] DATA-LOGGER ...
-h, --help

show this help message and exit

-i <interval>, --interval <interval>

interval between measurements, in seconds

glasgow run sensor-hcsr04 log csv

Log data to a comma-separated value (CSV) file.

usage: glasgow run sensor-hcsr04 log csv [-h] [--dialect DIALECT] CSV-FILE
csv-file

write data to CSV-FILE

-h, --help

show this help message and exit

--dialect {excel,excel-tab,unix}

format CSV file according to DIALECT

glasgow run sensor-hcsr04 log influxdb

Log data to an InfluxDB 1.x endpoint over HTTP(S).

usage: glasgow run sensor-hcsr04 log influxdb [-h] [-r POLICY] [-t TAG=VALUE]
                                              -p PRECISION
                                              [--batch-size BATCH-SIZE]
                                              ENDPOINT DATABASE SERIES
endpoint

write to endpoint URL //ENDPOINT/write

database

write to database DATABASE

series

write to measurement SERIES

-h, --help

show this help message and exit

-r <policy>, --retention-policy <policy>

write to retention policy POLICY

-t <tag=value>, --tag <tag=value>

attach TAG=VALUE to all data points

-p {ns,us,ms,s,m,h}, --precision {ns,us,ms,s,m,h}

set timestamp precision to PRECISION

--batch-size <batch-size>

submit data in groups of BATCH-SIZE points

glasgow run sensor-hcsr04 log influxdb2

Log data to an InfluxDB 2.x endpoint over HTTP(S).

usage: glasgow run sensor-hcsr04 log influxdb2 [-h] [-t TAG=VALUE]
                                               -p PRECISION
                                               [--batch-size BATCH-SIZE]
                                               --token TOKEN
                                               ENDPOINT ORGANIZATION BUCKET
                                               SERIES
endpoint

write to endpoint URL //ENDPOINT/api/v2/write

organization

write to Organization ORGANIZATION (can be either the name or the id)

bucket

write to bucket BUCKET

series

write to measurement SERIES

-h, --help

show this help message and exit

-t <tag=value>, --tag <tag=value>

attach TAG=VALUE to all data points

-p {ns,us,ms,s,m,h}, --precision {ns,us,ms,s,m,h}

set timestamp precision to PRECISION

--batch-size <batch-size>

submit data in groups of BATCH-SIZE points

--token <token>

set the Token to use for Authentication

glasgow run sensor-hcsr04 log stdout

Log data to standard output in a human-readable format.

usage: glasgow run sensor-hcsr04 log stdout [-h]
-h, --help

show this help message and exit

glasgow run sensor-hcsr04 measure

usage: glasgow run sensor-hcsr04 measure [-h]
-h, --help

show this help message and exit

API reference

class glasgow.applet.sensor.hcsr04.SensorHCSR04Interface(logger: Logger, assembly: AbstractAssembly, *, trig: GlasgowPin, echo: GlasgowPin)
async measure_time(supersample: int) float

Measures the time it takes for sound to travel to the object, in seconds.

supersample represents the number of samples to take for supersampling, as 2^samples. For example, if you want to take 8 samples, set this parameter to 3. A value of 0 means no supersampling. Maximum value is 7.

async measure_distance(supersample: int, speed_of_sound: float) float

Measures the distance to the object by using the speed of sound.

supersample represents the number of samples to take for supersampling, as 2^samples. For example, if you want to take 8 samples, set this parameter to 3. A value of 0 means no supersampling. Maximum value is 7.

speed_of_sound is the speed of sound in the current environment.