Servers by jDrones

How to make the TFMINI rangefinder talk I2C

(ppoirier) #1

The 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 ( 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

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.

You can find the INO sketch on my github
and feel free to download and try :slight_smile:

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:
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

This is a ''Double Decker Foam Tape Sandwich"

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

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:

Benewake TF mini Setup
Benewake TFmini LIDAR works on Ardupilot
Avoidance Experiments with the POC and Benewake TFMINI
Benewake TFmini - Inexpensive LiDAR With Teensy 3.5
PX4 Flow Bad Health Problem
Using sonar and PX4FLow
Maxbotix sonar 1202 and 1242
(Siya Liu) #2

TFmini is easy to use and integrate : )

It’s easy to find this TFmini LiDAR on eBay:

(Asterion Daedalus) #3

I seem to have lost my cable for my TF Mini, likely threw it away with the wrapping. The female socket is a strange one. Does anyone know the socket type please? Any hints where I might get a replacement cable please?


(ppoirier) #4

Its a JST GH
I buy them at Aliexpress

(Asterion Daedalus) #5

You are a life saver. Thanks.

(rickyg32) #6

You have a method for running the Benewake on I2c. Dude this is awesome.
IS the LIDAR in Pix mode, not sure the difference yet.

(rickyg32) #7

Are there instructions on wiring it up.

(ppoirier) #8

Take an image of a pro mini and compare with the build picture, you can see where the vcc-gnd-rx-tx and scl-sda are connected

(rickyg32) #9

Yup I see it now. The site wouldn’t give me the larger image when I clicked. My pc has been up for weeks, it was time for a reboot. Thanks man this is awesome, I added the Pro Mini to my shopping list at Banggood. I assume the lidar is running not in pixmode and that I need to tell Arducopter I am using an I2C Lidar and then it works. This is great as I used up all my uart ports and was looking to by a new GPS that used the CAN port. Not something I really wanted to do as the GPS is expensive and I already had two perfectly good ones. Using this method gets me back to the dual GPS for only a few dollars and an hour of work, much cheaper then the 129US for the GPS.

(rickyg32) #10

Another question came to mind. If I want to run two Lidar as I2C I assume I need a different address for each Pro Mini. Is there a way of defining the address or is there something I am missing. I ask because a forward facing Lidar would make for some interesting collision avoidance. Also curious what Opti Flow unit your using.

(ppoirier) #11

@rickyg32 This is a good question

We can change the address here:

But I think that Ardupilot just accept ONE Maxbotix for the moment, (the parameter is fixed), to use multiple sensor, we would need to change the emulation for a Lightware …that is indeed more flexible driver for multiple devices == > I am going to give it a try :wink:

My optical flow is the PX4 FLOW, it works like a charm on all platforms.

(rickyg32) #12

Hey man thanks for getting back to me. I only have the one Lidar right now so I have time to wait. I hope your successful as I think it opens up a world of simple and cheap avoidance systems. Benewake are offering to sell me another TFmini for about 29 bucks and thinking I would buy it. The Pro Mini is something stupid like 3 bucks canadian so thats less then 40 bucks to add a second Lidar that’s forward facing plus the existing Lidar I already have. To give me alt hold and anti collision. While saying me 130 US for a new GPS that I now don’t need thanks to you. I am going to go and order the pro mini because at a minimum I want alt hold via I2C.

Update Ordered my Pro Mini.

(ppoirier) #13

@rickyg32 Good news !!!
I never realized that Lightware was talking the same as Maxbotix so in order to get multiple sensor working , just have to specify
RNGFND_TYPE 7 (LightWare)
RNGFND_ADDR 112 (70 Hex is 112 Dec)

and change address on the subsequent units… sooooooooooooo easy :slight_smile:

(rickyg32) #14

Seriously thats it. No way.
Wa hooo…ok thats cool. I have ordered 3 Pro Mini’s can always use a spare and will make the mod and get myself an I2C version running. Very cool thanks man.

Or should I say thanks Fellow Canadian.

(ppoirier) #15

Yep, those who lives in the cold…
Someone asked me to test the TFMINI outside last week , I told him that it was -28 in Québec city that morning :wink:

(rickyg32) #16

Yeah been the same around darn cold, Ah Quebec City my favorite Canadian City.

I assume to change the address I can just edit the INO file and find a hex to decimal converter to grab the decimal equivalent of what ever address I am picking, I think I would just go 71 Hex which I think is just 113 in decimal if I remember my Hex conversion been a while since I had to do it.

This is awesome. Just need my Pro Mini and I am off.

Merci beaucoup monsieur

(Siya Liu) #17

@Asterion_Daedalus Hello, if you need to make a cable for TFmini by yourself, you could check this picture with the connector wire order. The connector model number is GH1.25-4p, pin spacing is 1.25mm.

I think it’s easy to make a cable or weld wires directly to the TFmini connectors by your talents. : )

(rickyg32) #18

(rickyg32) #19

Just got my pro mini today. downloaded the INO so might flash it tonight.

(rickyg32) #20

In case anyone is interested,