Run From mBlock IDE or Upload to Board?

If you haven’t yet downloaded mBlock, installed Arduino drivers or connected your board, you might want to take a look at this lesson first. mBlock programs can be run from 2 places: the mBlock interface or the robot board. The following talks about the differences.

mBlock IDE

When running a program in the mBlock IDE, the commands are sent from the computer to the robot board, where they are interpreted and then executed. This means that users can use their computers in conjunction with the robot. For example, you can use the keyboard to control the robot:


Or you can use the timer provided in the mBlock software:


You can also use your webcam, the stage in the mBlock IDE, and much more.

One of the drawbacks about using the mBlock IDE is that because the computer and robot are passing messages to each other, there is a slight lag as these messages take some time to go back and forth. In many programs, this won’t have a big effect on how the robot runs, but on others, for example a line following program, it will mean the program does not run how we would like.

Another thing to consider is that if you are running from the mBlock IDE, you will of course need a computer, and a connection to the computer. If you have a Bluetooth or 2.4G module you can go wireless, but if you don’t, do you really want the robot to always be attached to the computer via USB cable?

When you want to run programs through the mBlock IDE, “Upgrade Firmware” before you begin. Select Connect -> Upgrade Firmware:


This will overwrite any programs currently on the robot board with firmware that makes sure the computer and robot can communicate properly. If you are using the mBot Ranger you also need to select “Bluetooth mode”:


Once the firmware is upgraded, you are ready to start programming from the mBlock IDE.

Robot Board

When uploading to the robot board the program runs as a standalone. This means that all the programming scripts that were only relevant to the mBlock environment programming (such as “Motion” and “Looks”) are unavailable. On the plus side, because the code is uploaded to the board, there is no lag between, for example, reading sensors and acting accordingly.

When you want to upload a program to the Arduino board, you should go into Arduino mode. You can do that either by selecting it from the menu:


Or by dragging and dropping the “(Board Name) Program” block into the programming area and clicking on it (here are the common header blocks):

auriga-program orion-program megapi-program mbot-program

When entering Arduino mode, the stage layout (where the panda is on the left) is hidden and Arduino code is shown on the right. As well as this, all the programming scripts that were only relevant to the mBlock environment programming (such as “Motion” and “Looks”) are greyed out. As you write your mBlock program, Arduino code will automatically be generated in the Arduino editing window.


Once you have finished writing your program, click on the “Upload to Arduino” button and the program will start running as soon as it has successfully uploaded.


NOTE: Once you have uploaded a program to the robot board, whether it be the firmware upgrade or one that you have written yourself, it will have overwritten the preloaded program. If you need to get this program back onto the robot board, go to Connect -> Reset Default Program -> (Robot Name):


Construct Your Dreams!