Benewake TF-LC02

Benewake TF-LC02 Lidar Ranging Module DC 3-3.6V TTL for Arduino 

Specification:
Measuring range: 3cm~200cm @ 90% reflectivity
Detection speed: 33msec
Accuracy:土2cm @ (3cm~100cm); ±5% @ (100~200cm)
Storage temperature: -20~85°C
Working temperature: -20~70°C
Size: 20mm* 11.5mm*7.6mm

Light source: VCSEL
Supply voltage: 3~3.6V
Center wavelength: 940nm
Average current: ≤15mA
Eye safety: Class1 (IEC60825- 1:2400)
Power consumption: ≤50mW
Field of view: ±9° (9° on the left and right of the optical central axis; 18° in total)
Communication level: LVTTL (3.3V)

Connector: 1.0mm 6P
Cable Length: 10cm(including connector)

Pinout:

Connection with Arduino UNO:

Arduino code:

#include <SoftwareSerial.h> //软串口头文件

SoftwareSerial Port_Debug(2, 3); //定义软件口名称和PIN2为RX PIN3为TX

u8 cmd[5] = {0x55, 0xAA, 0x81, 0x00, 0xFA}; //获取距离指令

typedef struct {
int distance;
u8 ErrorCode; //TOF错误码请参考使用说明书
boolean receiveComplete;
} TF;
TF Lidar = {0,0,false};

/***************************************
* 通讯协议:
* 2 byte : 帧头 0x55 0xAA
* 1 byte : 功能码 (详细参考使用说明) 例:0x81 获取距离值 单位:mm
* 1 byte : 后面参数的长度
* N byte : 设定参数
* 1 byte : 帧尾 0xFA
* ***************************************
* 例:获取距离值
* Arduino 发送:55 AA 81 00 FA
* TOF模组回复 : 55 AA 81 03 01 55 00 FA
**************************************/
void getLidarData(TF* lidar) {
static char i = 0;
static int rx[8];
if (Serial.available())
{
rx[i] = Serial.read();
if (rx[0] != 0x55)
{
i = 0;
} else if (i == 1 && rx[1] != 0xAA)
{
i = 0;
} else if (i == 7)
{
i = 0;
if (rx[7] == 0xFA)
{
lidar->distance = rx[5] + rx[4] * 256;
lidar->ErrorCode = rx[6];
lidar->receiveComplete = true;
}
} else
{
i++;
}
}
}

void setup() {
/********************************
* TOF串口协议:TTL
* 波特率:115200
* 数据位:8
* 停止位:1
* 奇偶校验:无
* 流控:无
**************************************/
Serial.begin(115200); //通过硬件串口来获取实时性要求比较高的雷达数据,软串口容易出现掉帧的情况
Port_Debug.begin(115200);
}

void loop() {
if (!Lidar.receiveComplete)
{
Serial.write(cmd, 5);
} else
{
//Port_Print_Ascii(&Lidar); // Ascii 打印输出结果
Port_Print_Benewake_9Byte(&Lidar); // 北醒通用9Byte打印
Lidar.receiveComplete = false;
delay(33); //延时33ms,雷达探测速率最快33ms
}
}
void Port_Print_Ascii(TF* lidar)
{
Port_Debug.print(“Dist = “);
Port_Debug.println(lidar->distance);
if(lidar->ErrorCode)
{
Port_Debug.print(“ErrorCode = “);
Port_Debug.println(lidar->ErrorCode,HEX);
}
}

void Port_Print_Benewake_9Byte(TF* lidar)
{
u8 i = 0;
u8 CheckSum = 0;
u8 B_9Byte[9];
B_9Byte[0] = 0x59;
B_9Byte[1] = 0x59;
B_9Byte[2] = lidar->distance & 0xFF;
B_9Byte[3] = lidar->distance >> 8;
B_9Byte[4] = 0x00;
B_9Byte[5] = 0x00;
B_9Byte[6] = 0x00;
B_9Byte[7] = 0x00;
for(i=0;i<7;i++){
CheckSum += B_9Byte[i];
}
B_9Byte[8] = CheckSum & 0xFF;
Port_Debug.write(B_9Byte,9);
}

void serialEvent() {
getLidarData(&Lidar);
}

Result:

 

Reference link:
https://blog.csdn.net/zoran_wu/article/details/122127153

BW_TFDS V1.4.0 Download link: 
http://surl.li/bbpqo

Arduino code link:
http://surl.li/bbpqx

Leave a Reply

Your email address will not be published. Required fields are marked *