Seeking help, 0 readings from TF03 Benewake Lidar sensor

Hello, new to the forum, and I am trying to obtain readings from a TF03 Benewake sensor using the Uno board. The idea is to use the sensor as a camera trigger. I have the camera trigger part figured out, but am not able to get distance readings from the sensor, it is only showing a distance of 0 on the Serial Monitor. This is the initial code that I have been trying, found on this page:

[TF03 (ToF) Laser Range Sensor(100m/180m)]

This is also a source that i have been using:

https://paulillsley.com/arduino/lidar_camera_trigger.html

I also installed the TF Mini Library that apparently also works with this sensor. Also used the wiring information provided by the manufacturer, and supplying the required 5v of power to the TF03 sensor via the board (verified with multimeter). Also experimented with lower baud rates.

Bellow is the last code that I tried to use, any assistance would be greatly appreciated.

//------------- Code Starts Here ----------------------------

//-----------------------------------------
//Published by:
//Created by:
//-----------------------------------------

//======================= Start of Settings ===================

// *** Set the Minimum Distance trigger value (in cm) ***
int Minimum_Distance = 10;

// *** Set the Maximum Distance trigger value (in cm) ***
int Maximum_Distance = 600;

// *** Set the Delay value to wait for the camera's flash to recharge (in seconds) ***
int delay_seconds = 5;

//======================= End of Settings ====================

#include <Arduino.h>
#include <Wire.h>            // Including the Wire library
#include <DFRobot_TFmini.h>  // Including the TFmini Library (this needs to be installed)

DFRobot_TFmini tf03;

//Defining pin 13 for the Confirmation LED
#define LED 13

// Defining pin 4 for the Camera "Trigger" setup
#define Trigger 4

int16_t  Distance_cm;    // distance in centimeters

void setup(){
   Serial.begin(115200);    // Initalizing the Serial Port at a baud rate of 115200
   delay(20);
   Wire.begin();          // Initalizing the Wire Library

   // setting pin 13 (the LED) as an output (this is also the pin for the UNO's on-board LED).
   pinMode(13,OUTPUT);
   pinMode(4,OUTPUT);

   // Turning pin 4 (Trigger) off
   digitalWrite(Trigger , LOW);
}

void loop(){

   digitalWrite(LED , LOW); // Turning off the LED (Pin 13)

   // Pulling a distance value (in cm) from the TF03
   tf03.getDistance();//Distance_cm, tfAddr);

   // Write the distance to the serial monitor
   Serial.print("Distance (cm): ");
   Serial.println(Distance_cm);

   // Checking the distance for "In Trigger Zone"  LED
   // If the distance is above or equal to the Minimum and below or equal to the Maximum
   // turn on the LED
   if ((Distance_cm >= Minimum_Distance) && (Distance_cm <= Maximum_Distance)){
   digitalWrite(LED , HIGH); // Turning on the LED (Pin 13)
    }
   else{
   digitalWrite(LED , LOW); // Turning off the LED (Pin 13)
    }

   // Checking the distance for Camera Trigger
   // If the distance is above or equal to the Minimum and below or equal to the Maximum
   if ((Distance_cm >= Minimum_Distance) && (Distance_cm <= Maximum_Distance)){

   // Record an image (Trigger)    
   digitalWrite(Trigger , HIGH); // Turning on pin 4 (Trigger)  
   delay(100); // Delaying 100 milliseconds
   digitalWrite(Trigger , LOW); // Turning off pin 4 (Trigger)

   // Delay a set period of time (delay_seconds) to let the camera's flash recharge
   delay(delay_seconds*1000);
 }
}

//------------- Code Stops Here ----------------------------

When posting, please provide complete wiring information and links to components.

With a new device and device library, ALWAYS start with the library examples, and make sure that one or more work as expected.

Your code appears to be missing one or more absolutely critical function calls. Compare with the example in this library:

