Sergiy Baydachnyy

Blog about technologies

Archive for December 2014

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

leave a comment »

When you are planning to build your own device you should think about power. In some cases it’s OK to connect your device to the nearest socket but for some projects it will not work. Just imagine a robot, which requires access to socket. So, we need to use independent sources of power like batteries.

In order to understand, which power supply is supported by Galileo, I visited Intel site and found the Galileo 2 datasheet there. According to it, Galileo 2 supports power supplies from 7 V to 15 V. So, in order to be power independent, simple 9V battery should be OK. So, I visited Fry’s Electronics and found the following components there:

clip_image002

Finally, I spent about 2 minutes in order to assemble all components together and check that everything works fine. Right now I have an independent power supply and I may build something like a robot or a flying drone.

In order to build a robot you need to work with motors. There are three general types of motors: DC motors, Stepper-motors and Servos.

DC motors work based on electromagnetism and are used to rotate an axle continuously. You cannot control angle of rotation, so, usually this type of motors is using to turn wheels.

Stepper-motors allow to rotate axle step by step in fixed number of degrees. You should use this type of motors if you need good accuracy there. A simple example of Stepper-motors is second hand in many battery-powered clocks.

Servos are very popular in robotics because they are used in order to create joints. They cannot turn continuously but they can move to fixed number of degrees in both directions with great accuracy. Therefore in order to realize legs, hands, fingers etc. you will use servos.

Today I decided to make some experiments with a DC motor. Usually, DC motors have their own power supply, because they require more voltage than Galileo might give. At the same time we need a way to manage the source of external voltage in order to start and stop our motor. Of course, we may use relay and some components in order to do it or special motor shields but the best way is using a small control chip. This is L293D chip, which allows to control up to two DC motors.

I don’t like special motor shields, because they require a lot of space, they are expensive and limited to 2-4 motors. So, if you need more motors, you need to buy one more shield etc.

In case of L293D, the chip is pretty small, cheap and you can put as many chips as needed on your breadboard.

In order to understand how the chip works, you need to find a datasheet in Internet. In general, the chip looks like this:

clip_image004

There are the following pins:

· EN, A pins – we should use them in order to control our DC motor. We may use them in order to start a motor turning right or left and stop it;

· Y pins – we should use them in order to connect our motor. Thanks to L293D, you may use motors with voltage up to 36V;

· VCC2 pin – it should be used for power supply. This power chip be used in order to start motor turning. So, in general, we will use external power supply there (up to 36V);

· VCC1 pin – the chip requires power as well in order to operate, so we will use it in order to provide power from external supply or from the board (5V is OK);

The chip allows to use up to two motors. Because I have just one motor, I will not use 3A, 3Y, 4A, 4Y, 3,4 EN in my example.

Therefore, in order to use one motor you should implement the following schema:

clip_image006

I decided to use there 5V power from my board in order to set up VCC1 because recommended voltage for VCC1 is between 4.5V and 7V. But you may use external power there as well, using some resistors there. In order to set up VCC2 I decided to use 9V battery, because my DC motor operates find under this condition. Finally, we should understand, how to operate the motor. In order to do it, you can use the following table:

clip_image008

So, if you want to start the motor, you may use the following code:

pinMode(en, OUTPUT);       
pinMode(a1, OUTPUT);
pinMode(a2, OUTPUT);

digitalWrite(en, HIGH);
digitalWrite(a2, HIGH);
digitalWrite(a1, LOW);

There en, a1 and a2 are numbers of digital pins, which you use in your Galileo in order to communicate with chip.

Finally, I got a working solution:

clip_image010

Written by Sergiy Baydachnyy

12/15/2014 at 7:54 PM

Posted in IoT

Tagged with

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

leave a comment »

Today I am going to continue my series about Galileo 2 board for beginners and I will discuss analog inputs. But before it, I want to discuss resistors as well.

We already used several resistors in our projects in previous posts but it’s still too hard to understand a value of particular resistor. There are two ways to do it. First of all we may use a multimeter device. You can buy it in any electronics shop. If you want to find a resistor in 330 ohm you need to set the dial of multimeter to 20 KOhm and touch red and black probes of multimeter to different legs of the resistor. You will see something around 0.330 for 330 ohm resistor.

