Sergiy Baydachnyy

Blog about technologies

Posts Tagged ‘Galileo

Internet of Things: My first experience with Galileo 2 (part 2)

leave a comment »

In the previous article we discussed how to setup your first Galileo board and showed some stuff that you need to deploy applications there. In this article we will try to understand what is Galileo and how we may use it in more advanced projects.

So, Galileo is a powerful development platform with x86 compatible processor, USB, mini-PCI, Ethernet port, 256MB DDR3, SD slot, which may help makers, students and enthusiasts to develop their own projects. Galileo is compatible with Arduino prototyping boards, so developers may use any existing hardware, which could be used with Arduino Uno or something like this. And, of course, Galileo may support not just Linux but Windows platform as well. It allows us to create our software in a friendly environment.

Of course, Galileo is the heart of your device and enables reading some inputs from external world and provides own outputs there. For example in order to get inputs you can use many different sensors, buttons, switches etc. and in order to show some outputs you can use motors, LEDs, relays etc. Thanks to the Ethernet adapter, 3G and WiFi shields, Galileo may communicate with external services and other devices, which are connected to Internet.

Our goal, in this article, is to understand how we may connect external devices to Galileo and how we may start developing something. From this prospective we will start with the most important part of the board for developers – with pins. Galileo 2 contains two sets of pins, which allow us to control inputs and outputs. In every project we are going to work with pins, that’s why their understanding is so important.

Usually we will work with the first set of pins – Digital pins. We may use this set in order to send outputs and receive inputs. You can use these pins for outputs in on/off mode. So, output voltage may have 0V or 5V there. Pay attention that all pins provide 5V voltage but Galileo board has a special switcher, which allows to set board in 3.3V mode in order to guarantee compatibility with some 3.3V shields. We will use just 5V voltage in our devices. If you use this set of pins for inputs, you will have the same range of values there – 0V or 5V.

image

So, we have 13 pins for digital outputs/inputs. But you can notice that some of these pins have a special mark “~”. This shows that we may use marked pins in order to send signals (outputs) in pulse mode. It allows us to emulate rheostat effect, when we have a way to send just n% of current per unit of time. You can use this effect in order to regulate brightness of LEDs or temperature in your apartment etc.

The second set of pins (A0-A5) is used for input only. But in this case it should be analogue input like data from thermometers, potentiometers, variable resistors etc.

image

This set of pins is important then we receive data, which describes more than two states. We will use these pins in more advantage projects.

Finally you can find some more pins like POWER, 5V, GND and so on. Some of these pins are used in order to control the board, some pins like 5V and VIN are used as source of current and GND pins are used for the ground.

So, right now we got some knowledge about pins and it’s time to look at development tools for Galileo.

If you already installed VS Extensions for Galileo, you can create projects in C++ based on Galileo Wiring App template. Frankly speaking, Microsoft already included much code there but it allows us to concentrate on device only. Right now we can work with Main.cpp files only. Probably, later, we will dig to code there but today I am going to use already prepared stuff. So, there is the following code in the main.cpp file:

#include "stdafx.h"
#include "arduino.h"

int _tmain(int argc, _TCHAR* argv[])
{
return RunArduinoSketch();
}

int led = 13;

void setup()
{
pinMode(led, OUTPUT);
}

void loop()
{
digitalWrite(led, LOW);
Log(L"LED OFF\n");
delay(1000);
digitalWrite(led, HIGH);
Log(L"LED ON\n");
delay(1000);
}

Here there are three functions only. Of course the application will begin with _tmain, which runs RunArduinoSketch functions. The main task of this function is calling setup function and putting loop function inside infinity loop. So, it’s clear that we can use setup function in order to initialize something there and we will use loop function in order to create our runtime logic.

We can see that setup and loop functions are already prepopulated. There is just one call from setup function – pinMode method, which informs our board that we will work with pin number 13. This pin is also connected to a led on the board but we can still use it for external stuff. loop method contains just six lines of code but the most important call there is digitalWrite call. This function allows two parameters like number of pin and state. LOW state shows that we should have 0V voltage and HIGH – 5V.

Let’s use existing code in the template but we will try to use external LED there. In order to do it we need the following components:

· LED – usually LED consumes voltage around 1.7V. So we should resist our 5V voltage there and in order to do it we need a resistor;

· Resistor – in order to resist our voltage we need 330 ohm resistor. It’s time to remember high school and Ohm’s low: I=U/R, where I is current (amperage), U is voltage and R is resistance. So, Galileo board has current in 10 milliamperes and voltage in 5V but we need to select a resistor, which will resist voltage to 1.7V: (5-1.7)/0.01=330. I used a resistor, which contains rings in the following sequence: orange, orange, brown and gold colors. In the next article I will describe how to select the right resistor;

· Breadboard – usually you will use this stuff in order to create a prototype of your final board and it’s good for testing and investigations. You can buy this one separately or find it in many kits;

· 2 wires

Finally, I created this:

image

In order to understand how it works, you need some information about the breadboard. You can see that our breadboard has several lines that are marked by numbers (from 1 to 30). Pins in each of these lines are connected. So, I used a yellow wire in order to connect pin on my board to pin in line 12 on my breadboard. So, when I put my digital pin to HIGH, current will be in line 12. The resistor connects line 12 and 21, so, we will have 1.7V voltage in line 21. It’s time to connect our LED – put the longer lead (anode) to the same line (21) and put the shorter lead (cathode) to line 23. To the same line (23) connect the blue wire.

