Benewake LiDAR TFmini (Complete Guide)

20,648

30

23

Introduction: Benewake LiDAR TFmini (Complete Guide)

Description

The Benewake TFMINI Micro LIDAR Module has its unique optical, structural, and electronic designs. The product possesses three major advantages: low cost, tiny volume and low power consumption.

The built-in algorithm adapted to indoor and outdoor environments can guarantee an excellent ranging performance at a low cost and in a tiny volume, which highly expands the application fields and scenarios of LiDAR and lays a solid foundation for future “eyes” in the smart era.

Specifications

  • Input Voltage: 5v
  • Average Power: 0.12W
  • Communication Protocol: UART (Baud rate: 115200)
  • Operating Temperature: -20℃~60℃
  • FOV: 2.3°

Dimensions

  • Size: 42mmx15mmx16mm
  • Weight: 6.1g

Limitations

  • 0cm-30cm "blind" range

Where to Buy

This instructable requires that you are familiar with the following:

  • Basic electronics
  • Hand tools like wire cutters and strippers
  • Reading schematics and connection diagrams
  • C/C++ programming for Arduino (optional)
  • Python programming for Raspberry Pi (optional)

Step 1: Gathering Material

This instructable will take you through different ways of deploying TFmini LiDAR using your Windows PC and Raspberry Pi. Each method has its requirements and can vary based on your needs.

**You'll be needing Benewake TFmini LiDAR for each case (of course)**

For PC Based implementation:

  • OS: Windows
  • USB-TTL converter
  • Jumper Wires

For Raspberry Pi Based implementation:

  • Raspberry Pi
  • Jumper Wires
  • LEDs (optional)
  • USB-TTL converter (optional)
  • Breadboard (optional)
  • Resistor (between 100-1k Ohm) (optional)

Step 2: PC Based Implementation Using Benewake App

  1. Connect TFmini LiDAR to USB-TTL converter using jumper (male-female) wires according to the schematic shown
    • Red Wire --> 5V
    • Black Wire --> GND
    • White/Blue Wire --> Tx
    • Green Wire --> Rx
  2. Plug-in USB-TTL to your computer
  3. Go to Device Manager (Win + X) and locate "Prolific USB-to-Serial Comm Port" under Ports (COM & LPT). Make sure that Windows recognizes the device
  4. Download and Extract WINCC_TF.rar
  5. Run WINCC_TFMini.exe from the extracted files
  6. Select the corresponding COM port from the drop-down menu in Benewake App under the heading Serial Port
  7. Click CONNECT

Step 3: PC Based Implementation Using Python (PySerial)

  1. Connect TFmini LiDAR to PC using USB-TTL converter
  2. Download and open PC_Benewake_TFmini_LiDAR.py using Python IDLE (make sure you have PySerial and Python installed on your PC)
  3. Edit the COM port in the code to match COM port of USB-TTL converter on your PC (see image)
  4. Click Run tab
  5. Click Run Module

**Refer to Step-5 for explanation of the code

Step 4: Raspberry Pi Based Implementation

  1. Connect TFmini LiDAR to RPi using USB-TTL converter or UART port using GPIO
  2. Download and open Pi_benewake_LiDAR.py using Python IDLE
  3. If you're using a USB-TTL converter with RPi, Open Arduino IDE. Click on Tools ->Serial Port, and edit the code accordingly. If you're using UART GPIO port, then write /dev/ttyAMA0
  4. Run the code

**The code could be used to print the distance, but since RPi does not have a lot of processing power, it is advised to light an LED if the distance recorded is below a certain range (schematic for LED with RPi is attached)



Q. Why use USB-TTL converter with RPi?

RPi has only one UART port, and sometimes you need to put a few modules that demand UART communication. USB-TTL provides an additional UART port to RPi giving us an opportunity to connecting more than one UART device (like two or more TFmini LiDAR) to RPi.

Step 5: About the Code

The code can be divided into three parts:

  • Establishing connection
  • Writing data
  • Reading data

Establishing connection:


After importing necessary header files, we estabilish connection to our TFmini LiDAR by stating its COM port, Baud-rate and connection timeout

ser = serial.Serial('COM7',115200,timeout = 1)  #PC
ser = serial.Serial('/dev/ttyUSB1',115200,timeout = 1)  #Raspberry Pi

Writing data:


The code can be divided into two parts, writing and receiving. To receive data, you need to
forward the certain command to TFmini LiDAR (part of initialization process). In this case, I have chosen 4257020000000106. Even though RPi runs the same version of Python but there is a slight change in syntax as RPi does not accept data other than binary.

ser.write(0x42)
ser.write(0x57) 
ser.write(0x02) 
ser.write(0x00) 
ser.write(0x00) 
ser.write(0x00) 
ser.write(0x01) 
ser.write(0x06)

Reading data:

The chart provided in the data-sheet gives us the 'breakdown' of 9-Byte UART message. First two Bytes are frame header having a value of hex 0x59 (character 'Y'). They can be read and used to identify the start of the UART message.

if(('Y' == ser.read()) and ('Y' == ser.read())):

