mBlock3: Advanced Arduino Extension

Author: Aleksandr Grigorev

Download extension

Download
AdvancedArduino.zip
Compressed Archive in ZIP Format 4.6 KB

What is "AdvancedArduino"

Download
demo.sb2
Compressed Archive in ZIP Format 73.8 KB

"AdvancedArduino" is an extension for the mBlock visual programming environment , which can be used instead of basic "Arduino" extension, and has the following extra options when working in Arduino mode:

  • new blocks for a number of the most popular library functions of Arduino IDE (min(), max(), constrain(), map(), pow()), intended for converting values;
  • additional blocks for working with serial communications (Serial, and also Serial2);
  • most basic blocks named with classic library function names (like "digitalRead"); 
  • "def" and "code" blocks allows inclusion of custom code snippets written in "Wire" (Arduino IDE) programming language;
  • ability to use any library functions of Arduino IDE in the code snippets;
  • option to define custom functions that return values of arbitrary type;
  • ability to use global and local variables and function parameters of arbitrary type, including arrays.

Attention! The mBlock visual programming environment generates the Arduino code sketch using the "double" type for all variables and function parameters created in the visual mode. Do not forget, if necessary, cast the value to another type - int (), byte (), String ().

 

Installing the AdvancedArduino Extension

First method

  • Run mBlock and select Extensions -> Manage Extensions from the menu. The extension list will be downloaded from MakeBlock website.
  • Type "AdvancedArduino" in the "Search" field. You will see the "AdvancedArduino" element on the list.
  • Click on the "Download" button of the "AdvancedArduino" element.

 

Second method

  • Download or copy "AdvancedArduino.zip" file to your computer.
  • Run mBlock and select Extensions -> Manage Extensions from the menu, then click on the "Add Extension" button.
  • Select the file type "zip-file", scroll to the downloaded archive, then click on the "Open" button.

If you have any questions, look at the additional instructions from the Makeblock developers:

http://www.mblock.cc/docs/create-extensions-for-mblock/

 

Examples of using the AdvancedArduino extension

Example 1

Blocks with custom code snippets ("Wire" programming language) in a graphical script.

Attention! When mBlock generates Arduino code sketch it comments out the code () and def () block values using the /* and */ directives. To make the code fragment visible to the compiler, it is necessary to put the CLOSE "bracket" ( */ ) in the BEGINNING, and the OPEN “bracket”  ( /* ) at the END. Mind that the mBlock automatically  adds the pinMode () commands to the Arduino IDE sketch only when it encounters blocks like "digitalRead" and "digitalWrite" in the graphical script.

Download
Sample 1 - Advanced Arduino Program.sb2
Compressed Archive in ZIP Format 73.2 KB

 

Example 2

Global and local variables, arrays and functions that return values. 

Note that the global variable "SizeOfArray" is of a double type, in this example, an explicit conversion of the value to another type is used: byte(SizeOfArray).

Download
Sample 2 - Advanced Arduino Program 2.sb
Compressed Archive in ZIP Format 73.6 KB

 

Example 3

Boxes with library functions Arduino IDE

Download
Sample 3 - Advanced Arduino Program.sb2
Compressed Archive in ZIP Format 73.3 KB

 

Example 4

The "line" addition of the custom code snippets.

Note that in the text field of the first "Serial println" box, you need to enter the character <space> (ASCII 32), in this case mBlock adds the command Serial.println () to the Arduino IDE sketch. If there is an empty line inside the text field, the command Serial.println (0) is generated instead.

Download
Sample 4 - Advanced Arduino Program.sb2
Compressed Archive in ZIP Format 73.6 KB

 

Example 5

Using the Wire code saved as a text file on the disk.

Download
Sample 5 - Advanced Arduino Program.sb2
Compressed Archive in ZIP Format 73.5 KB

 The disk must contain a text file with the appropriate name and content. If it is necessary, change the path to this file in your script.

Contents of the text file:

 

 

sampleFunction:

 

void ascendingSort(int dt[], int SizeOfArray) {

  for (int i=0;i<SizeOfArray;i++) {

    for (int j=i+1;j<SizeOfArray;j++) {

  if (dt[i]>dt[j]) {

    int temp=dt[i];

dt[i]=dt[j];

dt[j]=temp;

  };

};

  };

};