Simple test

Ensure your device works with this simple test.

examples/hcsr04_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import time
import board
import adafruit_hcsr04

sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.D5, echo_pin=board.D6)

while True:
    try:
        print((sonar.distance,))
    except RuntimeError:
        print("Retrying!")
    time.sleep(0.1)