Thank you for this. I did also try with this example to just try to simply get a measurement reading, but am obtaining the same 0 readings, which I think is basically no information being received by the sensor. As far as the wiring, Red to 5V, Black to GND, and brown to 13 to transmit (for TX) and Blue to 12 to receive (TX). The code was adjusted accordingly.

SoftwareSerial mySerial(12, 13); // RX, TX

I just noticed you are using the Arduino Uno.

The TFMini uses 3.3V I/O. You cannot connect it to I/O pins on a 5V Uno without using logic level shifters. You may already have damaged the TFMini, the Uno, or both.

We are actually using the TF03, which takes 5V

5V POWER, 3.3V I/O

As stated, you may already have damaged the TF03, the Uno, or both.

From the TF03 product page:

Electrical Parameters
Supply Voltage: 5V±0.5V
Average Current: ≤180mA
Power Consumption: ≤0.9W
Peak Current: ≤180mA
Communication Voltage Level: LVTTL(3.3V)
Communication Interfaces: UART/CAN/IO

Good luck with your project.

Thanks again. So the issue may be the communication voltage from the UNO being 5V and not 3.3V. I just ordered some logic level shifters to get it down to 3.3V. The examples we found seem to be directly wired to the UNO.

Also ordered a USB to TSSL module to test the TS03 with the manufacturers software. The UNO board is still functioning for other commands. Will report back.

We finally have success with the following code.

//------------- Code Starts Here ----------------------------

//-----------------------------------------
//For: C
//Created by: 
//Written by: 
//-----------------------------------------

//======================= Start of Settings ===================


#include <SoftwareSerial.h> //header file of software serial port

SoftwareSerial Serial1(2,3); //define software serial port name as Serial1 and define pin2 as RX (TF03 Brown wire) and pin3 as TX (TF03 Blue wire (not in use))

/* For Arduinoboards with multiple serial ports like DUEboard, interpret above two pieces of code and directly use Serial1 serial port*/

int dist; //actual distance measurements of LiDAR
int check; //save check value
int i;
int uart[9]; //save data measured by LiDAR const
int HEADER=0x59; //frame header of data package
int delay_seconds = 3; // Change this “delay_seconds” value to adjust the time between images (in seconds)
int Trigger = 4; // Naming pin 4 "Trigger"
// int16_t  Distance_cm;    // distance in centimeters

int Minimum_Distance = 100; // *** Set the Minimum Distance trigger value (in cm) ***
int Maximum_Distance = 2000; // *** Set the Maximum Distance trigger value (in cm) ***

void setup() {
  Serial.begin(9600); //set bit rate of serial port connecting Arduino with computer
  Serial1.begin(115200); //set bit rate of serial port connecting LiDAR with Arduino
  
  pinMode(Trigger , OUTPUT); // Declaring pin 4 (Trigger) as an output
  digitalWrite(Trigger , LOW);  // Turning off pin 4 (Trigger)
}
  
void loop() {
  if (Serial1.available()) { //check if serial port has data input
    if(Serial1.read() == HEADER) { //assess data package frame header 0x59
     uart[0]=HEADER;
      if (Serial1.read() == HEADER) { //assess data package frame header 0x59
        uart[1] = HEADER;
        for (i = 2; i < 9; i++) { //save data in array
         uart[i] = Serial1.read();
        }
        check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];
        if (uart[8] == (check & 0xff)){ //verify the received data as per protocol
         dist = uart[2] + uart[3] * 256; //calculate distance value
          Serial.print("dist = ");
          Serial.println(dist); //output measure distance value of LiDAR

        if ((dist >= Minimum_Distance) && (dist <= Maximum_Distance)){
          digitalWrite(Trigger , HIGH); // Turning on pin 4 (Trigger)
        }
        else{
          digitalWrite(Trigger , LOW); // Turning off pin 4 (Trigger)
        }

         Serial.print('\t');
        }
     }
   }
  }
}

Our next challenge is to have 3 photos taken at 3 second intervals after the sensor is triggered, and not just a single image.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.