image

At the same time it’s not easy to find a right resistor among many types of them. Here is my box with different types of resistors and there are about 4 resistors in 330 Ohm only. Probably I will spend up to one hour in order to check all of them.

image

So, in order to find a right resistor you need to use the second way – you need to understand color marks there. It’s not too hard. Usually, you will find resistors with 4 or 5 bands there. Based on these bands you can calculate resistance of a particular resistor. Here is a small table, which will help:

Color

1st Band

2nd Band

3rd Band

Multiplier

Tolerance

Black

0

0

0

1 Ohm

 

Brown

1

1

1

10 Ohm

1%

Red

2

2

2

100 Ohm

2%

Orange

3

3

3

1 KOhm

 

Yellow

4

4

4

10 KOhm

 

Green

5

5

5

100 KOhm

0.5%

Blue

6

6

6

1 MOhm

0.25%

Violet

7

7

7

10 MOhm

0.10%

Grey

8

8

8

 

0.05%

White

9

9

9

   

Gold

     

0.1

5%

Silver

     

0.01

10%

So, if you have resistor with 4 bands, you will not use 3rd band column. Just find the right number for the first band and the right number for the second band and combine them to the one number like <first number><second number>. And multiply this number by multiplier in order to get the final resistance. That’s why we need <Orange, Orange, Brown> forth band resistor in order to get 330 Ohm resistor.

Let’s start to create a project based on sensors, which can send inputs to our board. I wanted to use a flame sensor in the first project but today I woke up at 4 A. M. due to fire alarm in my building. Probably somebody forgot to turn off a stove or something like it but buzzer’s sound was terrible and I decided that it was a sign to stop my experiments with flame. So, we will use a photoresistor sensor.

If you have a modern car, you should have something like “Auto” mode for your lights. This mode allows to switch your light based on amount of external light. We will try to emulate the same behavior in our project. In order to do it we will create a circuit like this:

image

Depending on your kit, you will find many types of photoresistors there. In my case I have an analog sensor, which looks like as a separate board:

image

It has three legs, which should connect your sensor to power, ground and analog input pin on the board. You should check the datasheet for your sensor in order to understand how to connect it.

Since we are using an analog sensor, it should be connected to an analog pin. Photoresistor works like a variable resistor, which resists our voltage based on the amount of light. If you have a lot of light, the resistor will put down your voltage. Galileo converts the analog input to digital and it helps to understand the quantity of light. Here is a simple code, which you may use to test the project:

int led = 8;  
int photo = A0;

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

void loop()
{
int res=analogRead(photo);
if (res <= 700)
{
digitalWrite(led, LOW);
}
else
{
digitalWrite(led, HIGH);
}
delay(1000);
}

Galileo convertor will convert the analog input to a number between 0 and 1023. In this code I decided that if our number is smaller than 700 (resistor resists enough voltage), we will switch off our led because we have enough amount of light. If our resistor doesn’t resist enough voltage (it’s dark) we will switch on out led. Based on this example you are able to make many experiments with light and analog input.

Since we are using Visual Studio, it’s easy to launch our projects in a debug mode. When you will stop debugging, Visual Studio kills your process automatically. Visual Studio allows us to set breakpoints and review variables values etc. You may also use the Log method in order to print something to the output screen in the Debug mode. If you are launching your application without Debug mode, you need to kill your process using the Telnet as I mentioned in previous articles.

So, Visual Studio makes our life better but there still is a question: how to launch our projects just after startup of our operation system. It’s very important if you already created the final version of your project. Because we are using Windows, it’s easy to do in two steps. First of all you need to navigate to the following folder: \\mygalileo\c$\Windows\System32\Boot. You will need to enter your credentials there. On the next step, change autorun.cmd file and put one more command there, like start YourFolder\YourApp.exe. That’s all and your application will launch on the system startup.

Today I will finish my post. Next time I am planning to show more advanced projects.

Written by Sergiy Baydachnyy

12/01/2014 at 7:42 PM

Posted in IoT

Tagged with