Problem with Ultrasonic ranger

i’m trying to use the ultrasonic ranger SEN10737P on my Raspberry. It’s connected to a GrovePi. I’m using the following code :

GrovePi + Grove Ultrasonic Ranger

import time
from grovepi import *

Connect the Grove Ultrasonic Ranger to digital port D4


ultrasonic_ranger = 4

while True:
# Read distance value from Ultrasonic
print ultrasonicRead(ultrasonic_ranger)
except TypeError:
print "Error"
except IOError:
print “Error”

But, instead of giving me the distance, i’ve got something like 1, 2, 5 , 0 , 1054, 784.
In short, it sometimes gives me the right distance, but every 2 or 3 distances, he sends me a random number.

Can you try reading the values in a while loop and see if the values become consistent after a second or two. There is a possibility that the GrovePi might be reading an old value from the buffer and that might be a reson for the inconsistency.

Do let us know if this helps.