-
Notifications
You must be signed in to change notification settings - Fork 0
Serial Protocol
The serial protocol defines the communication between the Arduino and the Android App. The serial communication is eigther a Bluetooth or USB connection. Transmitted are arrays of bytes with the following format:
Start | Version+Length | DataBlock | Check |
---|---|---|---|
0x80 | 0x2n | n bytes of data | 1 check byte |
The following format of bits is used:
Bit Value | Description |
---|---|
1 | always 1 |
0 | always 0 |
r | reserved, sender should write 0 and receiver should not use it |
s,v,l,d,c,p | value of the field |
The Start byte is byte 0x80, or -128 in decimal. All the other bytes must not be 0x80, or a new Start of Frame is detected.
Bit | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
---|---|---|---|---|---|---|---|---|
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
The fist nibble of this byte is the version field, the second the length field. There are version numbers 0-7 supported by this protocol. The version field spans from b6:b4. The actual Version is 2. The length field contains the number of DataBytes. There are 0-15 DataBytes possible. The length field spans from b3:b0. The current length of DataBlock to the Arduino is 3, to the Android App 8.
Bit | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
---|---|---|---|---|---|---|---|---|
0 | v2 | v1 | v0 | l3 | l2 | l1 | l0 |
There are Length n bytes of data in a frame. The sender needs to make sure a data byte does not contain a Start byte 0x80.
Bit | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
---|---|---|---|---|---|---|---|---|
d7 | d6 | d5 | d4 | d3 | d2 | d1 | d0 |
The check byte is calculated by the sender and checked by a receiver. To get the value of the check byte every byte sent in this frame is xored. Bit 7 is the even parity of bits b6 to b0 of the check value.
- c6:0 = Start XOR Value+Length XOR Data1 XOR ... XOR DataN
- p7 = even parity of Check c6:c0
Bit | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
---|---|---|---|---|---|---|---|---|
p7 | c6 | c5 | c3 | c3 | c2 | c1 | c0 |
Format of the Datablock in bytes:
speed | steer | status |
---|
The length of the DataBlock is 3 bytes. The length of the message is 6 bytes.
DataBlock | range | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
---|---|---|---|---|---|---|---|---|---|
speed | -127:127 | d7 = sign | d6 | d5 | d4 | d3 | d2 | d1 | d0 |
steer | -127:127 | d7 = sign | d6 | d5 | d4 | d3 | d2 | d1 | d0 |
status | 1: on; 0 off | 0 | r6 | d5 | d4 | r3 | r2 | d1 | d0 |
values are in the following range from the maximum speed:
max backwards | backwards | stop | forward | max forwards | forbidden |
---|---|---|---|---|---|
-127 | -127:-1 | 0 | 1:127 | 127 | -128 |
values are in the following range from the maximum steer angle:
max left | left | straight | right | max right | forbidden |
---|---|---|---|---|---|
-127 | -127:-1 | 0 | 1:127 | 127 | -128 |
the following status bits are used:
# | name | value | description |
---|---|---|---|
b7 | 0 | always 0 | |
r6 | r | reserved | |
d5 | failsafeStop | 1 | carduinodroid stops after it does not receive serial frames |
failsafeStop | 0 | carduinodroid repeats its last command even if there are no new commands incomming (unsafe) | |
d4 | resetAccCurrent | 1 | resets the accumulated current counter (it is done automatically at the arduino startup) |
resetAccCurrent | 0 | accumulates the current | |
r3 | r | reserved | |
r2 | r | reserved | |
d1 | frontLight | 1 | turn ON front light |
frontLight | 0 | turn OFF front light | |
d0 | statusLED | 1 | turn ON status LED |
statusLED | 0 | turn OFF status LED |
Format of the Datablock in bytes:
current | absolute capacity | relative capacity | temperature | voltage | distance front | distance back |
---|
The length of the DataBlock is 7. The length of the message is 10 bytes.
DataBlock | range | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
---|---|---|---|---|---|---|---|---|---|
current | 0:255 \ 128 | d7 | d6 | d5 | d4 | d3 | d2 | d1 | d0 |
absolute capacity | 0:255 \ 128 | d7 | d6 | d5 | d4 | d3 | d2 | d1 | d0 |
relative capacity | 0:100 | r7 | d6 | d5 | d4 | d3 | d2 | d1 | d0 |
temperature | 0:255 \ 128 | d7 | d6 | d5 | d4 | d3 | d2 | d1 | d0 |
voltage | 0:255 \ 128 | d7 | d6 | d5 | d4 | d3 | d2 | d1 | d0 |
distance front | 0:255 \ 128 | d7 | d6 | d5 | d4 | d3 | d2 | d1 | d0 |
distance back | 0:255 \ 128 | d7 | d6 | d5 | d4 | d3 | d2 | d1 | d0 |
Current current flow in 0.1mA resolution. The value 128 can not be transmitted. 127 is transmitted instead.
Absolute battery capacity in 1mAh resolution. The value 128 can not be transmitted. 127 is transmitted instead.
Relative battery capacity in %. Bit r7 is reserved. Values should be between 0-100.
Current voltage with 0.1V resolution. The value 128 can not be transmitted. 127 is transmitted instead.
Current temperature measured by the DS2745 chip with a 0.5°C resolution. The value 128 can not be transmitted. 127 is transmitted instead.
Distance measured to the next obstacle in front of the carduinodroid via ultrasound sensor with 1cm resolution. The value 128 can not be transmitted. 127 is transmitted instead. If the distance is 0 or >254 cm a value of 255 is transmitted.
Distance measured to the next obstacle in back of the carduinodroid via ultrasound sensor with 1cm resolution. The value 128 can not be transmitted. 127 is transmitted instead. If the distance is 0 or >254 cm a value of 255 is transmitted.