Intel Edison First Project

Well as the title describes, this is my first project using Intel Edison with Arduino expansion board and Grove starter kit plus gen 2. I got this amazing package from Instructables for free and now I’m presenting my first project. I developed this project under Windows, so all the steps are for windows. Other OS have similar steps.

Description

For this project I tried to do something related to IoT, so I made a temperature monitor for any application you can imagine, like a green house. So I used a temperature sensor (thermistor) from Grove kit, an Liquid Crystal Display also from Grove kit, connected to an Intel Edison and the Arduino break out through its shield.

Intel Edison reads the temperature and if it gets under a pre-programmed value it sends you an email using a Gmail account.

Materials

For this project I needed the following materials:

  • (1) Intel Edison + Arduino breakout board (photo 1)
  • (1) Grove starter kit plus gen 2 (photo 2)
  • (2) USB micro-B cable (photo 3)
Intel Edison plus Arduino breakout board
Photo 1
Grove Starter Kit Plus
Photo 2
USB Cable
Photo 3

 

Software

Intel Software

For the installation process I needed to follow the instructions from Intel web page. The following links explain in detail about the process:

So go ahead and follow the instructions.  Once you have the driver for windows, Arduino IDE for Edison, you have configured WiFi and you can continue.

Grove Libraries

Also, after installing the only the Arduino IDE for the Edison I had to add the Grove library found here.

On the GitHub page click on the “Download ZIP” button as you can see colored in red on the next picture.

Grove GitHub page
Grove GitHub page

Open your Arduino IDE, go to menu “File >> Preferences” and on the preferences window take a note were is your Arduino sketch folder, for example:

Arduino preferences
Arduino preferences

 

Note that my sketch folder may differ from yours, that is because I have changed mine. Keep in mind where is yours.

Now locate the ZIP file containing the Grove libraries and examples and decompress them to your Arduino sketch directory.

If your Arduino was open, close it and open it again, by now you can see several files under “File >> Sketches”, “File >> Examples >> Grove_LCD_RGB_Backlight” and “Program >> Import library”.

Other software

Additional software, not necessary for this project, to access to Edison files remotely (windows):

  • PuTTy: Download putty.exe, no installation needed
  •  WinSCP: Download latest version of installation packages.

And finally some useful software tools neither necessary for this project:

  • Python 2.7.x: Only to try some code in your machine if you want. Edison come with python build in it.
  • Notepad++: An improved editor that supports some programming languages. I prefer to code here and then save it and test it.

This software is just to make your life easier.

Getting started!

Now its time to test that everything is working, so we can load the very basic example to make LED 13 to blink, so just open the file under “File >> Examples >> 01.Basics >> Blink“. Check that Edison board is selected under “Tools >> Board” menu and the proper COM port is selected in “Tools >> Serial port” then load the sketch to the board.

As result you should see an LED blinking as the next image.

Blinking an LED
Blinking an LED 2 second cycle

Grove Starter Kit Plus

Now it is time to move on and it is time to play with the RGB LCD, temperature sensor and the buzzer from our Grove Starter Kit Plus. Take and connect the components as showed on the next pictures.

Grove components required
Grove components required
Connections
Connections

Pay special attention to connections, temperature sensor is on “A0”, buzzer is on “D3” and the RGB LCD could be connected in any “I2C” slot.

Now lets test every component. For this part we will use only examples and I am going to try to explain the basics behind them.

Temperature Sensor

Open “File >>  Sketches >> Grove_Temperature_Sensor“, you will see the next code:

[cpp]

// demo of Starter Kit V2.0 – Grove Temperature Sensor
//

const int pinTemp = A0; // pin of temperature sensor

float temperature;
int B=3975; // B value of the thermistor
float resistance;

void setup()
{
Serial.begin(9600);
}

void loop()
{

int val = analogRead(pinTemp); // get analog value
resistance=(float)(1023-val)*10000/val; // get resistance
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15; // calc temperature
Serial.println(temperature);

delay(1000); // delay 1s
}
[/cpp]

Now upload the sketch and press serial monitor button to the temperature.

