Workshop "Intel IoT". Galileo Gen2 - Eclipse & libmraa + UPM

    It is time to build and launch your “Hello, world!” (And not only) on Galileo, learning in the process how to do this in the most technical way.



    To create programs for Intel Galileo, you don’t need to use any development environments at all. The image of Yocto , which we prepared and installed in the previous part of the "workshop" , has everything you need:

    • Editor
    • Libraries
    • Compiler

    Therefore, let's proceed:

    1. Connect to our target system via SSH (in this case, by default the current folder is / home / root /)

    2. We launch a text editor with the created file:

    nano blink.cpp

    3. Enter the following code:

    #include "mraa.h"
    int main() {
    	mraa_gpio_context gpio; 
    	gpio = mraa_gpio_init(13);
    	mraa_gpio_dir(gpio, MRAA_GPIO_OUT); 
    	bool ledState=true;
    		mraa_gpio_write(gpio, ledState?1:0); 

    Exit (Ctrl + X) and confirm the save.

    4. Compile:

    g++  blink.cpp -lmraa -o blink

    If all is well, then there will be no error messages.

    5. Run the application:


    After that, the built-in LED on the board blinks as expected.

    The code above requires some explanation: the libmraa library is used for such simple pin manipulation.

    Libmraa library

    As previously mentioned , this is the “bicycle” that Intel invented in order to provide the easiest access to the pins present on the Galileo (and Edison) debugging platforms. The library is a "wrapper" for configuring and managing these pins.
    Since the library is open source , you can just peep at how you can work with the corresponding ports directly, without the abstractions provided by libmraa.

    This greatly simplifies the "entry" into the development for "former arduinists" or beginners. The libmraa library allows you to configure pins like GPIO, ADC, PWM, I2C, SPI, and RS232. It helps that the library is well-documented.

    This is good (for the Intel platform), but the Arduino platform is still very attractive for ordinary users (especially beginners) in that there are a huge number of different libraries that implement the simplest possible interaction with various sensors / displays / "performers", etc. Intel decided to offer a solution in this matter:

    UPM library

    UPM runs on top of libmraa and knows nothing about the hardware component of the platform. This library implements the logic of working with connected devices. Unfortunately, the list of compatible devices with which you can work through UPM is still quite modest , but I’m sure that this is a temporary phenomenon.

    The UPM library is also open source - if you wish, you can figure out and add support for the missing device.

    But back to the programming process. Writing code in a console editor is not the greatest pleasure and is suitable only for “real Jedi”, but most developers prefer to use convenient development tools with code highlighting, auto-completion and other goodies, and one of such tools isThe Eclipse . The guys from Intel took care and prepared this environment for working with Galileo (and Edison) debug boards.

    Installation and first start

    Installation is maximally simplified for all platforms - just download the corresponding file with the archive of the pre-configured development environment (includes Eclipse directly, libraries and examples) and unpack it to any convenient place on the disk.

    Appearance of the development environment at the first start

    Since we plan to conduct development for Intel Galileo Gen2, the environment needs to indicate this. To do this, go to the Remote System Explorer tab (in the upper right corner of the Eclipse interface). Since Intel has already prepared almost everything, in the opened tree of remote systems there is already a “galileo” node - all that remains is to specify the IP address of the target system (how to find the IP address of Intel Galileo Gen2 was described in the previous part"Workshop"). After that, you can connect to the node (context menu on the node "galileo" -> "Connect"). If everything is done correctly, you will be prompted for a password:

    After a successful connection with Intel Galileo Gen2, each element of the galileo node will have green "pluses" indicating that everything is in order and you can work.

    Further habitually we do Build. Since everything is already set up - the project from the example will "assemble" without errors (we look at the messages in the console below and in the same place - we look at the "Problems" section). Done, run the project (Run) - at the bottom we see the data from the debug board (as if the application was launched directly through the SSH console):

    Done. Now you can experiment with already prepared examples.

    Upgrading libmraa and upm

    When studying the examples , it turned out that the library versions that are included with the Intel IoT Developer Kit (iotdk) are somewhat outdated and require updating. Update:

    On Intel Galileo Gen2

    The update is done as follows:

    echo "src maa-upm" > /etc/opkg/intel-iotdk.conf
    opkg update
    opkg upgrade

    I can recommend doing it regularly, as the project is developing.

    On desktop pc

    Download the latest versions of the libraries (with the maximum numbers) mraa and upm and simply unzip them to the folder where you have the IDE installed. Naturally, you need to download the version for your platform. Now we have the current version of the libraries and the development environment is ready "in battle"!

    The pre-built Eclipse with examples is just great, but nothing is said about how to create a new project so that it works just like the examples. Correcting this situation.

    Create a new project

    Here I am a little cunning: I will use one of the projects that the guys at Intel prepared, since creating a project from scratch, setting it up for assembly and preparing all the environment variables is a very troublesome task.
    Naturally, you can create a project again, having previously “copied” all the parameters of an “approximate” project, but this is a more complicated way (although, perhaps, a more correct one). I’ll go along a simple and fast-reproducing path with a guaranteed result and minimal opportunities for error.

    As a basis I will take the project 3_c_onboard_LED_blink.

    The first thing to do to successfully copy a project is to close all other projects. To do this, right-click on the desired project and select “Close Unrelated Projects” in the drop-down menu (the folders in the project tree will be “closed”). After that, you can subject the original project to the Copy / Paste procedure (it is possible through the same context menu of the project) - a dialog box appears for entering the name of the new project:

    I called my project myTest. The original project can be closed (so as not to take up space in the project tree). If you expand the tree of the new project, you can see that all the sources and binaries are left there. They can be deleted at any time - they are no longer needed, but I recommend leaving the contents of the includes folder - it is part of the “magic” that will allow our project to pack up and make money on Intel Galileo Gen2. Then, in this folder, you can add others that are missing for the library project.

    I deleted everything unnecessary in the project, and in the src folder (do not confuse it with the Debug / src folder) I created a new source file (right-click on the src folder and in the drop-down menu “New” -> “Source File”:

    We’ll write something simple in the new file (you can take, for example, the blink code that I provided at the beginning of this post). "Build" project: if everything is fine, the project has been compiled, in the "Problems" section it is empty.

    There is only one step left before launching the finished application. Eclipse needs to be explained that the application needs to be run remotely (and not locally). To do this, right-click on the resulting binary (in the project tree) and select: “Run As” -> “Run Configurations ...” in the context menu. The dialog box looks something like this:

    Pay particular attention to the sections marked with arrows. At the top, you need to select our target connection (galileo). Fill in two fields approximately as in my screenshot. The first field indicates the full path to the application on the target device, the second field indicates the command that must be executed before launching our application (in my case, the compiled file is given launch rights). Then it’s easy - Apply and Run. If everything is done correctly, the LED on the board will blink. After that, you can already use the Run button on the Eclipse toolbar.

    Of course, programming in Eclipse is much more convenient than in the console (or in the Arduino IDE), which makes the Intel platform very attractive to developers. But the developer does not use Eclipse alone, there is also Intel XDK.


    In this way, Intel provides maximum capabilities: Intel Galileo Gen2 excellent debugging board, libraries, development tools and support .

    But even that is not all! In the next part of the "workshop":

    Warning spoiler!

    Write in the comments that you are primarily interested in learning about the contents of the spoiler. Did you stop by? :)

    PS In the discussion of the first part of the "workshop" there were questions about the fact that despite the fast processor, Intel Galileo Gen2 does not have very outstanding performance when the pin status changes. While preparing this material, I came across this page , where it says that it is possible to provide a switching frequency of up to 2.9 MHz (compared to the “base” 385 kHz), though such frequencies are not available for all pins - this is due to hardware implementation.

    " The first part of the" workshop ": Galileo Gen2 - The first acquaintance .
    " The second part of the" workshop ": Galileo Gen2 - Linux & Arduino .

    Also popular now: