mBlock firmware protocol introduction


#1

The unit of protocol communication is frame.

  • Request frame consists of head, length, index, action, module, data.

  head: head of frame, 2 bytes, with value 0xFF and 0x55.
  length: 1 byte, describe the length of data.
  Index: request number, 1 byte.
  action: command type, 1 for requesting sensor data, 2 for actuator command.
  module: describe the module of this frame, such as encoder motor driver module(0x01), stepper
  motor driver module(0x02), 1 byte.
  data: data to be sent.

  • Response frame consists of head, index, type, data.

  head: head of frame, 2 bytes, with value 0xFF and 0x55.
  Index: request number, 1 byte.
  type: 1 byte, data type. 1-byte, 2-float, 3-short, 4-len+string.
  data: its length is determined by data type.

  • Demo:

  Control DC motor:
    M1 port DC motor rotates clockwise with full speed: 0xFF 0X55 0x07 0x0 0x2 0x0A 0x09
    short2bytes(255)
    M2 port DC motor rotates counterclockwise with full speed: 0xFF 0X55 0x07 0x0 0x2 0x0A 0x0A
    short2bytes(-255)
    Short2bytes function is used to transfer short type data to byte array data.

  Get data from ultrasonic sensor:
    Request data of ultrasonic sensor from Port 3: 0xFF 0X55 0x04 index 0x1 0x01 0x03
    Response data: 0xFF 0X55 index 0x2 byte byte byte byte(transfer 4 bytes data to
    float automatically)


How to use dual mode bluetooth module in the Arduino IDE?