Simple test

Ensure your device works with this simple test.

examples/hcsr04_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import time
 5import board
 6import adafruit_hcsr04
 7
 8sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.D5, echo_pin=board.D6)
 9
10while True:
11    try:
12        print((sonar.distance,))
13    except RuntimeError:
14        print("Retrying!")
15    time.sleep(0.1)