TF-mini Lidar sensor does not work properly on pixhawk

It looks like with firmware version 16x they replaced mode 02, 07 by mode 00, 03, 07.

Sparkfun delivered a Tfmini with 160 firmware recently.
It works fine with an Arduino serial-i2c converter based on . From what I have seen in this Arduino-lib they do no distance scaling according to the mode at all. Returns always cm.

In contrary AP_RangeFinder_Benewake.cpp scales distance by factor 0.1 in mode 2.
But mode 2 does not exist with firmware 16x devices anyway.

1 Like


Thanks for looking into this. So I guess during the test the sonar was much more than the 9cm to 12cm shown in the log? … and presumably we think the issue is that the mode is coming out of the sensor as “2” and is being made 10x smaller than it should be? If true this is a bit of an issue because I’d say this would be a “breaking change” by benewake. In that it’s not backwards compatible.

I made a short bench test with a spare Tfmini (160 firmware) with a spare X2.1.

mRoX21 00570033 3236510B 36363331
ChibiOS: ff603d11
ArduCopter V3.6.2-rc3 (0e61bbe6)

Short and longrange measurement are correct!

Maybe mode 2 works as before. They just don’t use it any more with 16x firmware.

@rmackay9 ok will test tonight

Rainer, looking at opensensinglab link , it seems to be a serial-to-serial conversion , no I2C ( include <Wire.h) driver involved…?

Right, this is just the lib to read TFmini device. I didn’t want to fight with the TFmini protocol in my sketch. I took one of the example Sketches and merged it, I think it was your Sketch, to run on a Arduino Pro Mini 8MHz 3,3V.
TFmini is connected via softserial Pin 10/11 @57600 baud. (8 MHz Pro Mini can’t handle 115200 baud softserial)

I don’t know, if it is the right place, but anyway … here is the sketch I’m currently using with an Omnibus F4 Nano. (2.0 KB)

Cool , you could upload on github and make a link on my blog as an ‘‘alternative code’’ :slight_smile:

After all this can you translate. As you know I am a TF Mini owner…but not sure what if anything I need to do to ensure I am successful in my use of it.


1 Like

Ricky, We are still testin the new driver. It might be workin ok now but I have not tested it yet. I’ll let you know when fully ready :slight_smile:

1 Like

You da man.
thank you sir…I am in no hurry. My machine is down with a gps issue so there is time, just thought i would ask.

1 Like

@rmackay9 here is the result , looking good …BUT I had to disable the short distance mode in order to make good readings.

Then I upgraded both TFMINI (from Version 1156 to latest: 2156) and according to @RainFly note:
…with firmware version 16x they replaced mode 02, 07 by mode 00, 03, 07.

I had to change line 125 to
if (linebuf[6] == 0x03 ) {
and it worked.

May I suggest that we just remove this distance compensation (lines 123-126) check ?

Hummm it seems it is still 02-07 mode

Hi Randy

RNGFND_ORIENT=25 is only work
Others don’t work, so i couldn’t test the obstacle avoidance

(TF-mini/Pixhawk/Copter 3.6.2rc3)

I also would suggest to comment out or remove the special mode 2 handling.
This is what you already did, if you changed 2 --> 3 and the device sends mode 2 measurements.
None of the Arduino libs I looked at have a special handling like this.
Also in the data sheet I can’t find any information, that tfmini sends different units for different modes. Just a global setting for mm and cm.

Maybe I find time tonight to check my tfmini with Realterm.



Txs for testing. So you found that the distances were reported accurately and reliably as far as you could tell? How about a distances below 1m? Also do you know if your lidar has firmware version 15 or 16? Sorry for the questions, thanks for the feedback in any case.

Re other orientations not working, I suspect it’s a setup issue with the Avoidance and/or Proximity parameters. If you’ve got a dataflash log I can have a look

1 Like

@ppoirier, @RainFly,

Thanks very much for all this detailed analysis. It’s really helpful.

OK, I’ll push out a 3.6.2-rc4 (hopefully tomorrow) that has the mode-2 scaling thing removed. I’ve looked at the datasheets as well and I’m not quite sure why we thought this was necessary.

1 Like

Hi Randy

TF-mini firmware 1156 -> 2156 upgrade.

but, same result.

I think that 1m over is reliable.

still have problems within 1m.

Only when RNGFND_ORIENT = 25, distance measurements can be seen on the mission planner.

I’ve just tested without flying

Arming and spinning motors and moving distance measurements.

Here is the setting for object avoidance

and log.

2018년 11월 20일 (화) 오후 4:32, rmackay9 noreply@ardupilot.org님이 작성:

58 1980-01-01 오전 9-00-00.bin (656 KB)

58 1980-01-01 오전 9-00-00.bin.log (1.52 MB)

I’ve put a patched version of 3.6.2-rc3 here which simply has the “mode 2” handling removed.

It really should perform just like @ppoirier found I think… if anyone would like to double check then that would be greatly appreciated. sincere apologies for the number of attempts this is taking.

Txs again…

P.S. PR is here to put this change in master.

1 Like

Hello Randy,
Yes this mod works OK.
I will test the TF02 as well and report after a test flight with both sensor.
Thanks again for you availability and dedication (thanks to @OXINARF too) :wink:


Hi all
I have mounted the Benewake TF mini lidar in SERIAL4 / 5, I have the following configuration:

SERIAL4_BAUD = 115 (115200 baud)
RNGFND_TYPE = 8 (LightWareSerial)

I’ve been using it since the version copter 3.5.0
Recently I flew with the version copter 3.5.7, working very well

A few days ago I upgraded to the copter version 3.6.1. and testeand in mission planer seems to work well

I hope to contribute my little grain of sand

regards to all