Introduction
This is a TOF-based single-point laser ranging sensor for outdoor use. It has 100K LUX resistance to strong ambient light, which means there will be no problems at all when using it on sunny days.
With a detection range of 5cm to 15m, the product features distance resolution 1mm, 50Hz data update frequency, 1~2° FOV and supports UART, IIC and I/O multiple communication modes(support active and query output data in UART mode).
Small in size, there are standard screw holes reserved on the side and bottom of the module, which is convenient for installation in various places. It can be widely used in the fields of drone height setting, route planning, smart car competition and transportation, industrial automation, high-speed measurement and safety monitoring, etc.
NOTE: When exceeding the measurement range of 15m, the error is larger in the range of 15m to about 20m. And the sensor outputs 0 when detecting an object out of 20m.
Specification
- Measuring Range: 5cm~15m
- Measurement Resolution: 1mm
- Ranging Accuracy: [0. 05m, 2m]±2cm, std<0. 5cm; (2m, 15m]±2%, std<8cm
- Field of View (FOV): 1~2°
- Output Mode: UART, I2C, I/O (support active and query output in UART mode)
- Refresh Rate: 50Hz
- I2C Default Slave Address: 0x08
- Wavelength: 750~830nm
- Anti-Ambient Light: 100K Lux
- Power Supply Voltage: 3.7~5.2V, reverse connection protection
- Power Consumption: 610mW
- Working Temperature: -10~60℃
- Size: 22.7×28×13.6mm / 0.89×1.10×0.54 inch
- Weight: 7.7g
Board Overview
For using UART
Num | Label | Description |
---|---|---|
1 | vcc | Power supply + |
2 | GND | Power supply + |
3 | RX | UART receiving data line |
4 | TX | UART transmitting data line |
For using I2C
Num | Label | Description |
---|---|---|
1 | vcc | Power supply + |
2 | GND | Power supply + |
3 | IIC_SDA | I2C data line |
4 | IIC_SCL | I2C data line |
For using I/O
Num | Label | Description |
---|---|---|
1 | vcc | Power supply + |
2 | GND | Power supply + |
3 | I/O_H | Output High |
4 | I/O_L | Output Low |
Module Instruction
Principle of Use
TOF is an absolute distance detection technology, that is, the sensor emits the near-infrared light to be debugged, and it will reflect when encountering an object. The sensor calculates the distance of the captured scene by calculating the time difference or phase difference between light emission and reflection to generate depth information. Compared with the binocular scheme and the 3D structured light scheme, TOF has the advantages of long working distance, wide range of application scenarios, and high accuracy at long distances. Therefore, it is often used in personnel approach detection, robot obstacle avoidance, camera autofocus and other occasions.
Overview
The module can meet the needs of various scenarios. It can output distance measurement value (dis), distance status (dis_status), signal strength (signal_strength), ranging precision (range_precision) and other information.
- Output mode: In UART mode, it supports active output and query output. In IIC mode, the host sends a read parameter frame to read slave data. Active output means that the module sends measurement data frames independently and continuously, and the sending frequency is 50Hz; query output means that the module will output one measurement data frame every time it receives one query frame.
- Connection method: UART, IIC and I/O output methods are supported, and the three output methods share a set of physical interfaces. Among them, UART output supports active output and query output of one single module; IIC mode supports reading and writing parameters of a single module. In I/O output mode, the ranging value cannot be output, but the complementary level can be output.
Interface and Baud Rate
The module supports configuration as UART, IIC, I/O communication mode, the factory default is UART communication. If you need to use other communication modes, you can configure it through the module host computer.
Host download:
64bitnassistant_windows_64bit.zip
32bitnassistant_windows_32bit.zip
- Serial driver: CP210x_Windows_Drivers_v6.7.6.zip
UART
Under serial communication, the baud rate setting range is as follows.
UART_Baudrate | Note |
---|---|
115200,230400,460800,921600,1000000,1200000, 1500000,2000000,3000000 | Default Baud Rate 921600 |
I2C
In IIC output mode, the baud rate setting range is shown in the table below.
IIC_Baudrate | Note |
---|---|
Up to 400K | The maximum baud rate is 400Kbps, determined by the host. |
The IIC slave address of the current module. The setting range is as follows:
IIC_Address | Note |
---|---|
0x08~0x77 | The default address is 0x08 (7-bit address), and the slave address is 0x08+module ID. The slave address can be changed by changing the ID parameter of the module. The ID setting range is 0~111. Pay attention to shifting and increasing the read and write bits when communicating, that is, when the address is 0x08, the bytes with read and write bits sent are 0x10 (write), 0x11 (read) |
Distance Status
The module can output the current distance status, and the user can process data in combination with the distance status. The specific meaning is shown in the following table.
Value | Note |
---|---|
0 | Valid distance measurement |
1 | Invalid measurement |
Signal Strength
Indicates the strength of the current return signal, the larger the value, the stronger the return signal.
Range Precision
Indicates the accuracy of the current ranging, the smaller the value, the better the ranging accuracy.
FOV
The size of the FOV determines the field of view of the module, and the field of view of the module is 1~2°.
Mode Switch
If the module is in UART mode, you can connect NAssistant software to switch to IIC or I/O mode. If the module is in IIC mode, it needs to send a command to the module through IIC communication to switch back to UART mode. In addition, you can switch back to UART mode in the following ways when there is no IIC test environment or after switching to I/O mode:
You need to prepare a USB to TTL module that supports 921600 baud rate (CP2102 is recommended) and install the corresponding driver. Connect the TX, RX, and GND lines of the USB to TTL module to the corresponding pins of the TOF module, and leave the VCC pin temporarily unconnected. Then insert the USB to TTL module into the computer, open our host computer software, click icon to enter the serial port debugging assistant, change the baud rate to 921600, select the COM port corresponding to the USB to TTL module, then click the connect button to connect the COM port (it will connect automatically in most cases). Enter 54 20 00 ff 00 ff ff ff ff 00 ff ff 00 10 0e ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 7b in the Single Send text box. Change the sending interval to 20ms in the timing sending column in the lower right corner, then check the timing transmission , at this time connect the 5V of the USB to TTL module to the VCC pin of the TOF module, the module will switch to UART mode and start outputting data. At this point, unplug the USB to TTL module, power on the module again, and click the identification button on the main page to identify the module. If the switch fails or the output data is abnormal, you can repeat the whole step.
Module Protocol Analysis
Example
The below takes single-module continuous ranging as an example.
UART Active Output Mode
The protocol consists of Frame Header, Function Mark, Data, and Sum Check. Among them, Frame Header and Function Mark are fixed values; Data is the transmitted data content, and Sum Check is the lowest byte after adding Frame Header, Function Mark, and Data (that is, adding all the preceding bytes). Protocol composition: Frame Header + Function Mark + Data + Sum Check
Original data: 57 00 ff 00 9e 8f 00 00 ad 08 00 00 03 00 ff 3a
The command format is as follows:
Data | Type | Length(Bytes) | Hex | Results |
---|---|---|---|---|
Frame Header | uint8 | 1 | 57 | 0x57 |
Function Mark | uint8 | 1 | 00 | 0x00 |
reserved | uint8 | 1 | ... | * |
id | uint8 | 1 | 00 | 0 |
System_time | uint32 | 4 | 9c 8f 00 00 | 36766ms |
dis*1000 | uint24 | 3 | ad 08 00 | 2.221m |
dis_status | uint8 | 1 | 00 | 0 |
signal_strength | uint16 | 2 | 03 00 | 3 |
range_precision | uint8 | 1 | 06 | 6cm |
Sum Check | uint8 | 1 | 41 | 0x41 |
Special, for the int24 type, we need to convert it to int32 type first. To maintain the sign, we use the left shift operation followed by division by 256. For example, for position data represented in int24, with a multiplier of 1000.
uint8_t byte[] = {0xe6,0x0e,0x00};//代表十进制数值:3.814
//uint8_t byte[] = {0xec,0xfb,0xff};//代表十进制数值:-1.044
int32_t temp = (int32_t)(byte[0] << 8 | byte[1] << 16 | byte[2] << 24) / 256;
float result = temp/1000.0f
UART Query Output Mode
Original data: 57 10 FF FF 00 FF FF 63
The command format is as follows:
Data | Type | Length(Bytes) | Hex | Results |
---|---|---|---|---|
Frame Header | uint8 | 1 | 57 | 0x57 |
Function Mark | uint8 | 1 | 10 | 0x10 |
reserved | uint16 | 2 | ... | * |
id | uint8 | 1 | 00 | 0 |
reserved | uint16 | 2 | ... | * |
Sum Check | uint8 | 1 | 63 | 0x63 |
I2C Communication Mode
Slave address: The module works as a slave in the IIC bus, the default address is 0x08 (7-bit address), and the slave address is 0x08+module ID. You can change the slave address by changing the ID parameter of the module. When communicating, pay attention to address shifting and adding read and write bits, that is, when the address is 0x08, the bytes with read and write bits are 0x10 (write) and 0x11 (read).
Register address: If there is no corresponding parameter in the register, the default output is 0xff. Refer to the table below.
I2C Communication Process:
Single data write
Single data read
Multiple data write
Start: start signal
W: Write flag bit 1
R: Read flag bit 0
ACK: Acknowledgment
NACK: Non-acknowledgment
Stop: Stop signal
Tutorial
Requirements
- Hardware
- Arduino Mega Due (or similar) x 1
- ToF Outdoor Laser Ranging Module(15m) x1
- Wires
- Software
Debug on Arduino(PC Serial)
Given that the module is a serial device and a regular Arduino board only has one hardware serial port, it is recommended to use Arduino boards with multiple serial ports, such as Arduino Leonardo or Arduino Mega2560. In this case, we will use Arduino Mega2560 as the controller and Serial1 for serial communication. If you are using an Arduino Uno, it is not recommended to use software serial. Instead, use the hardware serial port. When downloading the program, make sure to disconnect the device first. After the program is successfully downloaded, reconnect the device and you can view the data in the Serial Monitor.
Connection Diagram
Use the serial port software on the PC end to display the detected distance and power the entire system.
Arduino Debug Code
A PC serial port tool is required, the read data will be displayed on the serial port tool interface.
#define TOF_FRAME_HEADER 0x57 //Define the frame header for the TOFSense series and TOFSense-F series
#define TOF_FUNCTION_MARK 0x00 //Define the function codes for the TOFSense series and TOFSense-F series
typedef struct {
unsigned char id; //TOF id
unsigned long system_time; //msPower-on time, unit: ms
float dis; //Output distance, unit: meters
unsigned char dis_status; //Distance status indication of the output
unsigned int signal_strength; //Signal strength of the output
unsigned char range_precision; //cmReference value for the repeating ranging accuracy of the output, unit: cm
} tof_parameter;
unsigned int count_i,count_j=0;
tof_parameter tof0;
unsigned char check_sum=0;
unsigned char rx_buf[32];
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial1.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial1.available()>0)
{
if(Serial1.peek() == TOF_FRAME_HEADER)
{
count_i=0;
rx_buf[count_i]=Serial1.read();
}
else
{
rx_buf[count_i]=Serial1.read();
}
count_i++;
if(count_i>15)
{
count_i=0;
for(count_j=0;count_j<15;count_j++)
{
check_sum+=rx_buf[count_j];
}
if((rx_buf[0] == TOF_FRAME_HEADER)&&(rx_buf[1] == TOF_FUNCTION_MARK)&&(check_sum == rx_buf[15]))
{
tof0.id=rx_buf[3];
tof0.system_time=(unsigned long)(((unsigned long)rx_buf[7])<<24|((unsigned long)rx_buf[6])<<16|((unsigned long)rx_buf[5])<<8|(unsigned long)rx_buf[4]);
tof0.dis=((float)(((long)(((unsigned long)rx_buf[10]<<24)|((unsigned long)rx_buf[9]<<16)|((unsigned long)rx_buf[8]<<8)))/256))/1000.0;
tof0.dis_status=rx_buf[11];
tof0.signal_strength=(unsigned int)(((unsigned int)rx_buf[13]<<8)|(unsigned int)rx_buf[12]);
tof0.range_precision=rx_buf[14];
Serial.print("id:");
Serial.println(tof0.id);
Serial.print("system_time:");
Serial.println(tof0.system_time);
Serial.print("dis:");
Serial.println(tof0.dis);
Serial.print("dis_status:");
Serial.println(tof0.dis_status);
Serial.print("signal_strength:");
Serial.println(tof0.signal_strength);
Serial.print("range_precision:");
Serial.println(tof0.range_precision);
Serial.println("");
}
}
check_sum=0;
}
}
Expected Results
The serial port software displays the data format as follows.
FAQ
For any questions, advice or cool ideas to share, please visit the DFRobot Forum.