Lidar tf mini-s to arduino nano

I have a lidar tf mini-s I'm trying to connect to my arduino, but the arduino does not receive any data input from the lidar.
The code is online and proven to work, but when I connect it stops at initializing. From what I searched it means it does not receive data from the lidar.

This is the website I referred to and the code below:

#include <SoftwareSerial.h>
#include "TFMini.h"
TFMini tfmini;
 
SoftwareSerial SerialTFMini(2, 3);          //The only value that matters here is the first one, 2, Rx
 
void getTFminiData(int* distance, int* strength)
{
  static char i = 0;
  char j = 0;
  int checksum = 0;
  static int rx[9];
  if (SerialTFMini.available())
  {
    rx[i] = SerialTFMini.read();
    if (rx[0] != 0x59)
    {
      i = 0;
    }
    else if (i == 1 && rx[1] != 0x59)
    {
      i = 0;
    }
    else if (i == 8)
    {
      for (j = 0; j < 8; j++)
      {
        checksum += rx[j];
      }
      if (rx[8] == (checksum % 256))
      {
        *distance = rx[2] + rx[3] * 256;
        *strength = rx[4] + rx[5] * 256;
      }
      i = 0;
    }
    else
    {
      i++;
    }
  }
}
 
 
void setup()
{
  Serial.begin(115200);       //Initialize hardware serial port (serial debug port)
  while (!Serial);            // wait for serial port to connect. Needed for native USB port only
  Serial.println ("Initializing...");
  SerialTFMini.begin(TFMINI_BAUDRATE);    //Initialize the data rate for the SoftwareSerial port
  tfmini.begin(&SerialTFMini);            //Initialize the TF Mini sensor
}
 
void loop()
{
  int distance = 0;
  int strength = 0;
 
  getTFminiData(&distance, &strength);
  while (!distance)
  {
    getTFminiData(&distance, &strength);
    if (distance)
    {
      Serial.print(distance);
      Serial.print("cm\t");
      Serial.print("strength: ");
      Serial.println(strength);
    }
  }
  delay(100);
}

Did you try the example sketches that were installed with the TFMini library?

1 Like

I haven't, I will try and update you. Thank you!

hi it still doesn't work, stuck at initializing.

yes I have, it does not work either

It could be that you have connected the sensor incorrectly, or the sensor is faulty.

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