Due to high demand, expect some shipping delays at this time - orders may not ship for up to 2-3 business days.
0

in _dist_two-wire error
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

in _dist_two-wire error

by Quaddam on Wed Jan 12, 2022 10:48 pm

Hi trying to run an animation on a WS2812 with a HCSR04 but getting this error as soon as i put my hand infront of it, searched quite a bit but couldnt find out why:

Traceback (most recent call last):
File "main.py", line 27, in <module>
File "adafruit_hcsr04.py", line 127, in distance
File "adafruit_hcsr04.py", line 144, in _dist_two_wire
RuntimeError: Timed out

Code: Select all | TOGGLE FULL SIZE
import time
import board
import adafruit_hcsr04
from neopixel import NeoPixel
from adafruit_led_animation.animation.comet import Comet
from adafruit_led_animation.color import PURPLE, ORANGE

sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.D2, echo_pin=board.D3)
pixels = NeoPixel(board.D1, 60, brightness=1, auto_write=True)

def show_comet(val):
    if(val > -1 and val <= 6):
        comet.animate()
    if(val > 6 and val < 12):
        comet1.animate()
    if(val > 12 and val < 18):
        comet.animate()
    if(val > 24 and val < 30):
        comet1.animate()
    if(val > 24 and val < 30):
        comet.animate()

comet = Comet(pixels, speed=0.01, color=PURPLE, tail_length=10, bounce=True)
comet1 = Comet(pixels, speed=0.01, color=ORANGE, tail_length=10, bounce=True)

while True:
    show_comet(sonar.distance)
    try:
        print((sonar.distance))
    except RuntimeError:
        print("error")
    time.sleep(0.1)
   
   

Quaddam
 
Posts: 51
Joined: Fri Nov 11, 2016 1:49 pm

Re: in _dist_two-wire error

by mikeysklar on Thu Jan 13, 2022 9:41 pm

I take it you are running this on a Raspberry Pi?

Are you using a level shifter?

What model of Pi? I do see some an issue with Pi Zeros and the bitbanged driver. What happens when you run this example?

https://github.com/adafruit/Adafruit_Ci ... /issues/22

Code: Select all | TOGGLE FULL SIZE
 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)

mikeysklar
 
Posts: 7492
Joined: Mon Aug 01, 2016 8:10 pm

Re: in _dist_two-wire error

by Quaddam on Fri Jan 14, 2022 12:35 am

Thanks for the response! No i am running this with a trinket M0, I initially ran the code you linked, and it ran fine, I have built as the image below with a voltage divider and astrip of 60, W2812 RGB leds.
Attachments
sonic.jpg
sonic.jpg (117.65 KiB) Viewed 62 times

Quaddam
 
Posts: 51
Joined: Fri Nov 11, 2016 1:49 pm

Re: in _dist_two-wire error

by mikeysklar on Sat Jan 15, 2022 1:27 pm

The HC-SR04 can be powered off the 3v pin on the Trinket M0. That will allow you to ditch the resistors and keep the sensor at 3v.

A NeoPixel strip of that size (60 LEDs) should be powered from a external 5v @ 4A power supply. You can still use your Trinket M0 GPIO pin to drive the DIN line on the NeoPixel.

mikeysklar
 
Posts: 7492
Joined: Mon Aug 01, 2016 8:10 pm

Re: in _dist_two-wire error

by Quaddam on Sun Jan 16, 2022 8:57 pm

Ah ok thanks for that! Just curious, I can run other code with animations (button press, poteniometer) with the 60 LEDs with no issues, just wondering why I would need the extra 5V power for the strip? Thanks :)

Quaddam
 
Posts: 51
Joined: Fri Nov 11, 2016 1:49 pm

Re: in _dist_two-wire error

by mikeysklar on Mon Jan 17, 2022 2:40 pm

60 LEDs with a nominal 60mA draw is 3.6A which is far more than the Trinket M0 can provide directly to the NeoPixel stirp. What are you currently powering the circuit with?

mikeysklar
 
Posts: 7492
Joined: Mon Aug 01, 2016 8:10 pm

Re: in _dist_two-wire error

by Quaddam on Tue Jan 18, 2022 12:25 pm

3.7 V 2500 mAh battery and it works great, should i be changing that setup?

Quaddam
 
Posts: 51
Joined: Fri Nov 11, 2016 1:49 pm

Re: in _dist_two-wire error

by mikeysklar on Tue Jan 18, 2022 7:15 pm

Actually that setup might be reasonable for most usage cases.

Have you been able to get the sensor and NeoPixel working individually, but while both are connected?

mikeysklar
 
Posts: 7492
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.