I'm trying to get a basic HCSR04 distance sensor working with CircuitPython and a CircuitPlayground Bluefruit. My code runs, but keeps printing out Retrying! so I don't think I'm getting a proper reading from the HCSR04. I've adapted code and (hopefully correctly) the wiring without the theremin-part from Sophie Wong's Pumpkin Theramin learn guide (https://learn.adafruit.com/jack-o-there ... he-circuit), so my code is simple read & print (shown below).
Following this is a schematic then photos of my wiring - which I'm guessing is the problem since the code runs. I did try this sensor using an Arduino sketch and different wiring (wired into 5v power so didn't need the double resistors), and the sensor worked. I've checked the alignment & pushed the pins in holes so I think that's OK.
Any ideas what I might be doing wrong? Thanks!
John
Code: Select all
import board
import time
from adafruit_circuitplayground import cp
import adafruit_hcsr04
sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.A2, echo_pin=board.A1)
while True:
try:
handDistance = int(sonar.distance)
print("Distance:", handDistance)
except RuntimeError:
print("Retrying!")
time.sleep(0.1)