Thursday, May 15, 2014

Using miniBloq as an IDE

One of the main features of the new v0.82 version is that it allows to make text coded programs. And not just in C/C++ and Arduino-compatible syntax, but also in Python and, if the community adds more targets, in nearly any imperative/OOP language (such as JavaScript, Java, Ruby, etc.). Although in future versions this will be simpler and I'm improving the user experience as much as I can, right now it's fully functional. And it has a feature which I really like: the possibility of switching between a text and a graphical program at anytime during the development. This way, you can make fast test with the blocks, while programming the core of your application with the full power of C/C++ (or whatever language your hardware is using with miniBloq). Let's see how to create an example text coded "echo" program for an Arduino board:

1. Open miniBloq (we will be using Arduino Mega 2560 for this example, but you can select any other Arduino-compatible board from miniBloq's hardware list):


2. Since we will create the whole code for the project, we don't want to initialize the board automatically. So we will change the first call to initBoard, for a call to the function go():
What does this mean? It means that at the very beginning of your program, it will do nothing but calling the go() function. And what is the go() function? Is a function that you will write by your own, and where your program will start. It's like the main() function in C/C++, but we can not name it main() because that name is already used internally by the Arduino kernel (I will post more about this soon). In  "Arduino terms", the go() function is equivalent to the setup() function.

3. Add a new cpp file (created just as a text file). First, go to the File->Add menu:

save the component (miniBloq's jargon for your program):



And inside the component's folder, create the text file:



We will name it echo.cpp but you can use any (valid) name of your preference:


You will see this message box when you change the file extension from txt to cpp. Of course say Yes:


Now, you will see the echo.cpp open in the file editor in miniBloq:


You can hide the blocks editor to gain space in the screen to work with your text file:


4. Let's add some code there. You will need to include the mbq.h file, which gives you access to the libraries for the motors, the sensors, the Arduino API functions, etc.:


5. If you compile that, it should compile just fine, but it's an empty program. Now, please try the following piece of code, which is our final echo program:

#include <mbq.h>

void go()
{
serial0.begin(115200);

while(true)
{
if (serial0.available())
{
int inByte = serial0.read();
serial0.print((char)inByte);
}
}
}

6. Run it and you will see how it works by using miniBloq's terminal:


Finally, if you want to use blocks to test, you just need to select initBoard() in the Start block, and start adding your blocks there. The files that you have added will remain there (unless you close them). Once you want to return to the text coding, just select go() again in your start block.

In a future post, I want to show you how to work with multiple file projects. But probably you can just try to experiment a bit by yourself using the Add file feature.

Enjoy!

Wednesday, May 7, 2014

miniBloq.v0.82 released!

Here are some of the new features and improvements:

miniSim!
This is a new, simple 2D robot simulator designed to help teaching simple robotics principles for those who don't own a robot:

Complete new XML backend
These are good news for all the developers, manufacturers and advanced users who want to add new hardware and custom blocks. Now you can do it just editing XML files! I will work on the Developer's Guide in the next days to explain how.

A lot of new hardware
Thanks to the new backend, there is a lot of new supported hardware (specially robots!), including: Pi-BotSparki robotSparkFun RedBot and RedBoardArduino Leonardo and the new Multiplo's DuinoBot.v2.3, both in HID and in CDC modes...

Write both graphical or text based programs
Or even combine graphical with text-based programming anytime during the development of your program. The new miniBloq can even work as a (simple) standard IDE!

And many other features...
  • miniBloq is now faster and it remembers its settings (like the selected hardware, the screen dimensions and the serial port). Also, you can associate mbqc files to it in order to open them with double click.
  • Of course, there are more blocks and bug fixes.
  • A LOT of examples! And they has been rearranged. Check them with the File-Examples menu, and remember that most of the examples are under the DuinoBot folder. And don't worry if you don't have a DuinoBot board: most of those examples run on an regular Arduino.

Portable Python + OpenCV!
Advanced users will find this really interesting: miniBloq now includes Portable Pytnhon and OpenCV to do some more advanced activities with interactive programming (not graphical yet) and computer vision. Here is a tutorial from SparkFun, wrote at during my Hackers In Residence early this year (thanks Linz!).

Downoad it it now!
This is the direct link to get the v0.82. Enjoy!

To read more about all the changes (and known issues), take a look to the changelog.  Finally, as many of you already know, miniBloq has moved to GitHub. So the complete source code is available from the online repository: https://github.com/miniBloq/v0.82. You can both replicate the repo, or just use the Donwload ZIP button there to get the complete source code.

In future posts I will be talking about some of the new features in this version...