Once the header frame is read, the next two bytes, carrying distance data, could be read. Distance data is divided into two 8-bit packets, Dist_L (Byte3)- Lower 8bits and Dist_H (Byte4)- Higher 8bits.

Dist_L = ser.read()		#Byte3
Dist_H = ser.read() #Byte4

By multiplying Dist_H by 256, the binary data is shifted by 8 to the left (equivalent to "<< 8"). Now the lower 8-bit distance data, Dist_L, could simply be added resulting in 16-bit data of Dist_Total.

Dist_Total = (ord(Dist_H) * 256) + (ord(Dist_L))

Since we have the 'deciphered' distance value with us, the next five byte could be ignore. Note that the read data is not being stored anywhere.

for i in range (0,5):
ser.read()

**In some other place, you might find 'delay' (time.sleep in Python) incorporated before the end of the loop for the reason that the TFmini LiDAR has 100Hz operating frequency. This delay 'program delay' and will result in data being UPDATED after some delay. I believe that since we are already waiting for the data to pile up to 9-Bytes, there shouldn't be any other delay

#time.sleep(0.0005)    #The delay is commented out
while(ser.in_waiting >= 9):
Raspberry Pi Contest 2017

Participated in the
Raspberry Pi Contest 2017

First Time Author Contest 2018

Participated in the
First Time Author Contest 2018

