Communication protocol
Serial port
Communication with the board is established through the serial port, with a 2Mbps baud rate, 8bits, no parity, one stop bit (8N1).
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 |
---|---|---|---|
|
|
|
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 |
---|---|
|
|
|
|
|
|
|
|
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 |
|
|||
16 bits integer |
|
|
||
32 bits integer |
|
|
|
|
Messages
ID
This message queries the softwareversion.
Bytes | 1 | 1 | 1 |
---|---|---|---|
|
|
|
Bytes | 1 | 1 | n>6 (string) | 1 |
---|---|---|---|---|
|
|
|
|
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 |
---|---|---|---|---|---|
|
|
|
|
|
n is the GPIO number, direction is an integer mapped according to the following table:
direction | input/output type |
---|---|
0 |
|
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
16 |
|
GPIO out
This message sets the output state of a GPIO.
Bytes | 1 | 1 | 1 | 2 | 1 |
---|---|---|---|---|---|
|
|
|
|
|
n is the GPIO number, v is interpreted as
-
a boolean for digital outputs,
-
the PWM duty cycle (65535 is 100%) for PWM,
-
the led index/color for WS28XX (see Modes of operation).
GPIO out array
This message sets the output state of the first n GPIOs.
Bytes | 1 | 1 | 1..2n | 1 |
---|---|---|---|---|
|
|
|
|
For each GPIO starting from 0, v is interpreted as
-
a boolean for digital outputs,
-
the PWM duty cycle (65535 is 100%),
-
the led index/color for WS28XX (see Modes of operation).
GPIO in
This message returns the state of a GPIOs.
Bytes | 1 | 1 | 1 | 1 |
---|---|---|---|---|
|
|
|
|
n is the GPIO number. The reply has the following format:
Bytes | 1 | 1 | 1 | 2 | 1 |
---|---|---|---|---|---|
|
|
|
|
|
n is the GPIO number, v is the state (0 or 0xffff for digital I/Os, or the PWM duty cycle for PWM, or the led #0 color.
Analog I/O in
This message returns the state of an analog input.
Bytes | 1 | 1 | 1 | 1 |
---|---|---|---|---|
|
|
|
|
n is the I/O number. The reply has the following format:
Bytes | 1 | 1 | 1 | 1 | 1 |
---|---|---|---|---|---|
|
|
|
|
|
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 |
---|---|---|---|
|
|
|
The reply contains two messages, with the state of digital I/O and analog pins.
Bytes | 1 | 1 | 1..n | 1 |
---|---|---|---|---|
|
|
|
|
|
|
|
|
|
The 'I' array is for all GPIOs, the 'A' array for analog inputs.