Communication Protocol
Communication Command Frame Format:
Header | Address | Data Length | Command | Data | Checksum |
---|---|---|---|---|---|
0x55 | 0xAA | 1 byte | 1 byte | 1 byte | Data 1~Data n |
Factory parameters:
- Serial parameters: 19200bps, 8, N, 1
- Factory address: 0x11
Commands List:
Read distance | Read temperature | Set address | Set baud rate |
---|---|---|---|
0x02 | 0x03 | 0x55 | 0x08 |
NOTE: if you are using a RS485 protocol sensor, the USB to RS485 converter is needed in the test commands listed as below.
Read the Measured Distance
The host sends a frame command to the ultrasonic sensor through the UART(RS485) interface to trigger the sensor to start detecting, and then receives the distance value command returned by the sensor.
For example, the address of the ultrasonic sensor is 0x11, the host sends: 0x55 0xAA 0x11 0x00 0x02 0x12 [ 55 AA 11 00 02 12 ]
Description:
Frame header --------- 0x55
Frame header --------- 0xAA
Device address ----- 0x11
Data length ----- 0x00
Command --------- 0x02
Checksum ------- 0x12
The ultrasonic sensor returns data as: 0x55 0xAA 0x11 0x02 0x02 0x00 0xCA 0xDE
Description:
Frame header --------- 0x55
Frame header --------- 0xAA
Local address ----- 0x11
Data length ----- 0x02
Command --------- 0x02
Distance High ----- 0x00
Distance low ----- 0xCA (Distance value 0x00CA unit is centimeter, that is, decimal 202 cm)
Checksum ------- 0xDE
Read the Measured Temperature
The host reads the current temperature measured by the ultrasonic sensor via the UART(RS485) interface.
For example, the ultrasonic sensor address is 0x11, the host sends: 0x55 0xAA 0x11 0x00 0x03 0x13 [ 55 AA 11 00 03 13 ]
Description:
Frame header --------- 0x55
Frame header --------- 0xAA
Device address ----- 0x11
Data length ----- 0x00
Command --------- 0x03
Checksum ------- 0x13
The ultrasonic sensor returns data as: 0x55 0xAA 0x11 0x02 0x03 0x00 0xFF 0x14
Description:
Frame header --------- 0x55
Frame header --------- 0xAA
Local address ----- 0x11
Data length ----- 0x02
Command --------- 0x03
Temperature high ----- 0x01
Temperature low ----- 0x13 (temperature value 0x0113, 27.5 degrees. Note: T = Returned value/10)
Checksum ------- 0x29
Set the Address of the Ultrasonic sensor
The host sets the ultrasonic sensor address via the UART(RS485) interface.
For example, set the ultrasonic sensor address 0x12, the host sends: 0x55 0xAA 0xAB 0x01 0x55 0x12 0x12 [ 55 AA AB 01 55 12 12 ]
- Note: 0xAB for the broadcast address, that is, all the common address of the sensor, you can use 0xAB instead of the device itself address if you are not sure the current Address
Description:
Frame header --------- 0x55
Frame header --------- 0xAA
Device address ----- 0xAB
Data length ----- 0x01
Command --------- 0x55
Set the address ----- 0x12 (need to set the device address 0x12)
Checksum ------- 0x12
Set the success of the ultrasonic sensor return command 0x55 0xAA 0x12 0x01 0x55 0xCC 0x33
Description:
Frame header --------- 0x55
Frame header --------- 0xAA
Device address ----- 0x12 (modified device address)
Data length ----- 0x01
Command --------- 0x55
Operation status ----- 0xCC (0xCC - operation completed 0xEE - operation failed)
Checksum ------- 0x33
Set the UART(RS485) Communication Baud Rate
The host sets the ultrasonic sensor communication baud rate via the UART(RS485) interface.
For example, if the address of the ultrasonic sensor is set to 0x11, the host sends: 0x55 0xAA 0x11 0x01 0x08 0x0B 0x24 //Set baudrate to 256000bps [ 55 AA 11 01 08 0B 24 ]
Description:
Frame header --------- 0x55
Frame header --------- 0xAA
Device address ----- 0x11
Data length ----- 0x01
Command --------- 0x08
Baud rate selection --- 0x0B
Checksum ------- 0x24
If the setting is successful, the ultrasonic sensor returns the command as: 0x55 0xAA 0x11 0x01 0x08 0xCC 0xE5
Description:
Frame header --------- 0x55
Frame header --------- 0xAA
Device address ----- 0x11
Data length ----- 0x01
Command --------- 0x08
Operation status ----- 0xCC (0xCC - operation completed 0xEE - operation failed)
Checksum ------- 0xE5
Baud rate Selection List:
1200bps | 2400bps | 4800bps | 9600bps | 14400bps | 19200bps | 28800bps | 38400bps | 57600bps | 115200bps | 128000bps | 256000bps |
---|---|---|---|---|---|---|---|---|---|---|---|
0x00 | 0x01 | 0x02 | 0x03 | 0x04 | 0x05 | 0x06 | 0x07 | 0x08 | 0x09 | 0x0A | 0x0B |
For example, when the device address is default 0x11, the baud rate setting command is as follows:
55 AA 11 01 08 00 19 //Set the baud rate 1200bps
55 AA 11 01 08 01 1A //Set the baud rate 2400bps
55 AA 11 01 08 02 1B //Set the baud rate 4800bps
55 AA 11 01 08 03 1C //Set the baud rate 9600bps
55 AA 11 01 08 04 1D //Set the baud rate 14400bps
55 AA 11 01 08 05 1E //Set the baud rate 19200bps
55 AA 11 01 08 06 1F //Set the baud rate 28800bps
55 AA 11 01 08 07 20 //Set the baud rate 38400bps
55 AA 11 01 08 08 21 //Set the baud rate 57600bps
55 AA 11 01 08 09 22 //Set the baud rate 115200bps
55 AA 11 01 08 0A 23 //Set the baud rate 128000bps
55 AA 11 01 08 0B 24 //Set the baud rate 256000bps