Servers by jDrones

Benewake TFmini - Inexpensive LiDAR With Teensy 3.5


(Sophia lee) #1

The Benewake TFmini LiDAR unit is a small, very light weight LiDAR sensor for about $50 Canadian. Documentation was good, but incomplete. It provided details on receiving data from the sensor, but forgot to mention the signal needed to put the sensor into the default mode so that it actually sends the data. Luckily that was in the debugging document.

So this is what worked for me, and it’s really a easy device to work with.

I chose to use a Teensy 3.5 as it has multiple HW Serial ports, it’s more than fast enough to receive data and process it without letting data pile up. Just for fun I used the Teensy Threading library to separate getting the data from the rest of the code.

Step 1: Connecting TFmini to Teensy 3.5 (similar for Arduino Mega)

This example requires two serial connections: one to the TFmini, and one to display results on your computer. For this reason, and as far as I can tell, this reason only, this particular example won’t work on anything below an Arduino Mega or Teensy 3.x.

That being said, for applications not requiring serial output to print to computer screen, the same project should be adaptable.

Using included wire harness:

  1. connect black wire to Teensy GND (if using difference VDC source, ensure ground also goes to GND on Teensy)

  2. connect red wire to Teensy Vin (or 5VDC source)

  3. connect white wire (TFmini RX) to pin 1 on Teensy (Serial1 TX)

  4. connect green wire (TFmini TX) to pin 0 on Teensy (Serial RX)

The included wire harness was too small for me to work with on a bread board, so I cut off the end opposite the TFmini, and soldered the wires to a breadboard, add a JST connector to the breakboard, and made a JST to male jumper wire harness.

Step 2: Code to Run It

Use the following code (for Teensy 3.5) or download the attached file:

For Arduino Mega, threading likely won’t work. Move code from readLiDAR function to main loop, and remove anything related to threading.

#include <arduino.h>
#include “TeensyThreads.h”
// Using supplied cable:
// - Black = GND (connected to GND)
// - Red = 5V (4.5 - 6.0V) (connected to Vin on Teensy 3.5, or 5V on Arduino)
// - White = TFmini RX (aka. connect to microcontroller TX, pin1 on Teensy 3.5)
// - Green = TFmini TX (aka. connect to microcontroller RX, pin0 on Teensy 3.5)
// NOTE: for this sketch you need a microcontroller with additional serial ports beyond the one connected to the USB cable
// This includes Arduino MEGA (use Serial1), Teensy (3.x) (use one of the available HW Serial connections)

volatile int liDARval = 0;

void readLiDAR(){
// Data Format for Benewake TFmini
// ===============================
// 9 bytes total per message:
// 1) 0x59
// 2) 0x59
// 3) Dist_L (low 8bit)
// 4) Dist_H (high 8bit)
// 5) Strength_L (low 8bit)
// 6) Strength_H (high 8bit)
// 7) Reserved bytes
// 8) Original signal quality degree
// 9) Checksum parity bit (low 8bit), Checksum = Byte1 + Byte2 +…+Byte8. This is only a low 8bit though
while(1){ // Keep going for ever
while(Serial1.available()>=9) // When at least 9 bytes of data available (expected number of bytes for 1 signal), then read
if((0x59 == && (0x59 == // byte 1 and byte 2
unsigned int t1 =; // byte 3 = Dist_L
unsigned int t2 =; // byte 4 = Dist_H
t2 <<= 8;
t2 += t1;
liDARval = t2;
t1 =; // byte 5 = Strength_L
t2 =; // byte 6 = Strength_H
t2 <<= 8;
t2 += t1;
for(int i=0; i<3; i++); // byte 7, 8, 9 are ignored
void setup()
Serial1.begin(115200); // HW Serial for TFmini
Serial.begin(115200); // Serial output through USB to computer
delay (100); // Give a little time for things to start
// Set to Standard Output mode
// Setup thread for reading serial input from TFmini
void loop()
delay(10); // Don’t want to read too often as TFmini samples at 100Hz
Step 3: Using Arduino IDE View Results in Serial Plotter

You can use whatever method you’d like, but Arduino’s IDE will plot the results nicely.

Connect to the Teensy, and open Serial Monitor. Ensure Baudrate is set to 115200.

(ppoirier) #2

Hello Sophia
This is a very interesting Blog about interfacing the TFMINI on a Teensy.
I am working on a similar project and I would be interested to know if your multithreading method would allow to read multiple sensors (up to 5 TFMINI). You can obviously reduce baud rate down to 9600 baud on the sensor to prevent overflow.

Please let me know if you have positive results :slight_smile:
Best Regards

(Sophia lee) #3

Hi ppoirier, 9600 baud rate can be adjusted, multi-threading does not support, at present only a serial port, only supports one-to-one communication.

(Sophia lee) #4

Hi ppoirier,
Have a nice day!
Year, i know you have contacted to Ms Siya for our TFmini LiDAR sensor , then 9600 baud rate can be adjusted, multi-threading does not support, at present only a serial port, only supports one-to-one communication.
We are so happy that you give us interaction.
Hope it can help you.
Thanks and best regards!
Ms sophia

Ms sophia
International Sales manager
Benewake (Beijing) Co., Ltd
TEL: 0086-13716314709
Skype: snow840910

(lucamax) #5

I recently bought three Lidars.
Lightware LW20 I2C version , LeddarOne and Benewake TFmini, the last two with serial connection .

I did just a short test with the TF-mini .
I do not like the fact that under 30 cm , where the sensor is not supposed to work, the manufacturer call it “blind area” , the reading jump from 30 cm to 1,5 meters.
So do not forget to set the right parameter in range finder parameters or you might see during landing your altitude estimation jump from 30 cm to 1,5 meters.

The LeddarOne measure correctly till a couple of centimeters but cost 3 times the TFmini.

(Sophia lee) #6

Hi lucamax, what application do you use the LiDAR sensor? According to the signal strength, You can judge the data from close range is trusted or not.

(lucamax) #7

Arduplane 3.8.3 checked with Mission Planner

(David ) #8

hi Sophia, is it also possible use Teensy 3.5 and lidar mini with final connection on pixfalcon?You advice serial of the fc or i2c?

(Sophia lee) #9

Yes,it is can be used, ours is a serial port, there is no I2C now
TFmini if the connection is Pixfalcon serial port, can not use Teensy.
TFmini if the connection is Pixfalcon I2C interface, you can use the Teensy as a transfer.

(Sophia lee) #10

Hi David, where did you purchase our TFmini lidar sensor and what application do you use it? we can contact by mail, my email

(David ) #11

Hi, i bought the tf mini lidar on roboshop, for now i setup it on arduino
mini pro and connected it on my pixhawk on i2c coz in this way its an
emulation of maxbotix sonar, ive done the settings on mission planner but
the parameter is always 2.55,even im moving something in front of the
sensor the parameter still the same.

(Sophia lee) #12

Please kindly find and check the demo display and update sheet in the google link:
And try it again

(Sophia lee) #13