A MicroPython library/port based on Adafruit's CircuitPython HC-SR04 library.
Additionally, this MicroPython port does not contain third-party dependencies.
The HC-SR04 is a module for measuring distances via ultrasonic waves. The device in itself is inexpensive and designed to be used with microcontrollers.
This library provides a driver for the module. The key difference is that this library is intended for MicroPython devices.
Import the driver file hcsr04.py in one's main script and ensure that hcsr04.py is in the MicroPython device's file system for import.
This library also contains a short example:
from hcsr04 import HCSR04
import time
sonar = HCSR04(trigger_pin=2, echo_pin=3)
while True:
try:
print((sonar.distance,))
except RuntimeError:
print("Retrying!")
pass
time.sleep(0.1)The example snippet is also included in examples/main.py