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

Hardcore
To create programs for Intel Galileo, you can not use any development environment at all. In the image of
Yocto , which we have prepared and installed in the
previous part of the "practical work" - there is everything you need:
Therefore, we proceed:
')
1. Connect to our target system via SSH (the current folder is / home / root / by default)
2. Start the text editor with the file being created:
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; while(true){ mraa_gpio_write(gpio, ledState?1:0); ledState=!ledState; sleep(1); } }
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:
./blink
After that, the integrated LED on the board blinks as expected.
The code above requires clarification: for such a simple manipulation of pins, the library libmraa is used.
Libmraa library
As it was
written earlier , this is a “bicycle”, which was invented by Intel in order to provide the easiest access to the pins that are present on 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 abstractions provided by libmraa.
This maximally simplifies the “entry” into the development for “former Arduinschikov” or beginners. The
libmraa library allows you to configure pins as 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) because there are a huge number of different libraries that implement the most simple interaction with various sensors / displays / "performers", etc. Intel decided to offer its 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 am sure that this is a temporary phenomenon.
The UPM library is also
open source - if you wish, you can understand and add support for the missing device.
But back directly to the programming process. Writing code in the console editor is not a great pleasure and is only suitable for "real Jedi", but most developers prefer to use handy development tools with code highlighting, autocompletion and other buns, and one of these tools is
Eclipse . The guys from Intel took care and prepared this environment for working with the Galileo (and Edison) debugging boards.
Installation and first launch
Installation is as simple as possible for all platforms - just download the
appropriate file with the archive of the pre-configured development environment (includes Eclipse itself, libraries and examples) and unpack it to any convenient place on the disk.
Appearance of the development environment at the first launchSince we plan to conduct development for Intel Galileo Gen2 - you need the environment 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, there is already a “galileo” node in the opened tree of remote systems - all that remains is to specify the IP address of the target system (how to find out the IP address of the Intel Galileo Gen2 described in the
previous part of the practicum). After that, you can connect to the node (context menu on the node "galileo" -> "Connect"). If done correctly, you will be prompted for a password:

After successfully connecting with Intel Galileo Gen2, each element of the “galileo” node will have green “pluses”, showing that everything is in order and you can work.
Next we do the usual Build. Since everything is already set up - the project from the example will “assemble” without errors (we look at the messages in the console from below and there 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 via the SSH console):

Is done. Now you can experiment with already prepared examples.
Upgrade libmraa and upm
When studying the
examples , it turned out that the versions of the libraries that come with the Intel IoT Developer Kit (iotdk) are somewhat outdated and need to be updated. Update:
On Intel Galileo Gen2
The update is done as follows:
echo "src maa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/intel-iotdk.conf opkg update opkg upgrade
I can recommend to do it regularly, as the project develops.
On the desktop
Download the latest versions of libraries (with maximum numbers)
mraa and
upm and simply unzip them into the folder where you have the IDE installed. Naturally, you need to download the version for your platform. Now we have up-to-date versions of libraries and the development environment is ready to “fight”!
The pre-configured Eclipse with examples is just great, but nothing is said about how to create a new project in such a way that it works just like the examples. Correct this situation.
Creating a new project
Here I am a little cunning: I will use one of the projects that the guys at Intel have prepared, since creating a project from scratch, all its configuration for building and preparing all environment variables is a very troublesome task.
Naturally, it is possible to create a project anew, having previously “sketched” all the parameters of an “exemplary” project, but this is a more complicated way (although, perhaps, a more correct one). I will follow a simple and fast-reproducible way with a guaranteed result and minimal possibilities for error.
I will take the project 3_c_onboard_LED_blink as a basis.
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 (and the folders in the project tree will “close”). After that, the original project can be subjected to the Copy / Paste procedure (through the same context menu of the project) —a dialog box will appear for entering the name of the new project:

I called my project myTest. The original project can be closed (so as not to occupy a place in the project tree). If you expand the new project tree, you can see that all the source codes and binaries remain there. They can be removed at any time - they are no longer needed, but I recommend to leave the contents of the includes folder - it is part of the "magic" that will allow us to get together for our project and make money on Intel Galileo Gen2. Then in this folder you can add others missing for the library project.
I deleted everything unnecessary in the project, and in the src folder (not to be confused with the Debug / src folder) I created a new source file (right-click on the src folder and in the dropdown menu “New” -> “Source File”:

In the new file we will write something simple (you can take, for example, the blink code, which I quoted at the beginning of this post). “Bildim” project: if everything is good, the project was compiled, in the “Problems” section - empty.
Only one step left before launching the finished application. It is required to explain to Eclipse that the application must be launched remotely (and not locally). To do this, right-click on the resulting binary (in the project tree) and select in the context menu: “Run As” -> “Run Configurations ...”. The dialog box looks like this:

Pay special attention to the sections marked with arrows. At the top, you need to select our target connection (galileo). Two fields fill in the same way as I have in the 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 permissions to run). Further simply - Apply and Run. If done correctly, the LED on the board will start blinking. 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 for developers. But the developer is not the only Eclipse, there is also the
Intel XDK .
IMHO
Thus, Intel provides the maximum possibilities: excellent debug board Intel Galileo Gen2, libraries, development tools and
support .
But even this is not all! In the next part of the "workshop":
Write in the comments that you are interested first of all to learn about the contents of the spoiler. You looked in, didn't you? :)
PS In the discussion of the first part of the “practical work” there were questions about the fact that, despite the fast processor, Intel Galileo Gen2 is not too prominent when changing the state of a pin. While preparing this material I stumbled upon
this page , where it is written that it is possible to provide the switching frequency as much as 2.9 MHz (compared to the “base” 385 kHz), although these frequencies are not available for all pins - this is due to the hardware implementation.
» The first part of the" workshop ":
Galileo Gen2 - The first acquaintance .
» The second part of the" workshop ":
Galileo Gen2 - Linux & Arduino .