LinuxDrone Project How to make the TFMINI rangefinder talk I2C

sophia lee

Member
he Benewake TFMINI is a small Laser RangeFinder that has a lot of potential as a replacement for the Sonar. Its in the same price range as the Maxbotix and it has a range up to 12 Meter indoor and 6 Meter outdoor.

It comes preconfigured in binary output at 115200 Bauds and we can change the mode by issuing these commands through the Benewake console (http://benewake.com/en/down.html6) or using Realterm:
The command of standard output is 42 57 02 00 00 00 01 06
The command of pix format output is 42 57 02 00 00 00 04 06

The pixformat send clear ascii distances in meter and we can read directly this format x.xx (cr-lf). Within this mode it can be used with ArduPilot by choosing Lightware Serial @ 115200 Bauds


image.jpg525x700 152 KB



Most of us are using the serial ports -UARTS- for other purposes and the need for switching this device to an I2C interface was needed. This is the goal of this presentation, create an emulator using an Arduino Pro Mini (3$ at Bangood) to transform the serial stream to I2c as it can be use directly using the MaxBotix
MaxsonarI2CXL emulation.

1
You can find the INO sketch on my github https://github.com/patrickpoirier51/TFMINI_MAXBOTIX_EMULATOR17
and feel free to download and try
slight_smile.png


Basically its reading the TFMINI serial stream in the binary format , check for the 2 start characters, read the whole frame, perform the checksum and transform into distance if all ok:
TFMINI FRAME:
0x59 - 0x59 - Dist_L - Dist_H - Strength_L - Strength_H - Reserved - Raw.Qual- CheckSum

It perform some transformation :
uint8_t OffSet = 120 ; //Offset error of the LIDAR
uint8_t Scaling = 10 ; //Benewake outputs in mm, we have to scale to cm

And send the distance in 2 Bytes when requested by the I2C Master:
void requestEvent()
{
Wire.write (highByte(distance));
Wire.write (lowByte(distance));
}

Here are pictures of the , build and installation in a Quad 330:
Pro Mini into Heat shrink with thw JST GH cable cut-trimmed and installed

2
This is a ''Double Decker Foam Tape Sandwich"

2
And this is the video showing thw TFMINI in action with the PX4FLOW , both connected on the same I2C of the PIXRACER, flying indoor - No GPS- and being tracked by Mission Planner using EKF3

Q330 TFMINI OPTICAL FLOW
If you look at the video, you can see that I am sliding a white coroplast to show the RangeFinder adjust height (well .. I tried..) and on the screen you can see the Bad Lidar Health message, this is because the TFMINI generate an error on low range (below 30 CM), this error make the signal going to longer distance (for example @ 20 cm , it output 40 cm), this error is intercepted by ArduPIlot as a momentary error, that does not affect the flight but is crtical on takeoff. I have been told that Benewake is working on this issue. Nonetheless it makes a good and cheap little range finder and it also can be used as an avoidance system....more to follow
wink.png
 

Top