User Manual

SJ-PM-TFmini-T-01 A03
Benewake (Beijing) Co. Ltd.
Page25
Step 2: Program Compilation
At least two serial ports of Arduino are required for achievement of this routine function with one for
receiving data of LiDAR and the other for outputting data to PC for display. The user may either copy
following code and paste it in the IDE program editing window or directly open relevant enclosed file.
/* this program is the interpretation routine of standard output protocol of TFmini product on Arduino.
For details, refer to Product Specifications.
For Arduino boards with only one serial port like UNO board, the function of software visual serial port is
to be used.
*/
#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 and pin3
as TX
/* 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 strength;//signal strength 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
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
}
void loop()
{
if (Serial1.available())//check if serial port has data input
{
if(Serial1.read()==HEADER)//assess data package frame header 0x59