Be the First to Share

    Recommendations

    • Puzzles Speed Challenge

      Puzzles Speed Challenge
    • "Can't Touch This" Family Contest

      "Can't Touch This" Family Contest
    • CNC Contest 2020

      CNC Contest 2020

    23 Discussions

    0
    pierrevoiriot
    pierrevoiriot

    Question 3 months ago

    Hello ! Thanks @Jay_Ali for this guide.

    It works fine with Raspberry and FTDI (serial-usb converter). But not when wiring directly the TF Mini to the raspberry RX and TX pins as shown in your scheme. I tried many things : slow the baud rate, use a logic level shifter , but nothing works!

    Could you please help me? Any idea?

    Thanks!

    0
    raxnocide
    raxnocide

    Question 3 months ago

    Can this sensor be interfaced with 8051 specifically ???

    0
    CloudExile
    CloudExile

    6 months ago

    I am using a raspberry pi 3 and I followed all the instructions and nothing happens. the LED never lights up. I believe @engrqazi pointed there is an error, but I don't understand how to fix the code to make work. I am not using the USB method, just pins. help

    0
    cint_bearcat
    cint_bearcat

    8 months ago

    Excellent guide! Have TF mini working with UNO but would like to try PC app. Downloaded your WINCC_TF.rar but was unable to extract with 7-Zip (exception: "Can not open file [...]\WINCC_TF.rar as archive"). Also tried downloading on Linux box with the same result.

    0
    Jay_Ali
    Jay_Ali

    Reply 8 months ago

    Hello! Thanks for the appreciation. You can find the application at Benewake's website as well, just Google it, hopefully you'll find it

    0
    cint_bearcat
    cint_bearcat

    Reply 7 months ago

    You'd think so but when you click the download button, it has you fill out a request form to which they never respond. All of the many different language Benewake sites do the same thing (even the link provided in the pdf manual doesn't work). After a long search, I did find a working site: http://wiki.seeedstudio.com/Grove-TF_Mini_LiDAR/.

    0
    engrqazi
    engrqazi

    8 months ago

    @Jay_Ali Why you provided those hexadecimal number in the beginning ? They are not necessary. The code is also not working properly. there mistakes in it.

    0
    Jay_Ali
    Jay_Ali

    Reply 8 months ago

    Hello Qazi, Thanks for reading my post.

    I am very much aware that those hex code is not at all necessary. If you had a chance to research the product, you'll must have come across that there are two commands "42 57 02 00 00 00 04 06" and "42 57 02 00 00 00 01 06" for decimal and hexadecimal formatted output (change being in the 3rd last number). I initialize this so we all get same output and our code "works properly".

    Also, the code was tested numerous times before posting. Please consider the fact that this post was written back in Jan 2018 (approx 2 years ago). I bet there's a mismatched/missing library issue, I'd love to help you regarding this issue if you can be specific about the warning/error that you're getting (could be hardware or software as well).

    0
    engrqazi
    engrqazi

    Reply 8 months ago

    I am working in this company Benewake, and I tried this on many LiDARs like TFmini, TFmini plus, TF03 etc, the reason is that you didn’t index these bytes, as this an array form, the terminal displays nothing, just empty terminal.

    0
    pcpushpak
    pcpushpak

    1 year ago

    I'm getting error while connecting tf mini 2 pc using usb to serial conv

    0
    sliawatimena
    sliawatimena

    Question 1 year ago

    where is the url for downloading Benewake App for computer?Thanks again.

    0
    RajP95
    RajP95

    1 year ago

    Can this LIDAR be mounted on a servo to get a 360 degree mapping LIDAR for mapping a room or any indoor unknown environment?

    0
    yashgajara
    yashgajara

    Question 2 years ago

    I am facing error when i connect 2 tf mini lidar to arduino
    the output gets stuck and it does not work. I am attaching the code
    below.

    Thank you

    /*
    The (UNO) circuit:
    Green TX
    White RX
    Red +5V
    Black Gnd
    * Uno RX is digital pin 10 (connect to TX of TF Mini)
    * Uno TX is digital pin 11 (connect to RX of TF Mini)
    */

    #include <SoftwareSerial.h>
    #include "TFMini.h"
    #include <NewTone.h>

    // Setup software serial port
    SoftwareSerial mySerialone(10, 11); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
    SoftwareSerial mySerialtwo(15,14); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
    TFMini tfmini1;
    TFMini tfmini2;

    void setup() {
    // Step 1: Initialize hardware serial port (serial debug port)
    Serial.begin(9600);
    // wait for serial port to connect. Needed for native USB port only
    while (!Serial);

    Serial.println ("Initializing...");
    }


    void loop() {
    // Take one TF Mini distance measurement
    mySerialone.begin(115200);
    tfmini1.begin(&mySerialone);
    uint16_t dist1 = tfmini1.getDistance();
    uint16_t strength1 = tfmini1.getRecentSignalStrength();

    // Display the measurement
    Serial.print(dist1);
    Serial.print(" cm sigstr: ");
    Serial.println(strength1);

    mySerialone.end();
    delay(500);
    // Take one TF Mini distance measurement
    mySerialtwo.begin(115200);
    tfmini2.begin(&mySerialtwo);
    uint16_t dist2 = tfmini2.getDistance();
    uint16_t strength2 = tfmini2.getRecentSignalStrength();

    // Display the measurement
    Serial.print(dist2);
    Serial.print(" cm sigstr: ");
    Serial.println(strength2);

    mySerialtwo.end();

    // Wait some short time before taking the next measurement
    delay(500);
    if (dist1<100 || dist2<100)
    {
    Serial.println("**************************************************");
    NewTone(3,50,100);
    }
    }

    0
    yashgajara
    yashgajara

    2 years ago

    I am facing error when i connect 2 tf mini lidar to arduino
    the output gets stuck and it does not work. I am attaching the code
    below.

    Thank you

    /*
    The (UNO) circuit:
    Green TX
    White RX
    Red +5V
    Black Gnd
    * Uno RX is digital pin 10 (connect to TX of TF Mini)
    * Uno TX is digital pin 11 (connect to RX of TF Mini)
    */

    #include <SoftwareSerial.h>
    #include "TFMini.h"
    #include <NewTone.h>

    // Setup software serial port
    SoftwareSerial mySerialone(10, 11); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
    SoftwareSerial mySerialtwo(15,14); // Uno RX (TFMINI TX), Uno TX (TFMINI RX)
    TFMini tfmini1;
    TFMini tfmini2;

    void setup() {
    // Step 1: Initialize hardware serial port (serial debug port)
    Serial.begin(9600);
    // wait for serial port to connect. Needed for native USB port only
    while (!Serial);

    Serial.println ("Initializing...");
    }


    void loop() {
    // Take one TF Mini distance measurement
    mySerialone.begin(115200);
    tfmini1.begin(&mySerialone);
    uint16_t dist1 = tfmini1.getDistance();
    uint16_t strength1 = tfmini1.getRecentSignalStrength();

    // Display the measurement
    Serial.print(dist1);
    Serial.print(" cm sigstr: ");
    Serial.println(strength1);

    mySerialone.end();
    delay(500);
    // Take one TF Mini distance measurement
    mySerialtwo.begin(115200);
    tfmini2.begin(&mySerialtwo);
    uint16_t dist2 = tfmini2.getDistance();
    uint16_t strength2 = tfmini2.getRecentSignalStrength();

    // Display the measurement
    Serial.print(dist2);
    Serial.print(" cm sigstr: ");
    Serial.println(strength2);

    mySerialtwo.end();

    // Wait some short time before taking the next measurement
    delay(500);
    if (dist1<100 || dist2<100)
    {
    Serial.println("**************************************************");
    NewTone(3,50,100);
    }
    }

    0
    lymulanqf
    lymulanqf

    2 years ago

    That's really very detailed information about the cost-effective LiDAR TFmini. Nice post ! Very helpful !

    0
    KalpeshB4
    KalpeshB4

    Question 2 years ago

    I am getting output as shown in image attached.. definitely its not in cm.. help me with that..

    IMG_20180319_232601391_HDR.jpg
    0
    Jay_Ali
    Jay_Ali

    Answer 2 years ago

    (Update) Hey KalpeshB4! I was facing the same
    issue earlier today, turns out I had a loose connection. I cut the wire and the
    jumper and soldered it, and now it's working perfectly fine.

    0
    Jay_Ali
    Jay_Ali

    Answer 2 years ago

    Correction: LiDAR can sense from 30cm to 1200cm (12m). Are you using the same model?

    0
    Jay_Ali
    Jay_Ali

    Answer 2 years ago

    I am not sure about the environment you're using to test your LiDAR. LiDAR can sense up to 12m (12000 cm). In outdoor conditions the value can lie between 30cm to 7000cm