Arduino · configuration
北醒 LiDAR 接入 Arduino CAN / UART / TTL / UART · Arduino Pro Mini:接入与配置指南
北醒 LiDAR 接入 Arduino 的准备、连接、配置与代码要点。原始文件可在资料下载区获取。涉及接口:CAN、UART / TTL、UART。
适用范围
北醒 LiDAR · Arduino · CAN、UART / TTL、UART · Arduino Pro Mini
原始英文技术说明
How to connect TFmini on Arduino Pro Mini Version:v1.0
Updated date:2018.8.13
Mincy Zhao
1. Introduction
This is about how to connect Arduino Pro Mini board to a TFmini via TTL UART.
2. Materials
TFmini × 1;
Arduino Pro Mini × 1;
USB to TTL converter × 1;
DuPont wire;
PC(Windows);
Arduino IDE;
3. Connection
4. Arduino IDE
If all are connected, there is no serial port number displayed in the computer. Please check if the driver of FTDI is installed successfully.
5. Coding
Free test code can be found in the TFmini product mannual or gibhub(https://github.com/TFmini/TFmini- Arduino/tree/master/TFminiArduinoSoftwareSerial).
/*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 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 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
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
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('\n');
}
}
}
}
}6. Verify
Click the verify button and wait. If the compilation is correct, it will show “Done compling”.
7. Upload
Click the upload button and wait. Press the “Reset” button once on the Arduino Pro mini board immediately when the word "Uploading…" appears.
8. Viewing
Use Serial Monitor to view the data.
使用说明
按原始资料可读取的技术内容编排;具体的产品硬件版本、飞控/软件版本和现场安全边界仍应以原始资料及目标平台当前文档为准。
资料与下载
- How to connect TFmini on Arduino Pro Mini · 英文原文(PDF)填写信息后下载