Buzzer

Now it is time to make some noise, open the sketch “File >> Sketches >> Grove_Buzzer”, look at the code:

[cpp]
/* Melody
* (cleft) 2005 D. Cuartielles for K3
*
* This example uses a piezo speaker to play melodies. It sends
* a square wave of the appropriate frequency to the piezo, generating
* the corresponding tone.
*
* The calculation of the tones is made following the mathematical
* operation:
*
* timeHigh = period / 2 = 1 / (2 * toneFrequency)
*
* where the different tones are described as in the table:
*
* note frequency period timeHigh
* c 261 Hz 3830 1915
* d 294 Hz 3400 1700
* e 329 Hz 3038 1519
* f 349 Hz 2864 1432
* g 392 Hz 2550 1275
* a 440 Hz 2272 1136
* b 493 Hz 2028 1014
* C 523 Hz 1912 956
*
* http://www.arduino.cc/en/Tutorial/Melody
*/

int speakerPin = 3; // Grove Buzzer connect to D3

int length = 15; // the number of notes
char notes[] = "ccggaagffeeddc "; // a space represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 300;

void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}

void playNote(char note, int duration) {
char names[] = { ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘a’, ‘b’, ‘C’ };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

// play the tone corresponding to the note name
for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}

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

void loop()
{
for (int i = 0; i < length; i++)
{
if (notes[i] == ‘ ‘)
{
delay(beats[i] * tempo); // rest
}
else
{
playNote(notes[i], beats[i] * tempo);
}

// pause between notes
delay(tempo / 2);
}
}
[/cpp]

Upload this sketch and you will hear part of the “twinkle twinkle little star” song.

RGB LCD

Now it is time to test the RBG LCD, open “File >> Sketches >>  Grove_RGB_Backlight_LCD >> HelloWorld“. This file contains interesting things like set the backlight color, display “hello, world!” and print the number of seconds since it has been working. Take a look at the code:

[cpp]
/*
Hello World.ino
2013 Copyright (c) Seeed Technology Inc. All right reserved.

Author:Loovee
2013-9-18

Grove – Serial LCD RGB Backlight demo.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;

const int colorR = 255;
const int colorG = 0;
const int colorB = 0;

void setup()
{
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);

lcd.setRGB(colorR, colorG, colorB);

// Print a message to the LCD.
lcd.print("hello, world!");

delay(1000);
}

void loop()
{
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);

delay(100);
}

/****************************************************************
END FILE
****************************************************************/
[/cpp]

Now lets take a look to see what is going on.

//Video

Edison Linux Scripting.

The Intel Edison contains a basic Linux Operative System based on Yocto project. This Linux flavor contains among other things Python, SSH, among others.

We will start making a little Python script. So before we can start we need to login using a SSH client such as PuTTY. For this step we need to know in which Serial COM port is the Edison connected, so first look at your “Device Manager” under “COM and LTP Ports”, that in my case are COM5 and COM6. In this case COM6 is the COM port for the Arduino side, so the right one is COM5 for connecting to the Linux side as showed in the image.

serial ports

Open PuTTY and configure as shown in the next image.

putty config

Click open and a new window will appear.

ssh connection

To login, if it is your first time, type root as username and just hit enter when it ask you the password, or provide your credentials.

To create a Python script we will use vi, a basic text editor, type without “$” symbol:

[cpp]
$ vi myscript.py
[/cpp]

myscript

vi editor

In order to start writing your code press “i key” on your keyboard and then type the following code:

[python]
print "Hello world!"
print "My name is Edison…"
[/python]

python code

To exit and save your code first you need to exit “insert mode” pressing “Esc key” and then press “:wq” and hit Enter.

exit vi

To run your script just type in the console without “$” symbol:

[cpp]
$ python myscript.py
[/cpp]

In the console will appear the following text:

running script

WORKING IN PROGRESS!!

Whats next?

  • An advance python script
  • From Arduino make a system call and execute a script
  • Write a file on the SD
  • Read temperature and set an alarm
  • Send an email when temperature alarm rises

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s