此文档介绍了北醒系列激光雷达在ESP32 DEVKIT_V1开发板上的运用,其中包含了
此文档的编译代码可以在Github上下载:
待添加
环境搭建:关于ESP32 DEVKIT_V1板子资料及环境搭建可以参考
参考:【vsCode + Arduino】在Visual Studio Code编译Arduino项目
步骤一: 使用vsCode打开Arduino建好的ino,项目文件,选择对应的开发板DOIT DEVKIT_V1
步骤二: 选择对应的编译器
步骤三: 选择对应COM口并编译,如果COM口正常(以下COM口处理略过)
如果没有COM口,请确认板子是否已经正常连接,对应驱动是否已经正常安装,此处可以参考
关于ESP32 DEVKIT_V1板子资料及环境搭建可以参考
步骤四: 此处一般会出现一个编译警告,如下图,通过更改json来避免此警告,并加速编译(此处参考待添加)
添加一句"output": “./Arduino/build”,如下所示
步骤五: 编译后进行烧录
烧录方式:先按住BOOT键点烧录,待出现正在上传时可以放开并开始烧录
步骤六: 测试
此处手动打开串口监控器,开始打印雷达数据
参考:【vsCode + PlatformIO】在Visual Studio Code编译Arduino项目
// Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
#define RXD2 16
#define TXD2 17
int dist; /*----actual distance measurements of LiDAR---*/
int strength; /*----signal strength of LiDAR----------------*/
float temprature;
unsigned char check; /*----save check value------------------------*/
int i;
unsigned char uart[9]; /*----save data measured by LiDAR-------------*/
const int HEADER = 0x59; /*----frame header of data package------------*/
int rec_debug_state = 0x01; // receive state for frame
void Get_Lidar_data();
void setup()
{delay(2000);Serial.begin(115200);Serial.println("nBenewake TFmini-S UART LiDAR Program");Serial2.begin(115200);
}
void loop()
{Get_Lidar_data();
}
void Get_Lidar_data()
{if (Serial2.available()) // check if serial port has data input{if (rec_debug_state == 0x01){ // the first byteuart[0] = ad();if (uart[0] == 0x59){check = uart[0];rec_debug_state = 0x02;}}else if (rec_debug_state == 0x02){ // the second byteuart[1] = ad();if (uart[1] == 0x59){check += uart[1];rec_debug_state = 0x03;}else{rec_debug_state = 0x01;}}else if (rec_debug_state == 0x03){uart[2] = ad();check += uart[2];rec_debug_state = 0x04;}else if (rec_debug_state == 0x04){uart[3] = ad();check += uart[3];rec_debug_state = 0x05;}else if (rec_debug_state == 0x05){uart[4] = ad();check += uart[4];rec_debug_state = 0x06;}else if (rec_debug_state == 0x06){uart[5] = ad();check += uart[5];rec_debug_state = 0x07;}else if (rec_debug_state == 0x07){uart[6] = ad();check += uart[6];rec_debug_state = 0x08;}else if (rec_debug_state == 0x08){uart[7] = ad();check += uart[7];rec_debug_state = 0x09;}else if (rec_debug_state == 0x09){uart[8] = ad();if (uart[8] == check){dist = uart[2] + uart[3] * 256; // the distancestrength = uart[4] + uart[5] * 256; // the strengthtemprature = uart[6] + uart[7] * 256; // calculate chip tempraturetemprature = temprature / 8 - 256;Serial.print("dist = ");Serial.print(dist); // output measure distance value of LiDARSerial.print('n');Serial.print("strength = ");Serial.print(strength); // output signal strength valueSerial.print('n');Serial.print("t Chip Temprature = ");Serial.print(temprature);Serial.println(" celcius degree"); // output chip temperature of Lidarwhile (Serial2.available()){ad(); // This part is added becuase some previous packets are there in the buffer so to clear serial buffer and get fresh data.}delay(100);}rec_debug_state = 0x01;}}
}
本文发布于:2024-02-13 18:48:28,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/1715735664254779.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |