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. Open your mBlock, then connect your mBot with computer
- 2. “Connect” -> “Serial Port ” -> your device COM number
- 3. “Connect” -> “Upgrade Firmware”
- 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_1 | begin_code_2 | length | index | action | device | port | speed_low | speed_high |
---|---|---|---|---|---|---|---|---|
ff | 55 | 06 | 00 | 02 | 0a | 09 | ff | 00 |
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
Set right DC motor speed 255:
- ff 55 06 60 02 0a
Buzzer
begin_code_1 | begin_code_2 | length | index | action | device | tone_Low | tone_High | beat_Low | beat_High |
---|---|---|---|---|---|---|---|---|---|
ff | 55 | 07 | 00 | 02 | 22 | 7b | 00 | fa | 00 |
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
Set LED Color
begin_code_1 | begin_code_2 | length | index | action | device | port | slot | position | r | g | b |
---|---|---|---|---|---|---|---|---|---|---|---|
ff | 55 | 09 | 00 | 02 | 08 | 07 | 02 | 00 | 0a | 00 | 00 |
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_1 | begin_code_2 | length | index | action | device | port |
---|---|---|---|---|---|---|
ff | 55 | 04 | 02 | 01 | 01 | 03 |
For example:
Send data to get ultrasonic value:
The format of data responded by the ultrasonic sensor is:
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_1 | begin_code_2 | length | index | action | device | port |
---|---|---|---|---|---|---|
ff | 55 | 04 | 05 | 01 | 03 | 03 |
For example:
Send data to get light value:
The format of data responded by the light sensor is:
The way to get result value is the same as the ultrasonic sensor part.
Read Line Follow Sensor
begin_code_1 | begin_code_2 | length | index | action | device | port |
---|---|---|---|---|---|---|
ff | 55 | 04 | 60 | 01 | 11 | 02 |
For example:
Send data to get line follow sensor’s value:
The format of data responded by the line follow sensor is:
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. Open your mBlock, then connect your mBot with computer
- 2. “Connect” -> “Serial Port ” -> your device COM number
- 3. “Boards” -> “mBot”. Please make sure you have chosen “mBot” mode
- 4. “Edit” -> “Arduino mode” to open serial port tool
After the above steps, open mBlock’s serial port tool:
Let’s run the motor instruction for a test.
- ff 55 06 60 02 0a
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/ 🙂