Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

PyPortal HCSR04 3 Wires
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PyPortal HCSR04 3 Wires

by kwalkerk on Sat Apr 18, 2020 2:14 pm

I'm trying to connect an HCSR04 distance sensor to my PyPortal.

I would like to use the 3 wire approach where the trigger and echo pins are tied together. This works fine on Arduino's

Here is the relevant code:

Code: Select all | TOGGLE FULL SIZE
import adafruit_hcsr04

sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.D3, echo_pin=board.D3)



But I get the following error: ValueError: D3 in use

Is this not possible on the PyPortal or am I missing something?

Thanks.

kwalkerk
 
Posts: 61
Joined: Wed Jan 11, 2017 11:54 am

Re: PyPortal HCSR04 3 Wires

by tannewt on Mon Apr 20, 2020 12:52 pm

I don't think it's possible because we don't want to assume the pin can be changed to an input fast enough after the trigger.

tannewt
 
Posts: 1685
Joined: Thu Oct 06, 2016 8:48 pm

Re: PyPortal HCSR04 3 Wires

by kwalkerk on Mon Apr 20, 2020 12:56 pm

Thanks. That's what I thought. I'm getting it to work by using 4 wires and all three pins on D3 and just the data pin on D4. Since I'm not connecting anything else to D4 this works fine.

kwalkerk
 
Posts: 61
Joined: Wed Jan 11, 2017 11:54 am

Please be positive and constructive with your questions and comments.