I had these ping sensor laying around for quiet some time and decided it's time to take a look at them. And since I have both sensors I thought maybe I should compare the two and see if they both work the same.
The nice thing about the laser ping sensor is that it has an ascii mode that will just give you the answer in millimeters rather than measuring the PWM value. I also notice there was not a driver for the laser ping sensor only the ultrasonic version.
So I quickly wrote up a laser ping driver and made it so that it would run in a cog so I could just set it and read the answers. I also had it average the answer over 10 reading so it would be a little more stable.
Here is the test code:
#define LASER 16
#define PING 0
i = laserping_distance();
printi("Distance: %d\n", i);
My setup was a box positioned 150 mm in front of the sensors.
So first the code puts the laser ping into serial mode and displays the answer. The answer was about 147 but jumped around 145 to 150. Never came back as a constant distance.
Next I put the unit into PWM mode and had to multiple by 174 and divide by 1000 to get the same readings. The manual states you should use 171.5 but that did not seem to be enough to come up with the same readings. Maybe my unit is not calibrated the same.
Next I tested the ultrasonic ping sensor using the same setup. For this unit I used the 171.5 value since it produced about the correct distance with a reading of 151. The value did not move around like the laser sensor and was a constant 151. Now I don't know if the distance is from the center of the speakers or measured from the printed circuit board. That would make about a 10mm difference in the measurement.
Anyway the to sensors are very close in distance but the ultrasonic unit produce more stable measurements.
I did find out that adding a moving a light source around caused the reading of the laser ping sensor to jump around a bit.
Being they are pin compatible is a nice touch and thinking that a light sensor should be better than a sound one may not be the case.