0% found this document useful (0 votes)
6 views

Arduino 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Arduino 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

北醒 http://en.benewake.com/support_article/detail/5e031...

Home > Technical Support > Short-range Distance Sensor TFmini Plus > TFmini Plus_Arduino(1)

TFmini Plus_Arduino(1)
This application takes Uno board of Arduino as an example, reading response data from LIDAR, processing and printing measurement data through Arduino, which helps customers to quickly familiarize
themselves with our company's product and reduce development cycle.

Step 1: Hardware connection

Fig.1 Wiring of TFmini Plus and UNO board

Fig.2 Wiring of TFmini Plus and DUE board


Step 2: Programming
The implementation of this example requires at least two serial ports of Arduino, one is for receiving lidar data and the other is for displaying data to the
computer. The following code can be copied and pasted into the IDE command window.
/*
This program is the interpretation routine of standard output protocol of TFmini-Plus 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
float temprature;
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
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
strength = uart[4] + uart[5] * 256; //calculate signal strength value
temprature = uart[6] + uart[7] *256;//calculate chip temprature
temprature = temprature/8 - 256;
Serial.print("dist = ");
Serial.print(dist); //output measure distance value of LiDAR
Serial.print('\t');
Serial.print("strength = ");
Serial.print(strength); //output signal strength value
Serial.print("\t Chip Temprature = ");
Serial.print(temprature);
Serial.println(" celcius degree"); //output chip temperature of Lidar
}
}
}

1 de 3 22/2/23, 23:22
北醒 http://en.benewake.com/support_article/detail/5e031...

}
}
STEP3:Data review
Upload the sketch to the Arduino board, then open the serial monitor, It can display the measured distance and reflected strength, as shown in figure 3.

Figure 3 display the lidar data on serial monitor


In addition, you can also view the data curve on the serial port plotter, but you should modify the above code for serial port printing:
//Serial.print("dist = ");
Serial.print(dist); //output measure distance value of LiDAR
Serial.print(" ");
//Serial.print("strength = ");
Serial.print(strength); //output signal strength value
//Serial.print("\t Chip Temprature = ");
Serial.print(" ");
Serial.print(temprature);
Serial.println();
//Serial.println(" celcius degree");
Recompile and download to the Arduino board, open the serial port plotter to see the three curves representing distance, strength and temperature, as shown in
Figure 4:

图 4 雷达数据在串⼝绘图器上的图像

Prev:TFmini Plus_Arduino(2) Next:Application of TFmini Plus in open source flight control pixhawk

2 de 3 22/2/23, 23:22
北醒 http://en.benewake.com/support_article/detail/5e031...

Support Email

+86-10-57456983

PRODUCTS

APPLICATIONS

NEWS

ABOUT US

CONTACT US

  
Copyright © 2017 Benewake (Beijing) Co., Ltd. All Rights Reserved. Privacy Policy

3 de 3 22/2/23, 23:22

You might also like