GrovePi+ Ultrasonic, precision of milimeter on raspi

Hi, I am using the example code from github to read Ultrasonic ranger and it worked well. It give value in centimeter.
This is the code that I use grovepi.ultrasonicRead(4).

But its not precise. I need a reading accurate to 1mm, and I dont know how to modify it. can somebody help me?

I am using raspi, and Ultrasonic sensor on GrovePi+

1 Like

I am not sure what you are trying to ask.

Let’s do this a different way:

Do you want:

  1. Repeatable accuracy to ±0.001 meter? (i.e. ±1mm)
    – or –
  2. Readings that have more digits of precision ? (i.e. instead of 0.01 meter, readings of 0.001 meter?)

For number 1, that entirely depends on the specifications of the sensor itself, ambient noise, temperature, humidity, what is in the room with it such as furniture, carpet, or curtains, and maybe even other things. You will need to find the technical data sheet for the actual sensor itself to find out if it is possible to get the accuracy you need. Maybe? Maybe not?

For number 2, I would suggest that you look at the grovepi sensor libraries themselves. Maybe the library reads more digits of precision from the sensor, but rounds to the centimeter?

I am not an expert on the Grove Pi system and I do not have that particular sensor. However, if I had one, and had these kinds of questions, this is what I would look at first.

I DO have a GoPiGo, and I have had similar questions in the past. The way I solved these problems was both to ask here, (a good idea!), and to look at the device and its programming libraries.

Perhaps someone who knows more about the Grove Pi system can help?

Please reply and let us know what you discover!

If I have not understood your question correctly, please reply and let me know.


First, welcome to the forum @kishiro80.

Second, what @jimrh said is correct. Regarding point #1, from the datasheet I found here:
it seems that the resolution of the sensor is only 9mm. So you really wouldn’t be able to reliably get 1mm accuracy - it’s beyond the ability of the sensor itself. Regarding point #2 - I was taught not to show more digits of precision if the measurement itself doesn’t have that level of precision. It’s misleading.

Wish it were better news for your first time here.


Hi, thank you for answering, and thankyou for the datasheet. so, it is not possible to read 1mm. i see, thank you!

1 Like

Very true.

Unfortunately I did not make it clear that, only IF the results of the datasheet analysis indicated that higher levels of precision were possible, then the libraries could be modified to make them available. Obviously, if the sensor can only read in centimeter-sized chunks, going for sub-millimeter precision is pointless.

Actually, this isn’t so bad. It’s better for @kishiro80 to find out right away that the tools he’s using are not capable of doing what he needs them to do, rather than spending days or weeks trying to make lead bricks fly.

Now that the problem is obvious, the solution should be similarly obvious - a sensor with greater accuracy and precision of measurement.

And there are a lot of them out there. SparkFun and Adafruit would be two of the sites I’d look at first. You can also try Digikey or Mouser, but they’re more oriented as suppliers, not “maker” suppliers, so their information and articles will be less.

I have seen articles and advertisements from Sparkfun that talk about high-accuracy/high precision distance measuring devices. Since they use Sparkfun’s Qwick connector interface, it’s easily adaptable to a Grove-sized i2c plug and connector. (I think they even have the adapter cables.)

The downside is that the standard Grove/GoPiGo libraries may not work. The advantage of using places like Sparkfun and/or Adafruit is that they usually have a reasonable set of pre-built libraries for you to use.

One last thought:
Maybe you should re-examine your requirements based on what the sensor CAN do instead of what you WISH it could do. Does your Grove-Pi REALLY need sub-millimeter precision and accuracy? Or, maybe, you could re-examine and relax some other constraint or assumption that would make the need for millimeter precision unnecessary.

1 Like

And I wasn’t trying to imply that you were advocating for false precision. I was just trying to clarify as you did.

1 Like