in _dist_two-wire error

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Quaddam
 
Posts: 52
Joined: Fri Nov 11, 2016 1:49 pm

in _dist_two-wire error

Post by Quaddam »

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

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)
    
    

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: in _dist_two-wire error

Post by mikeysklar »

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

 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)

User avatar
Quaddam
 
Posts: 52
Joined: Fri Nov 11, 2016 1:49 pm

Re: in _dist_two-wire error

Post by Quaddam »

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 109 times

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: in _dist_two-wire error

Post by mikeysklar »

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.

User avatar
Quaddam
 
Posts: 52
Joined: Fri Nov 11, 2016 1:49 pm

Re: in _dist_two-wire error

Post by Quaddam »

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 :)

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: in _dist_two-wire error

Post by mikeysklar »

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?

User avatar
Quaddam
 
Posts: 52
Joined: Fri Nov 11, 2016 1:49 pm

Re: in _dist_two-wire error

Post by Quaddam »

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

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: in _dist_two-wire error

Post by mikeysklar »

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?

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”