Home
Home copied to clipboard
HC-SR04 for ESP32 crash after 45minutes of running
Library/API/IoT binding
nanoFramework.Iot.Device.Hcsr04.Esp32
Visual Studio version
v2022 17.2.3
.NET nanoFramework extension version
2022.2.023
Target name(s)
ESP32_REV0
Firmware version
1.8.0.431
Device capabilities
No response
Description
I have a loop to get distance measurement from HC-SR04 ultrasonic sensor on ESP32 and after a running for 45minutes to 1 hour, I get this error.
Distance: 24.27969149 cm memory: 99504 Cnt: 13858
Distance: 24.27969149 cm memory: 99504 Cnt: 13859
Distance: 24.27969149 cm memory: 99504 Cnt: 13860
Distance: 24.27969149 cm memory: 99504 Cnt: 13861
++++ Exception System.ArgumentOutOfRangeException - 0x00000000 (1) ++++
++++ Message:
++++ System.Threading.Thread::Sleep [IP: 001e] ++++
++++ Iot.Device.Hcsr04.Esp32.Hcsr04::TryGetDistance [IP: 0018] ++++
++++ nanoFramework_HR_SC04.Program::Main [IP: 001d] ++++
nF Error: Exception was thrown: System.ArgumentOutOfRangeException
How to reproduce
Run the code here
Expected behaviour
Not crash.
Screenshots
No response
Sample project or code
No response
Aditional information
The code crash here. The value of DateTime.UtcNow.Ticks is less then _lastMeasurment.
@alberk8 from your report on Discord I believe you've tested a fix for this. Can you please submit a PR with the proposed fix? 😉