Benewake LiDAR TFmini (Complete Guide)

3,820

22

9

Published

Introduction: Benewake LiDAR TFmini (Complete Guide)

About: Final year student. Loves Programming.

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

Share

    Recommendations

    • Water Contest

      Water Contest
    • Creative Misuse Contest

      Creative Misuse Contest
    • Oil Contest

      Oil Contest

    9 Discussions

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

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

    IMG_20180319_232601391_HDR.jpg
    3 more answers

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

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

    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

    i have tried to use this lidar with rpi 3. I havent got any expected result. Output distance is in mm or not?

    If you have any additional information please mail it to me

    1 more answer

    Output distance is in cm. Can you share what kind of output you're getting?

    Amazing sensor! I might use this in a future robotics project!