Kursy • Poradniki • Inspirujące DIY • Forum
Intel Edison programming
When the platform is already standing on your desk, there comes the time when you can start writing a program. It's not that obvious, though, since we have a few different options to choose from. The good news for programmers is that on the Intel website we can find information prepared for Windows, MacOS and Linux users.
For testing Edison I used Windows, and the rest of the article pertains to this system. The sequence of actions is mostly analogous, though, and it shouldn't cause anyone much trouble. We can create applications using 3 compilers:
- Arduino,
- Intel® XDK IoT Edition,
- Eclipse.
This article describes only the stages of working with Edison, one by one, without detailed descriptions! If this topic turns out to be interesting to a wider range of readers, thorough guides about this platform will be posted.
More details in the conclusion of this article!
Since recently I've been spending all my time writing the Arduino course, I'm sure you can guess which one of the Edison programming options I chose? Obviously it was the first option. Why? Arduino itself is very easy, so I unconsciously counted on a similarly easy start with Edison. But before I started flashing the LED I had to do some preparations.
System update, settings
After uploading the software package (available to download from the Intel website) I connected the board to the computer with two USB cables. According to the manufacturer's website, an external power supply is recommended but it's not required. So obviously I didn't use it, which turned out to be a mistake.
Without an additional power supply, the board refused to fully start, it wasn't properly detected. Of course first I reinstalled the drivers, switched the cables for shorter ones and read some information online. Eventually I connected the power supply and the system fully started. The computer showed the new drive I had been waiting for:
Then I updated the operating system (Yocto Linux). It was relatively easy. In a nutshell: connect the system to the computer, remove the old system, download the appropriate archive from the manufacturer's website, upload it to the above drive, connect to the module through through Putty, run the command:
1 |
reboot ota |
There's some magic happening on the screen and the new system appears in front of our eyes.. The next step was configuring the WiFi – we do everything from the console by running the command:
1 |
configure_edison --wifi |
The process of configuring WiFi looks like this:
After that we can connect to the platform using the provided IP address, which you can see on the screenshot below:
Let's leave the console for now and move on to Arduino, which was uploaded with the Intel software package. It's a compiler version, which to the long list of Arduino boards has added Intel Galileo and Intel Edison.
After selecting the platform we need to define the COM port – here we select "the second one". That's because we don't upload programs through the port that we have used before to communicate with Linux.
First I uploaded the standard flashing LED code:
1 2 3 4 5 6 7 8 9 10 11 12 |
void setup() { // initialize digital pin 13 as an output. pinMode(13, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } |
The effect is visible in the animation below (the green LED on the right from Edison):
It's a shame to use such a well-developed platform for flashing 1 LED, though. That's why I started to create another program. It was going to be a simple weather station that collects the following information from the sensors connected to Edison:
- Ambient temperature
- Temperature of Edison's first core
- Light intensity
In order to do that, I built a very simple circuit on a breadboard. According to the diagram below. I used an ordinary photoresistor as a light sensor, and the LM35 analog sensor acted as a thermometer. The potentiometer visible in the diagram was used for regulating the resistance in the voltage divider created with the phototransistor. Thanks to that, I could easily regulate the sensor values.
Next, using the examples, I created a simple program that collected information from the sensors. "Collected" is actually too big of a word – it simply read the information and didn't do anything with it. The whole thing looked as follows. The function reading the temperature of the core comes from the examples:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include <IoTkit.h> // include IoTkit.h to use the Intel IoT Kit #include <Ethernet.h> // must be included to use IoTkit #include <aJSON.h> IoTkit iotkit; char* therm_file = "/sys/devices/virtual/thermal/thermal_zone3/temp"; int odczytSwiatla = 0; int tempCore = 0; int tempOut = 0; void setup() { pinMode(13, OUTPUT); } void loop() { tempCore = getTemp(); tempOut = (analogRead(A1) * 5.0) / 1024.0 * 100; odczytSwiatla = analogRead(A2); } int getTemp() { bool successful = true; int socTemp; char rawTemp[6]; FILE *fp_temp; fp_temp = fopen(therm_file, "r"); if(fp_temp != NULL) { fgets(rawTemp, 6, fp_temp); fclose(fp_temp); } else { Serial.println("Cannot open file for reading."); Serial.println(therm_file); Serial.println("Try another sensors readings in this directory"); successful = false; } if(successful) { socTemp = atoi(rawTemp)/1000; return socTemp; } return 0; } |
The information is collected, time to get to know the Intel IoT Analytics cloud.
The first confrontation with the cloud
To begin your adventure with IoT it's necessary to visit the website of the Intel IoT Analytics project. On the site we find a login and registration form.
After logging in to the system we go to account settings, we need to get the activation code that is valid for one hour:
Now we return to Edison and connect to it through WiFi (using Putty). As I said at the beginning, this description only gives general directions, so I'm not going to describe every single step in detail right now (more information at the end of the article).
It's necessary to install the iotkit-admin agent which allows us to communicate with the cloud. Then we use the provided code and activate Edison.
After a few seconds it's going to be visible in our devices:
Registering system components
Now we need to register the components the system is going to use. To be more clear, we need to declare which information we're going to send from Edison and what's supposed to happen to it later. For this purpose we use sensors and actuators available in the catalog, for example:
Hopefully the detail view sufficiently explains what components are:
Now it's time to actually register the components, which you do from the Edison console. Each sensor needs to be added separately, running a command similar to this one:
1 |
iotkit-admin register tempOut temperature.v1.0 |
Each element needs to have its own unique alias assigned, in this case it's tempOut and the type – here it was the temperature reading. Choosing the appropriate type means that in the chart we're going to see the appropriate scale and unit.
After adding the components it's necessary to restart the iotkit-admin client!
Now we can return to Arduino and start sending the data.
Intel Edison – sending data to the cloud
Now it's time to add the function of sending information to the cloud to our previous program. It's very easy. You just run commands similar to this one:
1 |
iotkit.send("tempOut", tempOut); |
Very simple, isn't it? Communicating with a cloud is not much more difficult than using UART with Arduino. Running this command causes the value of the variable tempOut provided as the second argument to be attributed in the cloud to the component registered under the name tempOut. Of course the similarity of the names of the two values is coincidental.
We don't need to worry about any of Edison's addresses (ID/IP/MAC) – everything is already attributed and saved on our account during the activation process using the code.
The entire program looks as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#include <IoTkit.h> // include IoTkit.h to use the Intel IoT Kit #include <Ethernet.h> // must be included to use IoTkit #include <aJSON.h> IoTkit iotkit; char* therm_file = "/sys/devices/virtual/thermal/thermal_zone3/temp"; int odczytSwiatla = 0; int tempCore = 0; int tempOut = 0; void setup() { pinMode(13, OUTPUT); iotkit.begin(); } void loop() { tempCore = getTemp(); tempOut = (analogRead(A1) * 5.0) / 1024.0 * 100; odczytSwiatla = analogRead(A2); //Zacznij wysyłać aktualizację do chmury iotkit.send("tempOut", tempOut); delay(1000); iotkit.send("tempCore", tempCore); delay(1000); iotkit.send("ileSwiatla", odczytSwiatla); delay(1000); } int getTemp() { bool successful = true; int socTemp; char rawTemp[6]; FILE *fp_temp; fp_temp = fopen(therm_file, "r"); if(fp_temp != NULL) { fgets(rawTemp, 6, fp_temp); fclose(fp_temp); } else { Serial.println("Cannot open file for reading."); Serial.println(therm_file); Serial.println("Try another sensors readings in this directory"); successful = false; } if(successful) { socTemp = atoi(rawTemp)/1000; return socTemp; } return 0; } |
After uploading the program, the data starts to be regularly sent to the cloud. It's going to be visible right after logging in, on the main page.There we will find information about the number of devices connected to our account that send data, and about the number of collected samples:
In the chart tab we're going to find the most interesting part – charts. First we need to select the device and the information we're interested in (you can see that I had registered another thermometer that I didn't end up using):
The chart is displayed below. We can choose how often it's going to refresh. This allows us to have a chart that changes in real time:
What's interesting, the cloud also allows us to define certain rules that trigger certain actions. For example, we can receive an email when the sensor reading drops below a set threshold. There are more options, but for now I'm not going to describe them.
IoT systems on Intel Edison – Course?
As I said at the beginning, I didn't describe working with Intel Edison in much detail. It's not a topic that can be dealt with briefly in just two articles.
After seeing your interest, I thought of a course. One just like the Arduino or STM32 courses. Which means from zero to feeling at home with the platform.
Remember that in this case the cost of hardware will be pretty high – but its capabilities largely exceed those of other technologies. The module itself is also very universal.
Summary of the adventure with Intel Edison
It's time to summarize my brief adventure with Edison. Despite not having had much experience with IoT, I have to admit that accustoming myself to that world wasn't that scary at all. As you can see, writing the first program using GPIO, WiFi and cloud technology is not difficult.
Currently the modules are available in Botland, among other places, and soon they're going to be available in TME too. You can find more information on the Intel iQ blog
It's a shame that for now there's only a limited number of projects based on Intel Edison on the Polish Internet (and not only there). It seems to be caused by the lack of adequate educational materials, and the official ones sadly have some shortcomings. But, as I said, Forbot can change that – everything depends on the results of the poll above!