Ultrasonic Ranger 1.0 Broken?

Hello,
I have my new GrovePi attached to my RPi Rev 2 and it appears to be functioning correctly:

sudo i2cdetect -y 1
Sees the GrovePi

sudo python grovepi_blink.py
Flashes the LED

I attached the ultrasonic ranger rev 1.0 to port D4
This is what I get:
pi@PlanetPluto ~/tools/GrovePi/Software/Python $ sudo python grovepi_ultrasonic.py
65535
65535
65535
…(Repeats)

Sometimes there the following is error is received:

IOError
Traceback (most recent call last):
File “grovepi_ultrasonic.py”, line 5, in <module>
print ultrasonicRead(pin)
File “/home/pi/tools/GrovePi/Software/Python/grovepi.py”, line 111, in ultrasonicRead
return (number[1]*256+number[2])
TypeError: ‘int’ object has no attribute ‘getitem

Any help you can provide would be appreciated.
Thanks,
Paul

Hi All,
So it turns out that the firmware on my GrovePi was out of date.
The GrovePi/Firmware/version.txt contained 1.1
So I soldered on some pins to the ISP and D1 pads on the GrovePi

(The parts for this should have been included in the GrovePi package ??)

I updated the firmware to 1.1 by following these instructions

So now I get somewhat expected output.
Except for the exception.

The distance is: 724 cm, 285.039370079 In.
The distance is: 451 cm, 177.559055118 In.
The distance is: 454 cm, 178.74015748 In.
The distance is: 155 cm, 61.0236220472 In.
The distance is: 153 cm, 60.2362204724 In.
The distance is: 152 cm, 59.842519685 In.
IOError
Traceback (most recent call last):
File “plf_ultrasonic.py”, line 5, in <module>
distance_cm = ultrasonicRead(pin)
File “/home/pi/tools/GrovePi/Software/Python/grovepi.py”, line 112, in ultrasonicRead
return (number[1]*256+number[2])
TypeError: ‘int’ object has no attribute ‘getitem

Am I doing something wrong ?
Thanks,
Paul

Oh crap I’m talking to myself again :slight_smile:

I have a fix for the grovepi.py ultrasonicRead function:
Checking the type of number prevents the need to trap exceptions on this call.

#Read value from Grove Ultrasonic
def ultrasonicRead(pin):
write_i2c_block(address,uRead_cmd+[pin,0,0])
time.sleep(.2)
read_i2c_byte(address)
number = read_i2c_block(address)
if type(number) is list:
return (number[1]*256+number[2])
return -1

-Paul

Hi Paul,
This looks like a pretty good solution. Thanks for the heads up. We’ll integrate this into the next software update.

-Karan