A MicroPython driver for the HC-SR04 ultrasonic sensor with accurate timing and integer-only distance calculation.
micropython-hcsr04 is a MicroPython driver for the HC-SR04 ultrasonic distance sensor. It provides accurate distance measurements using MicroPython's built-in timing functions and offers both floating-point and integer-only distance calculation methods. The driver solves the problem of inaccurate or hardware-specific implementations in existing MicroPython sensor drivers.
MicroPython developers working on embedded systems or IoT projects that require distance sensing with HC-SR04 sensors, particularly those needing accurate measurements or working without floating-point support.
Developers choose this driver for its improved accuracy through native timing functions, cross-board compatibility without hardware-specific code, and the unique integer-only distance calculation for resource-constrained environments.
Micropython driver for ultrasonic sensor HC-SR04
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Leverages MicroPython's `machine.time_pulse_us()` for precise measurements, improving over pure Python methods as highlighted in the motivation.
Includes `distance_mm()` method that avoids floating-point operations, essential for resource-constrained environments without FPU support.
Designed to work with standard MicroPython across various boards, avoiding hardware-specific code for portability.
Allows custom timeout settings in microseconds via the constructor, enabling adaptation to different measurement ranges.
Converts timeout errors to `OSError('Out of range')` for consistent exception management, as demonstrated in the examples.
Only compatible with the HC-SR04 ultrasonic sensor, making it unsuitable for projects requiring other distance sensing technologies.
Requires users to specify trigger and echo pins in the constructor, which can be error-prone and adds setup complexity.
Lacks built-in filtering, calibration, or environmental compensation, which are often needed for industrial or high-accuracy applications.
README provides basic examples but lacks comprehensive API docs, troubleshooting guides, or performance benchmarks.