Go Down

Topic: Development Routines of TF LiDAR on Arduino (Read 957 times) previous topic - next topic

Kevin_Sunny

Hello, everyone. I am sharing how to connect Benewake TF LiDAR to Arduino.
May this helpful.
Step 1: Hardware Connection
    The linear order for the LiDAR products of our company is defined as: red +5V, black GND, green
TX, white RX; the power supply voltage for TF02 is 5V, so it is permissible to directly connect 5V and
GND on the Arduino board. For other LiDARs, please refer to product specification to ensure normal
power supply; For serial communication connection, please note that with regard to Arduino UNO board, the TX end of LiDAR connects to pin 2 port (soft serial port Serial1's RX) and the RX end of LiDAR connects to pin 3 (soft serial port Serial1's TX). This is relevant to the programming hereinafter; For Arduino DUE board, the TX end of LiDAR connects to RX1 port and the RX end of LiDAR connects to TX1 port.


Step 2: Programming

The implementation of this routine functions requires at least two serial ports: one for receiving
data from LiDAR and the other for sending data to PC for display. You can copy the following code to
IDE syntax editor or directly open corresponding attachment files.
/* This program is a parsing routine of TF02 product standard output protocol on Arduino.

The format of data package is 0x59 0x59 Dist_L Dist_H Strength_L Strength_H Sequence_L Sequence_H CheckSum_L
Refer to the product specification for detailed description.
For Arduino board with one serial port, use software to virtualize serial port's functions: such as UNO board.
*/
#include<SoftwareSerial.h>// soft serial port header file
SoftwareSerial Serial1(2,3); // define the soft serial port as Serial1, pin2 as RX, and pin3 as TX
/*For Arduino board with multiple serial ports such as DUE board, comment out the above two codes, and directly use Serial1 port*/
int dist;// LiDAR actually measured distance value
int strength;// LiDAR signal strength
int check;// check numerical value storage
int i;
int uart[9];// store data measured by LiDAR
const int HEADER=0x59;// data package frame header
void setup()
{
  Serial.begin(9600);//set the Baud rate of Arduino and computer serial port
  Serial1.begin(115200);//set the Baud rate of LiDAR and Arduino serial port
}
void loop()
{
  if (Serial1.available())//check whether the serial port has data input
  {
    if(Serial1.read()==HEADER)// determine data package frame header 0x59
    {
      uart[0]=HEADER;
      if(Serial1.read()==HEADER)//determine data package frame header 0x59
      {
        uart[1]=HEADER;
        for(i=2;i<9;i++)// store data to array
        {
          uart=Serial1.read();
        }
      check=uart[0]+uart[1]+uart[2]+uart[3]+uart[4]+uart[5]+uart[6]+uart[7];
      if(uart[8]==(check&0xff))// check the received data as per protocols
      {
        dist=uart[2]+uart[3]*256;// calculate distance value
        strength=uart[4]+uart[5]*256;// calculate signal strength value
        Serial.print("dist = ");
        Serial.print(dist);// output LiDAR tests distance value
        Serial.print('\t');
        Serial.print("strength = ");
        Serial.print(strength);// output signal strength value
        Serial.print('\n');
       }
     }
   }
 }
}
Step 3: Data View
    Upload the program to the Arduino board and open the serial monitor to check the distance value
detected by LiDAR in real time and corresponding signal strength as in Figure 3;
    Besides, you can also check the data curves on the serial curve plotter, but for that you need to
modify the code related to serial printing (Serial.print):
//         Serial.print("dist = ");
            Serial.print(dist);// output LiDAR tests distance value
            Serial.print(' ');
//         Serial.print("strength = ");
            Serial.print(strength);// output signal strength value
            Serial.print('\n');
     Re-compile and upload them to Arduino board. Open the serial curve plotter and you can see two
curves representing distance and strength as in Figure 4.

http://api.ning.com/files/R5MeEsywqmtaepxbE6dNe-hDfgtlU6CV30140z5mZSV01*AO8MA9JAepV-jBM0nyGsPfrGnAcSr-Q3BEuIJgPu-Zp1uIGdhc/2.png

http://api.ning.com/files/R5MeEsywqmvCTvCcpYlwmxHCdaXQc4uWtvlrxglVIrh2qD-OTcYM86rPqiHum1YR8WFNnedQIOt64HtmwYt0lSnFSf4*XiPf/3.png

fedeocchio



Hi everyone,

I'm interested to use Lidar sensor to improve our "Arduino Uno" bike counter, at the moment powered by a very simple PIR Sensor hc-sr501 .

As activist in Rome (Italy), my goal is to show to public officiers how our main bike lane is important (and thus reclaiming more investement to keep it cleaner and safer).

That's our website
http://reginaciclarum.it/wordpress/?page_id=2707&lang=en

and that's page dedicated our bike lane traffic counter project (sorry, only in italian)
http://reginaciclarum.it/wordpress/?page_id=288


Unfortunately, with current PIR sensor , almost 50% of real crossing (bikers, runners, .... moving along the bike lane)  are missing (not detected by the sensor), especially related to people in group.

I'm a very very beginner about Arduino, and searching "Lidar" into this  forum, I've found this post.

I?m trying to find someone helping me to migrate from PIR sensor to something better (i.e Lidar sensor).

I hope this is the right place, otherwise excuse me and please, help me to navigate into right section/post.

Thanks in advance.

Federico



Go Up