adafruit / Adafruit_CircuitPython_HCSR04

CircuitPython library for controlling HC-SR04 ultrasonic range sensors
MIT License
9 stars 22 forks source link

RCML-1601 using hcsr04_simpletest breaks after a few seconds on Pi Pico #26

Closed MegaMattMiller closed 3 years ago

MegaMattMiller commented 3 years ago

After running hcsr04_simpletest.py on a raspberry pi pico for a few seconds, the script seems to forget about it's own values. See below output:

code.py output:
(11.237,)
(11.237,)
(11.237,)
(11.237,)
(11.237,)
(11.237,)
(11.237,)
(11.237,)
(11.237,)
(11.237,)
(11.237,)
(11.237,)
Traceback (most recent call last):
  File "code.py", line 14, in <module>
  File "code.py", line 12, in <module>
  File "adafruit_hcsr04.py", line 127, in distance
  File "adafruit_hcsr04.py", line 142, in _dist_two_wire
AttributeError: 'HCSR04' object has no attribute '_timeout'

The distance value also never changes during the run, even when the Pi Pico is moved around. sonar.distance only returns a different value on the first sample of each run.

When forcing _USE_PULSEIO to False, the values returned are more accurate, but only in ~15 cm steps. With that value forced to False it does not crash after a few samples.

tannewt commented 3 years ago

What version of CircuitPython are you using? Please try the latest pre-release if you haven't yet.

MegaMattMiller commented 3 years ago

I'm using 6.3.0, I'll try 7.0.0-alpha.5 and report back

MegaMattMiller commented 3 years ago

I think that did the trick! Distance readings are correct and it seems to be much more stable.