/
mBot using Arduino IDE

mBot using Arduino IDE

To harness the full power of the robot, you need to use the Arduino IDE.

The mBot official tutorial can be found here - https://support.makeblock.com/hc/en-us/articles/4419572961943-Program-mBot-with-Arduino-IDE

Setting up the IDE for mBot

Installing the IDE

Install the IDE using the Windows Installer.

  • The installation is very straightforward.

  • When it asks you to install certain drivers, click yes / allow.

  • It may also prompt you that some updates are available for your board and libraries. You can click update all on your own computer. If you are using a lab computer, simply close the window.

Essential Settings

Select Arduino Uno as the device in Tools > Board > Arduino AVR Boards > Arduino Uno.

Select the correct serial port in Tools > Port > COMx after ensuring that the mCore is powered on. If you are not sure which port to select, in Windows, you can go to Device Manager (type 'Device Manager' in the Windows Start Menu), and check for the port number under Ports (COM & LPT). The correct port will be the one corresponding to 'USB-SERIAL CH340'.

Once both the above are set correctly, the bottom-right corner of Arduino IDE should show . The actual COM number could be different on your PC/laptop.

The first time when you try to program using Arduino, you may get one or more Windows firewall warnings. Click Allow access when prompted. 

Installing Makeblock library

Install the library (customized).

In the Arduino IDE:  Sketch > Include Library > Add .ZIP Library > select the downloaded file > Open. Restart the Arduino IDE. 

  • If you are getting an error, unzip the .zip file and copy it to Documents\Arduino\libraries. Make sure that you can see subfolders examples, src and files library.properties, README.md in the path Documents\Arduino\libraries\Makeblock-Libraries.

  • The original library can be found at https://github.com/Makeblock-official/Makeblock-Libraries, but you can use the customized library for now. There are a number of boards available; we use the MeMCore board. The original library uses MeOrion.h whereas we need MeMCore.h.

  • If you get an error that Wire.h can't be found, please copy the Wire.h from Documents\Arduino\libraries\Makeblock-Libraries\src\utility to Documents\Arduino\libraries\Makeblock-Libraries\src\ folder.

Example Programs

Try out the various example programs from - File > Examples > MakeBlockDrive. 

  • The examples assume that the line follower sensor is connected to PORT_3 and the Ultrasonic sensor is connected to PORT_4.

  • For some example programs, you will need to open the Serial Monitor tab via Tools > Serial Monitor. This may also trigger a Windows firewall warning the first time.

    • The baud rate should be set to be the same as the one in Serial.begin()

image2022-12-2_0-0-41.png

Using Button and Blue LED Onboard

Note that there is no example program for the onboard button. However, it can be easily read using analogRead() from pin A7.

  • This will require you to have pinMode(A7,INPUT); in setup() and something like if (analogRead(A7) < 10){} in loop() to detect if the button is pressed.

There is also a blue LED connected to pin D13.