Installing mBlock Software
http://www.mblock.cc/mblock-software/.
- Install the latest version for PC (V5.4.0).
- You will need to install the driver when prompted by clicking INSTALL, as well as Allow access when you get a firewall warning.
Getting Started with mBlock Software
mBlock software getting started - https://www.mblock.cc/doc/en/quick-start/quick-start.html. Follow this page as well as the next two pages.
- https://www.mblock.cc/doc/en/quick-start/create-your-sprite.html
- https://www.mblock.cc/doc/en/quick-start/add-sounds.html
Now, it is time to play with the actual device (mBot/mCore). The steps here - https://www.mblock.cc/doc/en/quick-start/connect-device.html show a device called HaloCode and not our beloved mBot. Hence, the steps are slightly different, which is given below (the steps below are mostly similar to http://docs.makeblock.com/mbot/en/tutorials/quick-start.html).
The default device after installation will be CyberPi and not mBot. You can delete the CyberPi and then click 'add'.
In the Device Library dialog, you can select mBot. Clicking the star button on the icon will cause the default to be set to mBot, so that you don't have to do it the next time.
Get familiarized with both Upload mode and Live mode - read more at https://www.mblock.cc/doc/en/hardware-basic/mode.html.
Live mode
Select the mode (say, Live mode for now) and click Connect after ensuring that mBot/mCore is powered on. You will then be prompted to select the port.
Generally, mBlock will detect the correct port automatically. However, 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'.
In Live mode, you can change the behaviour very easily without re-uploading the code every time. It requires the firmware to uploaded/updated one time and then not again unless you switch to upload mode. You will be prompted to update after you click 'Connect' if the firmware is to be uploaded/updated. You can choose the Online firmware. Once the firmware is updated, you have to click Connect again.
=> =>
Now let us test the Live mode. The event block should already be there in the scripts area. If not, you can find it under Events, and drag it to script area as shown below.
Next, drag the block into the scrips area and connect it to the block.
Next, click the button. The two LEDs on mBot should turn RED for 1 second. Hurray, you have gotten started well!
Play with other blocks, and see the various inputs/outputs in action! You can see details of other blocks applicable for mBot under Block Reference section in http://docs.makeblock.com/mbot/en/.
Interaction between Devices and Sprites
Enabling your mBot/mCore to interact with sprites is useful to make the sprite (say, Panda) read out sensor values.
This is illustrated using an example for reading the light sensor on the Device (mBot)and making the Sprite (Panda) display the reading.
Create a new variable from the tab. Select 'For all sprites'
Create your program similar to the one shown below for the device (mBot).
Note that the broadcast block is available under . Here, we created a message with a meaningful name 'new_light_reading'.
For the sprite (Panda), create a program similar to the one below.
The variable 'light_reading' will be available for the sprite as well.
Now, click the flag and the sprite (Panda) will say the new reading when it is made available by the device (mBot), which will be once a second.
The official tutorial is found here - https://www.mblock.cc/doc/en/quick-start/role-device.html. Note that here too, you can use instead of the 'when button is pressed' mentioned in that page (which is for HaloCode device and not mBot). A more detailed description is given below.
Upload mode
Note that in Upload mode, the only available is , which isn't available in Live mode.
In upload mode, you can see the corresponding Arduino C code by clicking the orange button on the right side of the window , which is pretty cool and helps you transition to Arduino C. A sample is given below.
More Examples
You can try out the various examples here using mCore - http://www.mblock.cc/example/introduction/
Arduino C in mBlock
mBlock can also handle Arduino C directly. You can't see l switch between using blocks and using code seamlessly though. Make sure you include #include <Arduino.h>