PyPortal HCSR04 3 Wires

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
kwalkerk
 
Posts: 94
Joined: Wed Jan 11, 2017 11:54 am

PyPortal HCSR04 3 Wires

Post by kwalkerk »

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

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.

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: PyPortal HCSR04 3 Wires

Post by tannewt »

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.

User avatar
kwalkerk
 
Posts: 94
Joined: Wed Jan 11, 2017 11:54 am

Re: PyPortal HCSR04 3 Wires

Post by kwalkerk »

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.

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

Return to “Adafruit CircuitPython”