Arduino · guide
TF03 with Arduino UART: integration and configuration guide
Setup, connection, configuration and code guidance for TF03 with Arduino. The original files are available in Materials and downloads. Documented interface: UART.
Applicable setup
TF03 · Arduino · UART
Original Chinese technical instructions
TF03在Arduino上的开发例程
本例程以Arduino Uno 和 DUE板作为示例,主要帮助客户快速熟悉我公司雷达,减少产品的研发周期。
关于Arduino的详细介绍请参考以下网站:
英文官网:www.arduino.cc
步骤一:硬件连接
步骤二:程序编写
该例程功能的实现至少需要Arduino的两个串口,一个接收雷达的数据,一个用于将数据输出到电脑端显示出来。可以复制以下代码粘贴到IDE程序编辑窗口,也可直接打开相应附件文件。
/*This program is the interpretation routine of standard output protocol of TF03 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 portSoftwareSerial 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 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
Serial.print("dist = ");
Serial.print(dist); //output measure distance value of LiDAR
Serial.print('\t');
}
}
}
}
}步骤3:数据查看
将程序下载到Arduino板,打开串口监视器, 即可看到雷达实时探测的距离值,如图3:
另外也可以在串口绘图器上查看数据曲线,但是要把上述有关串口打印的代码修改一下:
//Serial.print("dist = ");
Serial.print(dist); //output measure distance value of LiDAR
Serial.print(" ");重新编译下载到Arduino板,打开串口绘图器即可看到代表distance的曲线,如图4所示:
图 4 雷达数据在串口绘图器上的图像
Use and verification
The technical content follows the readable source material. Confirm the product hardware revision, flight-stack or software version, and field safety boundary against the original material and current platform documentation.
Materials and downloads
- TF03在Arduino上的开发例程 · Chinese source (DOCX)Complete inquiry to download
