mBot Serial Port Protocol

This article shows a basic instruction format of mBot. You can use some serial port tool to test these instructions on your mBot.

 

Upgrade Your mBot’s Firmware

The latest version of mBot firmware is V1.20101. You can upgrade your mBot with the latest mBlock.
Follow the below steps to upgrade:

  1. 1. Open your mBlock, then connect your mBot with computer
  2. 2. “Connect” -> “Serial Port ” -> your device COM number
  3. 3. “Connect” -> “Upgrade Firmware”
  4. 4. When a dialog pops up, just click the “confirm” button and wait till the upgrading process finished

After upgrading firmware, use the following instructions to test your mBot.

Instruction Format

 

DC Motor

begin_code_1begin_code_2lengthindexactiondeviceportspeed_lowspeed_high
ff550600020a09ff00

speed_low = speed & 0xff;
speed_high = (speed >> 8) & 0xff;
(“speed” is a number set by your own, ranging from -255 to 255.)

For example:

Set left DC motor speed 255:

  • ff 55 06 60 02 0a 09 ff 00

Set right DC motor speed 255:

  • ff 55 06 60 02 0a 0a ff 00

Buzzer

begin_code_1begin_code_2lengthindexactiondevicetone_Lowtone_Highbeat_Lowbeat_High
ff55070002227b00fa00

tone_low = tone&0xff;
tone_high = (tone>>8)&0xff;
tone is a number chosen by your own. Here is a list for you to choose the tone value:

“C2”:65, “D2”:73, “E2”:82, “F2”:87, “G2”:98, “A2”:110, “B2”:123, “C3”:131, “D3”:147, “E3”:165, “F3”:175, “G3”:196, “A3”:220, “B3”:247, “C4”:262, “D4”:294, “E4”:330, “F4”:349, “G4”:392, “A4”:440, “B4”:494, “C5”:523, “D5”:587, “E5”:658, “F5”:698, “G5”:784, “A5”:880, “B5”:988, “C6”:1047, “D6”:1175, “E6”:1319, “F6”:1397, “G6”:1568, “A6”:1760, “B6”:1976, “C7”:2093, “D7”:2349, “E7”:2637, “F7”:2794, “G7”:3136, “A7”:3520, “B7”:3951, “C8”:4186

beat_Low and beat_high have separate default values: “fa” and “00”.

For example:

Play tone C4:

  • ff 55 07 00 02 22 7b 00 fa 00

Set LED Color

begin_code_1begin_code_2lengthindexactiondeviceportslotpositionrgb
ff55090002080702000a0000
position has 3 values: 01 represents left LED, 02 represents right LED, and 00 represents both LEDs.
For example:

Turn both LEDs to red color:

  • ff 55 09 00 02 08 07 02 00 0a 00 00

Read Ultrasonic Sensor Value

begin_code_1begin_code_2lengthindexactiondeviceport
ff550402010103
For example:

Send data to get ultrasonic value:

  • ff 55 04 02 01 01 03

The format of data responded by the ultrasonic sensor is:

  • ff 55 02 02 23 ac 03 43 0d 0a

Please pay attention to the highlighted 4 bytes above, you should transform them from “byte” to “int” type separately, then add them together to get the result value, as follow:

  • result = ( 0x23 << 24 ) + ( 0xac << 16 ) + ( 0x03 << 8 ) + 0x43

Read Light Sensor Value

begin_code_1begin_code_2lengthindexactiondeviceport
ff550405010303
For example:

Send data to get light value:

  • ff 55 04 05 01 03 03

The format of data responded by the light sensor is:

  • ff 55 05 02 00 00 40 41 0d 0a

The way to get result value is the same as the ultrasonic sensor part.

Read Line Follow Sensor

begin_code_1begin_code_2lengthindexactiondeviceport
ff550460011102
For example:

Send data to get line follow sensor’s value:

  • ff 55 04 60 01 11 02

The format of data responded by the line follow sensor is:

  • ff 55 60 02 00 00 40 40 0d 0a    both led turn on
  • ff 55 60 02 00 00 00 40 0d 0a    left turn on, right turn off
  • ff 55 60 02 00 00 80 3f 0d 0a      left turn off, right turn on
  • ff 55 60 02 00 00 00 00 0d 0a      both turn off.

The line follow sensor will only return the data of the above 4 stages.

The way to get result value is the same as the ultrasonic sensor part.

Use mBlock’s serial port tool to test the above instructions:

  1. 1. Open your mBlock, then connect your mBot with computer
  2. 2. “Connect” -> “Serial Port ” -> your device COM number
  3. 3. “Boards” -> “mBot”. Please make sure you have chosen “mBot” mode
  4. 4. “Edit” -> “Arduino mode” to open serial port tool

After the above steps, open mBlock’s serial port tool:

1

Let’s run the motor instruction for a test.

  • ff 55 06 60 02 0a 09 ff 00

2

Now, see your own motor running? If not, please check the above steps carefully, check whether your mBot has connected to mBlock successfully or not.

It would be much appreciated if you share some interesting cases of this test at http://openlab.makeblock.com/ 🙂

Skills

Posted on

2016-01-26