Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Sensor

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
imhavoc
 
Posts: 42
Joined: Thu Oct 05, 2017 10:32 pm

Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Sensor

Post by imhavoc »

using the sample code from https://learn.adafruit.com/ultrasonic-s ... ce-sensors, I get the following results:

Code: Select all

code.py output:
0.272
0.272
0.272
0.272
0.272
0.272
0.272
0.272
0.272
0.272
0.272
0.272
Traceback (most recent call last):
  File "code.py", line 11, in <module>
  File "code.py", line 9, in <module>
  File "adafruit_hcsr04.py", line 144, in distance
  File "adafruit_hcsr04.py", line 159, in _dist_two_wire
AttributeError: 'HCSR04' object has no attribute '_timeout'
I loaded the code on a Isty Bitsy M0, and it works great.

I moved back to the Feather, and moved the echo pin, and got the exact same result.

User avatar
imhavoc
 
Posts: 42
Joined: Thu Oct 05, 2017 10:32 pm

Re: Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Senso

Post by imhavoc »

Hooked up a neopixel ring, no problems. Looks like something in the HCSR04 library is not playing nice with the RP2040.

User avatar
imhavoc
 
Posts: 42
Joined: Thu Oct 05, 2017 10:32 pm

Re: Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Senso

Post by imhavoc »

Downloaded the latest libraries: adafruit-circuitpython-bundle-6.x-mpy-20210329

Still failing. It takes longer to fail, but it still fails.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Senso

Post by adafruit_support_carter »

Which Feather RP2040 pins are you using for trigger and echo?

User avatar
imhavoc
 
Posts: 42
Joined: Thu Oct 05, 2017 10:32 pm

Re: Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Senso

Post by imhavoc »

adafruit_support_carter wrote:Which Feather RP2040 pins are you using for trigger and echo?
Pin D5 for trigger,
Pin D6 for echo.

(It occurred to me last night that the Pin 5 on the Itsy Bisy is 5V, which may explain why it's working and the Feather is not. (?))

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Senso

Post by adafruit_support_carter »

While the Trig signal can be 3V or 5V, the 'return' Echo signal is 5V logic. For that reason, we include two 10K resistors, use these as a divider to convert the 5V logic level to a safe 2.5V that you can ready with your 3V device.
Are you setting up the voltage divider?

User avatar
imhavoc
 
Posts: 42
Joined: Thu Oct 05, 2017 10:32 pm

Re: Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Senso

Post by imhavoc »

adafruit_support_carter wrote:Are you setting up the voltage divider?
Yes.

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Senso

Post by adafruit_support_carter »

Hmm. I think I'm seeing the same thing. It might be RP2040 related. There' still some issues being worked out for it. Want to open a new issue here?
https://github.com/adafruit/Adafruit_Ci ... R04/issues

User avatar
imhavoc
 
Posts: 42
Joined: Thu Oct 05, 2017 10:32 pm

Re: Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Senso

Post by imhavoc »

here is a diagram:
Screenshot 2021-03-30 125412.png
Screenshot 2021-03-30 125412.png (155.51 KiB) Viewed 135 times

User avatar
stocksp
 
Posts: 2
Joined: Fri Aug 20, 2021 3:14 pm

Re: Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Senso

Post by stocksp »

I'm have exactly the same results.

New Feather hardware (running the sample app with a voltage divider on the Echo) ... I get a dozen good reads and then the crash.

"AttributeError: 'HCSR04' object has no attribute '_timeout'"

Which doesn't make any sense (to me!) as the _timeout attribute does exist.
I moved the library source into my code and printed out the value on each loop (0.1)

Reading the discussion above I'm hearing this is a problem with the Feather and NOT the RP2040?

Did I understand correctly? as I see so many examples of the HCSR04 running on the 'naked' Pico.

Don't mind moving off the Feather till this is resolved ... IF this is a Feather problem and not also a RP2040 or CircuitPython issue...

thanks for any guidance!

P:)

User avatar
stocksp
 
Posts: 2
Joined: Fri Aug 20, 2021 3:14 pm

Re: Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Senso

Post by stocksp »

I updated my CircuitPython from 6 to 7.0 alpha 6 and the Ultrasonic sensor works perfectly!!

oh happy days!

P:)

User avatar
imhavoc
 
Posts: 42
Joined: Thu Oct 05, 2017 10:32 pm

Re: Feather RP2040 + HC-SR04 Ultrasonic Sonar Distance Senso

Post by imhavoc »

stocksp wrote:I updated my CircuitPython from 6 to 7.0 alpha 6 and the Ultrasonic sensor works perfectly!!

oh happy days!

P:)
stocksp, good to know! Thanks for the info.

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

Return to “Feather - Adafruit's lightweight platform”