Internet of Things: My first experience with Galileo (part 3)
Published on MSDN Blog. Please, visit it for more great articles from Canadian DX team.
In the previous post we developed our first device based on digital outputs from Galileo board. Today I am going to show emulation of analog outputs.
But before we will start to create something I want to return to question about electric schemas. Frankly speaking I am not sure if I want to learn all symbols related to schemas but at the same time we need a tool which will help us show design of our schemas. In order to do it I am going to use a free, open-source application called Fritzing. This application was developed by University of Applied Sciences in Potsdam, Germany. You can download the tool here: http://fritzing.org and it contains links to versions for operation systems like Windows, Linux and OS X.
It’s too easy to recognize needed components, put them to a breadboard and understand if your circuit is completed. Just drag and drop needed components from the parts section to breadboard and connect them in order to make a route.
I tried to create a schema for the previous example and you can see the result below:
If you are not able to find some components here you can make search in Internet. For example, I found a better look of Galileo board on Intel Community site. I just clicked the Mine tab and imported “.fzpz” file there.
So, I just used Fritzing in order to show our next example.
Here we are going to use RGB LED in order to show digital outputs in pulse mode. RGB LED is able to show different colors based on RGB schema (R – red, G – green, B – Blue) and it allows different voltage for each lead (the longest lead relates to the ground; the shortest lead, near the ground, relates to red; the shortest lead, on opposite side, relates to blue color; last one relates to green). As I mentioned in the previous post, we are able to emulate analog output using the digital pins with mark “~”. So, let’s connect each lead of RGB LED to appropriate pins (like the image shows) and complete the circuit. We will need more 330 Ohm resistors in order to resist our voltage.
In order to emulate analog output we should use analogWrite method instead of digitalWrite. This method allows to vary parameter from 0 to 255 instead of High/Low and looks very simple in our example. This code will help to show basic color with RGB LED. It will help you to test your circuit and later you can change the parameters of color method in order to generate different colors.
int _tmain(int argc, _TCHAR* argv)
const int redPin = 6;
const int greenPin = 5;
const int bluePin = 3;
void color(unsigned char red, unsigned char green, unsigned char blue)
color(255, 0, 0); // turn the RGB LED red
color(0, 255, 0); // turn the RGB LED green
color(0, 0, 255); // turn the RGB LED blue
In the next article I am going to talk about digital and analog inputs and we will create more examples there.