GrovePi + Ultrasonic sensor

I have the GrovePi board on a Raspberry pi 3B using the OS:

Then I type sudo i2cdetect -y 1, I get the expected 04 being shown.

With the US Sensor on Port 4 (with power off) and running your python programme I get:
a Error message saying “Type Error” ( I modified the to show which error was taking place.
The original just typed error.)

After the when I retry the I2cdetect -y 1 the 04 has disappeared.

I thought that grove would be simple to work with, so I am a bit disappointed.

I have other sensors I need to try out and need to buy more.

Please assist!!

Your Python programme:

import grovepi

Connect the Grove Ultrasonic Ranger to digital port D4

SIG,NC,VCC,GND

ultrasonic_ranger = 4

while True:
try:
# Read distance value from Ultrasonic
print(grovepi.ultrasonicRead(ultrasonic_ranger))

except TypeError:
    print ("Type-Error")
except IOError:
 print ("IOError-Error")

There is an update to the ultrasonic_sensor example here:
https://github.com/DexterInd/GrovePi/blob/master/Software/Python/grove_ultrasonic.py

specifically these lines have been added:


# set I2C to use the hardware bus
grovepi.set_bus("RPI_1")
2 Likes