μSharp Patch Data Format -- UART
The standard UART protocol is used for our serial transmission interface. The protocol can be modified based on your specific requirement. Contact us to request a change in protocol or other requirements you may have with your system.
Communication Protocol
The communication protocol is:
- Standard UART
- Baud rate is 115200 b/s
- Data length is 8 bits, plus one start bit and one stop bit, and no parity bit
- I/O standard is 3.3V LVTTL

user interface on μSharp Patch for UART
Data Format for Serial Transmission Interface
The packet of output data consists of 6 Bytes. The byte structure is explained below. Note that an 'x' refers to a variable bit containing dynamic data.
Byte 1 | 0xFE | Packet Header |
Byte 2 | 0x01 | Version ID |
Byte 3 | 0bxxxxxxxx | Distance (Least Significant 8 Bits) |
Byte 4 | 0bxxxxxxxx | Distance (Most Significant 8 Bits) |
Byte 5 | 0bxxxxxxxx | SNR (signal to noise ratio) |
Byte 6 | 0bxxxxxxxx | Checksum (formula below) |
Explanation
Distance
The distance bytes can be combined (totally 16 bits) to represent the distance information in centimeters. The structure would be: 0x[MSB][LSB], where MSB and LSB are each two hexadecminal numbers (8 bits).
Note: When distance returns 0, it to mean 'no target detected' or 'infinity'.
SNR
The altitude reading will be associated with SNR ( range from 0 to 60 ) to indicate the quality of the reflections.
Checksum
The Checksum Byte could be used in the following check code:
if (Version_ID + Distance_H + Distance_L + SNR) & 0xFF == checksum
is_valid = 1 (check passed)
else
is_valid = 0 (failed)
Example Python 2.7 Code for receiving/showing data on PC
Note: Please download necessary Python package before running this example script.
from serial import Serial
import struct
import matplotlib.pyplot as plt
serial = Serial('COM7', 115200,8, 'N',1) ### This serial port may be various on different machines
serial.flushInput()
serial.flushOutput()
while(1):
byte = struct.unpack('B', serial.read(1))[0]
if(byte == 0xFE):
byte2 = struct.unpack('B', serial.read(1))[0]
byte3 = struct.unpack('B', serial.read(1))[0]
byte4 = struct.unpack('B', serial.read(1))[0]
byte5 = struct.unpack('B', serial.read(1))[0]
byte6 = struct.unpack('B', serial.read(1))[0]
header = byte
version_id = byte2
lsb_byte = byte3
msb_byte = byte4
snr = byte5
check_sum_transmitter = byte6
check_sum_receiver = (byte2 + byte3 + byte4 + byte5) & 0xFF
DISTANCE = byte3 + (byte4<<8)
### Print received data
if (check_sum_receiver == check_sum_transmitter):
print "checksum passed, DISTANCE: " + str(DISTANCE) + ", SNR:" + str(snr) + '\r\n'
else:
print "checksum failed!!!" + '\r\n'
else:
continue
Example Arduino Code for receiving/showing data on PC
Note: Please install Arduino IDE before running this example script.
// This function is called only once, at reset.
void setup() {
Serial.begin(115200);
Serial.println("uSharp Patch Readout");
}
// This function is called continuously, after setup() completes.
void loop() {
int altitude = 0;
int data[64];
int data_packet[6];
int idx;
int receiver_checksum;
int SNR;
/// Buffer size = default 64 Bytes, this depends on Arduino board setting!
while (Serial.available() == 63) {
delay(20);
for(int i=0;i<64;i++){
data[i]=Serial.read();
}
for (int j=0;j<12;j++){
if (data[10+j] == 0xFE && data[10+j+1] == 0x01){
idx = j;
break;
}
}
data_packet[0] = data[10+idx];
data_packet[1] = data[11+idx];
data_packet[2] = data[12+idx];
data_packet[3] = data[13+idx];
data_packet[4] = data[14+idx];
data_packet[5] = data[15+idx];
altitude = data_packet[2] + (data_packet[3] << 8);
SNR = data_packet[4];
receiver_checksum = (data_packet[1] + data_packet[2] + data_packet[3] + data_packet[4]) & 0xff;
/// Print received data
if (receiver_checksum == data_packet[5]){
Serial.print("Checksum passed, ALTITUDE: ");
Serial.print (altitude);
Serial.print(", SNR: ");
Serial.print (SNR);
Serial.print("\n\r");
}else{
Serial.print ("Checksum failed!!!");
Serial.print("\n\r");
}
}
}
Updated almost 6 years ago