PB00003 DFRobot_UART_protocol_V1.0 - jimaobian/DFRobotWiki GitHub Wiki

DFRobot ultrasonic module UART communication protocol

Support a Master and multi-Slaves communication, the Master commands and Slave answers. Master needs not address but each Slave has a 1-byte address. 0xAB is broadcast address, using the address, all cascaded slaves will answer.

Communication Command Frame

  • Command format:
align = "center" colspan = 2 Header align = "center" Destination Address align = "center" Data Length align = "center" Command Word align = "center" Data align = "center" Checksum
align = "center" 0x55 align = "center" 0xAA align = "center" 1 Byte align = "center" 1 Byte align = "center" 1 Byte align = "center" 0~n Byte
  • Answer format : with the command in the same format; where " destination address " to " source address", " command word " is sent back to fill in the Master command word .

Command word definitions

align = "center" Command Word align = "center" Function align = "center" Command -data length(Bytes) align = "center" Command -data align = "center" Answer -data length(Bytes) align = "center" Answer -data
align = "center" 0x02 align = "left" get measuring distance align = "left" 0 align = "left" null align = "left" 2 align = "left" distance value; the previous high, in mm
align = "center" 0x03 align = "center" get temperature align = "left" 0 align = "left" null align = "left" 2 align = "left" tenfold temperature; high front and signed, units of degrees Celsius; actual temperature value = tenfold temperature / 10
align = "center" 0x04 align = "center" set measuring distance limit align = "left" 2 align = "left" distance value; the previous high , in mm align = "left" 1 align = "left" 0xCC = operation success, 0xEE = operation failed
align = "center" 0x05 align = "center" get measuring distance limit align = "left" 0 align = "left" null align = "left" 2 align = "left" distance value, the previous high , in mm
align = "center" 0x08 align = "center" set baud rate align = "left" 1 align = "left" baud identifier, see Note (1) align = "left" 1 align = "left" 0xCC = operation success, 0xEE = operation failed
align = "center" 0x55 align = "center" set Slave address align = "left" 1 align = "left" address align = "left" 1 align = "left" 0xCC = operation success, 0xEE = operation failed

Note (1) : baud identifier description:

0x00: baud rate of 1200 bps

0x01: baud rate of 2400 bps

0x02: baud rate of 4800 bps

0x03: baud rate of 9600 bps

0x04: baud rate of 14400 bps

0x05: baud rate of 19200 bps

0x06: baud rate of 28800 bps

0x07: baud rate of 38400 bps

0x08: baud rate of 57600 bps

0x09: 115200 bps baud rate

0x0A: baud rate 128000 bps

0x0B: baud rate 256000 bps

Examples of Use

Get the measurement ranging

The Master sends command to an ultrasonic module via UART interface, trigger the module start ranging, and then return the distance value.

Such as ultrasound module address is 0x11, and then the Master sends:

Header --------- 0x55  Header --------- 0xAA Destination Address ----- 0x11 Data Length ----- 0x00 Command Word --- 0x02 Checksum ------- 0x12 

Ultrasonic Module answer is : 0x55 0xAA 0x11 0x02 0x02 0x12 0x34 0x5A

Where the data: 0x12 as high byte of distance, 0x34 low byte

Distance value 0x1234, in millimeters, which is decimal 4660 mm .

Get the temperature

Master reads the current temperature measured from ultrasonic module.

Such as ultrasound module address is 0x11, and then the host sends:

Header --------- 0x55  Header --------- 0xAA Destination Address ----- 0x11 Data Length ----- 0x00 Command Word ----- 0x03 Checksum ------- 0x13

Ultrasonic Module answer is: 0x55 0xAA 0x11 0x02 0x03 0x00 0xFF 0x14

Where the data: 0x00 is high byte of temperature , 0xFF is low byte

That temperature is 0x00FF(decimal 255), which means that 25.5 degrees Celsius.

Set ultrasonic module address

Master sets ultrasonic module address.

Such as setting ultrasonic module address is 0x11, then the host sends:

Header --------- 0x55 Header --------- 0xAA Destination Address ----- 0xAB (broadcast address, you can use the original address) Data Length ----- 0x01 Command Word --------- 0x55 Data ----- 0x11 Checksum ------- 0x11 

Set successful answer from the ultrasonic module: 0x55 0xAA 0x11 0x01 0x55 0xCC 0x32

Return Data: 0xCC - Successful Operation

Slave address setting is successful; the module will use its new address to the host answer.

Ultrasonic module baud rate set

Master sets baud rate of ultrasonic module.

Such as ultrasound module address is 0x11, set the baud rate of 2400, the host sends:

Header --------- 0x55 Header --------- 0xAA Destination Address ----- 0x11 Data Length ----- 0x01 Command Word --------- 0x08 Data --- 0x05 Checksum ------- 0x1E

Set successful answer from the ultrasonic module: 0x55 0xAA 0x11 0x01 0x08 0xCC 0xE4

Return Data: 0xCC - Successful Operation

Set measuring distance limit of ultrasonic module

You can set the measuring distance limit according to the application of ultrasonic module. While reducing the measuring distance limit, it can improve data output refresh rate from module.

Such as ultrasound module address is 0x11, to set the measuring distance limit 3840 (0x0F00) mm , the Master sends:

Header --------- 0x55 Header --------- 0xAA Destination Address ----- 0x11 Data Length ----- 0x02 Command Word--------- 0x04 Data(High Byte) ------- 0x0F Data(Low Byte) ------- 0x00 Checksum ------- 0x25 

Set successful answer from the ultrasonic module: 0x55 0xAA 0x11 0x00 0x04 0xCC 0xE0

Return Data: 0xCC - Successful Operation

Get ultrasonic measuring distance limit

Such as ultrasound module address is 0x11, the Master sends:

Header --------- 0x55 Header --------- 0xAA Destination Address ----- 0x11 Data length ----- 0x00 Command Word--------- 0x05 Checksum------- 0x15

Ultrasonic Module answer is: 0x55 0xAA 0x11 0x02 0x05 0x0F 0x00 0x26

Return Data: 0x0F00, which is decimal 3840 mm .

Communication protocol library

Arduino library link: DFRobot_URM library and samples.