LiDAR Sensor – TF-Luna

What is? How do? And many other questions left unanswered in a sea of obscurity.


Hardware

Below is an excerpt from the datasheet giving the pinout of the sensor. The connector is a [insert from notes – could be pico molex or super small JST].

The power ideally needs to be from a 5V rail (datasheet notes a voltage range between 3.7V & 5.2V). I’ve not checked, but I doubt it will work with a 3V3 supply.

The logic pins are compatible with 3V3 boards, so you don’t need a logic level converter for an ESP32/ESP8622.

Ground pin 5 to turn the sensor to I2C mode.


The Code

This library by Bud Ryerson is brilliant and handles the commands with the I2C interface.

This is the example code. Don’t change the data types for the tfDist & tfAddr else the program won’t compile. (Ask me how I know)

/* File Name: TFLI2C_simple.ino
 * Developer: Bud Ryerson
 * Date:      10 JUL 2021
 * Version:   0.1.1
 * Described: Simplified Arduino example sketch for the Benewake
 *            TF-Luna Lidar sensor configured for the I2C interface
 */
 
#include <Arduino.h>     // Every sketch needs this
#include <Wire.h>        // Instantiate the Wire library
#include <TFLI2C.h>      // TFLuna-I2C Library v.0.1.1

TFLI2C tflI2C;

int16_t  tfDist;    // distance in centimeters
int16_t  tfAddr = TFL_DEF_ADR;  // Use this default I2C address or
                                // set variable to your own value

void setup()
{
    Serial.begin( 115200);  // Initalize serial port
    Wire.begin();           // Initalize Wire library
    Serial.println( "TFLI2C example code simplified"); // Say "Hello!"
    Serial.println( "10 JUL 2021");                    // and add the date.
}

void loop()
{
    if( tflI2C.getData( tfDist, tfAddr)) // If read okay...
    {
        Serial.print("Dist: ");
        Serial.println(tfDist);          // print the data...
    }
    else tflI2C.printStatus();           // else, print error.

    delay( 50);
}

The datasheet notes that you can have a maximum frame rate of 250Hz, however it’s set to 100Hz by standard.


Last updated: 18/12/2022