-
Notifications
You must be signed in to change notification settings - Fork 25
Serial Protocol
This article covers the serial communication between the Bluetooth module with MyoBridge Firmware and the Arduino library. Knowledge of this is not required to use the library, although it might be interesting to know. However, if you want to modify either the firmware or the library, you will probably need this information.
Because the communication between Bluetooth module and host device (Arduino) is often based on software serial, meaning it does not use a physical UART port, but still requires high baud rates for streaming the incoming sensor data, the data is not just sent as binary information.
Instead, commands, responses and data are packed into packages. Each packages starts with the ASCII letter P
, followed by the length of the package (one byte). This length indicates, how many bytes of data follow now. The package ends with the letter E
. A package containing 5 data bytes, for example, would look like this (<5> is the unsigned byte 0x05, not the ASCII character):
P<5>HELLOE
This allows both sides to check if the transmitted packet has the specified length and only process valid packages.
The serial connection operates with a baud rate of 115200, so it can keep up with Myo data streaming.
Based on this packet structure, there are two types of serial packets used in the MyoBridge serial protocol.
Commands are only sent by the host device (Arduino). Which commands the firmware understands is described in the source documentation, or in the MyoBridgeTypes.h header file:
#define MYB_CMD_PING 0x01 ///< ping MyoBridge. MYB_RSP_PING is returned.
#define MYB_CMD_READ_CHAR 0x02 ///< read a characteristic. MYB_RSP_VALUE is returned.
#define MYB_CMD_WRITE_CHAR 0x03 ///< write a characteristic. MYB_RSP_PING is returned.
#define MYB_CMD_SET_ASYNC_STATUS 0x04 ///< set notification/indication status. MYB_RSP_PING is returned.
#define MYB_CMD_GET_STATUS 0x05 ///< request the current system status. Staus constant is returned.
The MyoBridge Firmware always sends a response to commands sent. Same here, you can find them explained in the source documentation or the MyoBridgeTypes Arduino library header:
#define MYB_RSP_PING 0x30 ///< Ping response type ID. Response contains only the packet type.
#define MYB_RSP_VALUE 0x31 ///< Data response type ID. Response contains a value of a specific characteristic.
#define MYB_RSP_STATUS 0x32 ///< Status response type ID (Is sent either through MYB_CMD_GET_STATUS or asyncronously). Response contains the current system status of MyoBridge.
Now that you know which kinds of commands and responses exist, the diagram below shows which response corresponds to which command: