Communication protocol
Message format
Messages sent to and received from the microcontrollers are byte oriented streams. All messages start with a caret sign ^ (0x5e) and end with a dollar sign $ (0x24).
Bytes | 1 | n | 1 |
---|---|---|---|
^ |
n unsigned bytes |
$ |
An exclamation mark ! inside a message body indicates a transmission error and invalidates the whole message. The characters ^, $, ! and \ are special and must be escaped with a backslash \ followed by the two’s complement of the escaped character (they are thus encoded on two successive bytes).
Special character | Escaped version inside a message body |
---|---|
^ |
\ 0xa2 |
$ |
\ 0xdb |
! |
\ 0xde |
\ |
\ 0xa3 |
All messages may embed signed or unsigned integers. They are encoded on 1, 2 or 4 bytes (depending on the message format decribred later), in big-endian format (most significative byte first).
Bytes | 1 | 2 | 3 | 4 |
---|---|---|---|---|
8 bits integer |
n |
|||
16 bits integer |
n >> 8 |
n |
||
32 bits integer |
n >> 24 |
n >> 16 |
n >> 8 |
n |
Messages
ID
This message queries the softwareversion.
Bytes | 1 | 1 | 1 |
---|---|---|---|
^ |
? |
$ |
Bytes | 1 | 1 | n>6 (string) | 1 |
---|---|---|---|---|
^ |
? |
arduioX.Y |
$ |
X.Y represent the software version running on board.
GPIO direction
This message configures the given GPIO for input, with or without pullups, output or PWM.
Bytes | 1 | 1 | 1 | 1 | 1 |
---|---|---|---|---|---|
^ |
d |
n |
direction |
$ |
n is the GPIO number, direction is 0 for input, 1 for input + pullup, 2 for output and 3 for PWM.
GPIO out
This message sets the output state of a GPIO.
Bytes | 1 | 1 | 1 | 1 | 1 |
---|---|---|---|---|---|
^ |
o |
n |
v |
$ |
n is the GPIO number, v is interpreted as a boolean for digital outputs, or the PWM duty cycle (255 is 100%).
GPIO out array
This message sets the output state of the first n GPIOs.
Bytes | 1 | 1 | 1..n | 1 |
---|---|---|---|---|
^ |
O |
v |
$ |
For each GPIO starting from 0, v is interpreted as a boolean for digital outputs, or the PWM duty cycle (255 is 100%).
GPIO in
This message returns the state of a GPIOs.
Bytes | 1 | 1 | 1 | 1 |
---|---|---|---|---|
^ |
i |
n |
$ |
n is the GPIO number. The reply has the following format:
Bytes | 1 | 1 | 1 | 1 | 1 |
---|---|---|---|---|---|
^ |
i |
n |
v |
$ |
n is the GPIO number, v is the state (0 or 0xff for digital I/Os, or the PWM duty cycle for PWM).
Analog I/O in
This message returns the state of an analog input.
Bytes | 1 | 1 | 1 | 1 |
---|---|---|---|---|
^ |
a |
n |
$ |
n is the I/O number. The reply has the following format:
Bytes | 1 | 1 | 1 | 1 | 1 |
---|---|---|---|---|---|
^ |
a |
n |
v |
$ |
n is the pin number, v is the analog state value.
State request
This message returns the state of all GPIOs and analog input.
Bytes | 1 | 1 | 1 |
---|---|---|---|
^ |
s |
$ |
The reply contains two messages, with the state of digital I/O and analog pins.
Bytes | 1 | 1 | 1..n | 1 |
---|---|---|---|---|
^ |
I |
v |
$ |
|
^ |
A |
v |
$ |
The I array is for all GPIOs, the A array for analog inputs.