I am trying to connect the Ranger Ultrasonic sensor directly to a Raspberry Pi4. My hardware connections are; 3.3v pin, gnd pin and gpio pin 5. I have checked the voltage and pin status, and all are good. I ran the following code;
#!/usr/bin/env python
import sys
sys.path.append('/home/hank/grove.py')
import time
from grove.grove_ultrasonic_ranger import GroveUltrasonicRanger
sensor = GroveUltrasonicRanger(5)
while True:
distance = sensor.get_distance()
print('{} cm'.format(distance))
time.sleep(1)
Nothing happens, except 1 time I did get readings when nothing was in front of the sensor. All other times no results or errors.
I insured that GPIO 5 is input.
I did get some strange results(which I think you will find hard to believe).
If I execute the script nothing happens but if I disconnect the 3.3v supply while it is running I get some output (nothing in front of sensor).
150.35991010994746 cm
71.36525778934873 cm
178.98658226276265 cm
76.42137593236463 cm
103.82306986841662 cm
1.3195235153724407 cm
1.3236341805293643 cm
1.3359661760001347 cm
1.3236341805293643 cm