adafruit / Adafruit_CircuitPython_HCSR04

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

Many failed distance reedings "Retrying" before a valid distance value comes up #22

Open Kennedys1337 opened 3 years ago

Kennedys1337 commented 3 years ago

Hi, I'm using a pizero with the HC-Sr04 sensor, I hooked it up and used the follwing code:

import time import board import adafruit_hcsr04 sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.D18, echo_pin=board.D24) while True: try: print((sonar.distance,)) except RuntimeError: print("Retrying!") time.sleep(2)

The results look like this:

Retrying! Retrying! (8.568000000000001,) (8.517000000000001,) Retrying! Retrying! Retrying! Retrying! Retrying! (8.534,) Retrying! Retrying! Retrying! Retrying! (3.0940000000000003,) Retrying! Retrying! (8.5,) Retrying! (7.6160000000000005,) Retrying! Retrying! Retrying! Retrying! (8.534,) (8.925,) Retrying! Retrying! Retrying! (7.344,) (8.517000000000001,) Retrying! Retrying! Retrying!

Any suggestions? Increasing the sleep time did not solve this issue.

DanielMcGinn18 commented 3 years ago

I'm having this issue as well

jposada202020 commented 3 years ago

Hello yes RP Zero is not great at bitbanging, have you folks try this using an RP3 or RP4?. Thanks

DanielMcGinn18 commented 3 years ago

Ah Cool! I do have a RP3 so I'll give that a try instead. Thanks for your reply

rpressiani commented 3 years ago

I have the same issue with my Pi Zero. It works with this other library though (https://github.com/alaudet/hcsr04sensor). So I'm wondering what's the issue with the Adafruit library.