Next time I will try to create some schemas but many developers (like me) don’t have knowledge in electrical schemas at all:)

Finally, you can connect yellow wire to digital pin 13 and blue wire to GND pin and just deploy the default application from Visual Studio. Your led should blink. In order to stop the process you can use telnet and tlist/kill commands there.

In the next article we will test more sensors and functions from API.

Advertisements

Written by Sergiy Baydachnyy

11/18/2014 at 8:55 PM

Posted in IoT

Tagged with

Internet of Things: My first experience with Galileo 2 (part 1)

with 2 comments

Published on MSDN Blog. Please, visit it for more great articles from Canadian DX team.

I didn’t feel so excited since that time, when I bought my first PC – ZX Spectrum. It was a new world, which required strong programming knowledge as well as ability to make research. And today I will open a door to one another new world, where I will try to integrate my programming knowledge with new types of hardware in order to build many new devices. Let’s begin.

First of all, in order to create a new hardware we need to buy some stuff like a board, sensors and wires. Because I have a good experience with Microsoft platform and Visual Studio, I have selected Intel Galileo 2 board, which is supported by Microsoft and it is compatible with Arduino boards, so you will able to find some stuff like sensors, shields, breadboards anywhere. At this time, I don’t have an idea about my future devices, so, I decided to buy a board as well as several starter kits. Finally, I bought my Galileo 2 board, SunFounder 37 modules Arduino Sensor Kit and Sunfounder Project Super Starter Kit.

clip_image002

I used Amazon in order to buy this stuff but you can use any online store. Additionally, I have visited Fry’s Electronics last week and I was too surprised that you may buy a board as well as many of these sensors and components there. There was a huge selection of kits for building own robots, sensors and wires. Probably, there is a special shop in Canada but I am a newcomer in Canada right now. So, please, recommend a good place here and it will help many Canadian developers.

Additionally, you will need a network cable, a microSD card (16 Gb should be enough) and microUSB to USB cable. The last one is used for all modern phones, so it should not be a problem but I forgot to buy a microSD, so I needed to find a nearest Staples in order to buy it. Pay special attention that in order to deploy your application, you need a network cable, which will connect your computer and your board.

Ok, right now, we have a board and some stuff, so we are ready to test the board. In order to use Windows as well as Visual Studio there, you will need to sign a special Windows Developer Program for IoT, which is available here: http://www.windowsondevices.com. You will need to use your Live ID, fill the registration form and right after your application is approved you will get access to Connect site, there you will be able to download all needed software.

In order to set up everything you will need three packages there: WIM image of the operation system, which you will deploy to your board (microSD card); apply-bootmedia.cmd file, which you will use to deploy the operation system; MSI package, which include some tools like Galileo Watcher and Visual Studio integration package.

In order to setup your PC you will need to launch the MSI package and enable Telnet features there. Later we will use Telnet in order to kill processes and get some information from the board. In order to enable Telnet features just go to “Program and Features” in the “Control Panel” and call “Turn Windows Features on or off” window.

clip_image004

Right now it’s time to setup your board. In order to do it you need to deploy Windows image to microSD card. Apply-BootMedia.cmd is able to do it for you. Just run the following command in the Command Prompt window (with Administrator permissions):

apply-bootmedia.cmd -destination {YourSDCardDrive} -image {.wimFile} -hostname mygalileo -password admin

Your card will be ready in 2-3 minutes.

clip_image006

Right now, we are ready to run something on Galileo. So, put your microSD card to the slot on the board, use the network cable to connect your Galileo board and turn on your board. Pay attention that Intel provides a universal power supply unit with different connectors. So you will able to use your board anywhere despite of voltage of the local system.

Usually it takes Galileo 2 2-3 minutes in order to start Windows there. During this process you will see blinking LED, which is marked as SD. When LED finishes blinking, your board is ready to communicate with your computer. The second way to understand that the board is ready – launch Galileo Watcher, which will show IP address of your board, MAC address, name and information about state of your board.

clip_image007

Using the Galileo Watcher you are able to monitor the state of your board as well as to launch some stuff like window in browser, which will show existing processes.

Pay attention that if you will use Visual Studio or Telnet in order to connect your board, you will need to provide the name and password there. We provided our password below and the default name is administrator. But, in many cases, you will need to provide the full name of the user like localhost\administrator or mygalileo\administrator, especially, if your computer is in a domain.

Finally, you may launch Visual Studio and create your first project for Galileo 2.

clip_image009

Microsoft provides a ready to go template, which we will discuss next time. Just try to start it on Galileo. If deployment is successful you will see that one more LED is blinking in infinity loop on your board.

In order to kill the process you will need to start Telnet and use the following commands:

· tlist – in order to see all existing processes

· kill <process ID> – in order to kill selected process

Probably I wrote enough for the first part. In the next article we will try to understand, what is Galileo and how to create a simple scenarios there.

Written by Sergiy Baydachnyy

11/07/2014 at 9:00 PM

Posted in IoT, Microsoft, Windows 8

Tagged with ,