Introduction: Ubuntu and the Arduino.

About: computoman.blogspot.com Bytesize articles instead of a trilogy in one post.
The Arduino is a great little micro-controller. Originally developed in Italy, ir became sort of an open source project. You can get just the micro-controller themselves are you can get a pre-fabricated setup with the needed interfaces and simple connections. Such brand names are Arduino uno, Osepp uno, and a host of others.  I have both the microcontrollers themselves and the Osepp uno. You can make everything from a simple light blinker to a robot. Only your imagination is your limitation. Hopefully we will give you something to start with.

The arduino has the ability to digitally turn things on or off, Check digitally whether something is on or off, and it can measure low analog voltages. That means you can use it for home automation, science projects,  automatic plant watering system, an autonomous vehicle, or laser harp and a host of other uses. Traditionally you could do this with a computer, but for the inexperienced that can be daunting.

Note: I have it working on Fedora 16 and 17 also.

Seeed now is carrying arduino products at a more resonable price for the daughteroards. Bought the Seeed ethernet adapter and it works on both the arduino and the osepps boards also.

Added information about using the Nexus 7 as a terminal.

Step 1: Getting Information for the Uno.

Step 2: How Do We Talk to It?

Micro-controllers only do what we ask them to do. Unfortunately they do not understand the spoken word yet. We need a way to translate what we want into what the Arduino can understand, The Arduino only understands numbers. So to do that we need a compiler. In fact to even make that easier we need a development environment. The Ide (Integrated development environment will take English like commands and store them in a .pde file. You load the .pde file into the IDE and then these commands can be translated into the ones and zeros the Arduino understands. this is called compiling. Once that is done the instructions can be sent or uploaded to the Arduino for running. (the ide has some great examples built in to start with and experiment.)

For ubuntu you will need several files to set up the ide. (sudo apt-get install and sudo apt-get -f upgrade if needed)

arduino-core
arduino
librxtx-java
libjna-java

The there are some settings that need to be changed. You want to be added to the dialout group and have rights to /dev/ttyUSB0
You will want to add settings to the arduino ide configuraton file  .arduno/preferences.txt.

for usb use:
change serial.port=com1 to serial.port=/dev/ttyUSB0

Add these two lines:
serial.debug_rate=9600
serial.download_rate=19200

After that you should be in business.

In (traditional) Gnome:

Applications > Programming > Arduino IDE

Step 3: Your First Project.

Unless you have built your own Arduino board or using a very early version of the Arduino, you should have a built in led to show off the fruits of this first project. It is also a way to make sure your board is working. You will want to load in the example called blink.

Note: for the board you want to use the arduino uno with the arduino board. With the Osepp, you want to use the with atmel328

Here is the code in case you do not have the examples.

Blink.pde:
[code]
/*
 * Blink
 *
 * The basic Arduino example.  Turns on an LED on for one second,
 * then off for one second, and so on...  We use pin 13 because,
 * depending on your Arduino board, it has either a built-in LED
 * or a built-in resistor so that you need only an LED.
 *
 * http://www.arduino.cc/en/Tutorial/Blink
 */

int ledPin = 13;                // LED connected to digital pin 13

void setup()                    // run once, when the sketch starts
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
}

void loop()                     // run over and over again
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
}
[/code]

So run the IDE program
Choose your board.
Choose the port to use.
You should not have to do this again unless your hardware changes.
Load Blink.pde
Compile it.
Upload it to the board.
Watch the light blink.

Not spectacular, but it is an awesome start!

On to bigger and better things.

Step 4: Fritzing.

If you want to make things easier to set up and document, I highly recommend Fritzing. It has many microcontrollers and electronic parts in it's libraries.fritzing.org

Step 5: Xcircuit

This is another electronics drawing  program known as Xcircuit, I found in the linux repository. Should be available for MSWindoows machines also. Looks interesting.

Step 6: Add-ons.

You can get add on boards to make your Arduino more functional. Seeed (available at Radio Shack and other fine companies) makes several boards that are price competive.)   I bought the Seeed ethernet ad-on board for half the price of the Arduino option, but it was a bit trimed down such as no card slot. The board aso works with the Osepp arduino clones. That is what we used for this project.

I wanted a way to have a web sever up when I needed to bring the regular web server down.  The arduino was the perfect choice. I just took the web server example from the Arduino IDE and commented out the code that was not needed (but could be resued later) and added the code that was needed i.e.

...
          client.println("<center>");
         
          client.println("<h1>Your server name<h1>");
          client.println("<hr");
          client.println("<br />");
         
          client.println("<h2>Bear with us as the server is under reconstruction!</h2>");
          client.println("<img src='http://www.seemyheart.org/wp-content/uploads/2013/06/Website_Under_Construction.gif' height=500 width=500 />");
          client.println("</center>");
...

Code is attached.

Now I have a way to keep a web presense if I need to alter the server for a short period of time without the web page being up.

Step 7: Get Video From Your Arduino.

With just a three line interface with two resisters, we output video to a composite monitor. Actually, we used an old B&W tv with a composite video input option, You can get more information at: http://playground.arduino.cc/Main/TVout.

Note:You will have to download and install the tv.out libary. The site has all the details.

-------------------------------------------------------------

#include <TVout.h>

TVout TV;
unsigned char x, y;

void setup ( )
{
  TV.start_render( _NTSC );
}

void loop ( )
{
  TV.clear_screen ( );
  TV.print_str ( 10, 10, "I love" );
  TV.print_str ( 10, 20, "electronics," );
  TV.print_str ( 10, 30, "computers, and" );
  TV.print_str ( 10, 40, "microcontrollers!" );
  TV.delay ( 60 );
}

Step 8: Program in Tiny Basic.

You can run basic programs on the arduino, but you can not save them on the original version. More information at:
http://ec2-122-248-210-243.ap-southeast-1.compute.amazonaws.com/mediawiki/index.php/Arduino_Basic#The_project_sketch_.2F_source_file

You can ither install an rs232 converter and seriak terminal or you can use the serial monitor of the host computer with the Arduino IDE.


At the time of this writing I found a small bug in the code. (There may be others)
------------------------------------------------------------/
// TinyBASIC.cpp : An implementation of TinyBASIC in C
//
// Author : Mike Field - hamster@snap.net.nz
//
// Based on TinyBasic for 68000, by Gordon Brandly
// (see http://members.shaw.ca/gbrandly/68ktinyb.html)
//
// which itself was Derived from Palo Alto Tiny BASIC as 
// published in the May 1976 issue of Dr. Dobb's Journal.  
// 
// 0.03 21/01/2011 : Added INPUT routine 
//                 : Reorganised memory layout
//                 : Expanded all error messages
//                 : Break key added
//                 : Removed the calls to printf (left by debugging)

#ifndef ARDUINO
#include "stdafx.h"
#include <conio.h>
#endif 
f                                 //<<<<<<<<<<<<<< remove the letter "f"
// ASCII Characters
#define CR	'\r'
#define NL	'\n'
#define TAB	'\t'
#define BELL	'\b'
#define DEL	'\177'
#define SPACE   ' '
#define CTRLC	0x03
#define CTRLH	0x08
#define CTRLS	0x13
#define CTRLX	0x18

typedef short unsigned LINENUM;

Step 9: Blink an Led. (in Progress)

The next several steps are to show you how to connect to the arduino in the most basic ways. You certainly can do many more complicated things.

This step shows you how to turn on and off an external led. With addtional circuitry for safety, you could do the same for applicances and lighting. The basic of home automation.

<code>
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 7;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);    
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}
</code>

Step 10: A Button and an Led. in (progress)

Used a button to turn on an led. (R2 is required to keep the arduino safe some people say 10k ohms is better.).So now you have external digital input to control the led.

Code:

/*
  Use a button to turn on a light.
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 7;
int button = 6;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(button, INPUT);
  pinMode(led, OUTPUT);    
}

// the loop routine runs over and over again forever:
void loop() {
 if (digitalRead(6) == 0) {
   digitalWrite(7,1);
 }
 else {
   digitalWrite(7,0);
 }

}

Step 11: Pulse Width Modulation (PWM)

Varying the brightness of an led. (pulse width modulation). Very important for controlling say the speed of motors. A great first step into robotics mobility.

/*
 Pulse width modulation test
 A
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 5;
int button = 6;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(button, INPUT);
  pinMode(led, OUTPUT);    
}

// the loop routine runs over and over again forever:
void loop() {
 if (digitalRead(button) == 0) {

   analogWrite(led, 255);
 }
 else {
   analogWrite(led, 64);
 }
 
}

Step 12: Analog InPut (in Progress)

To measure the resistance of a variable resistor. Read the results on the pc monitor. With additional ccircuitry such as an opamp (operational amplifier) you could use the arduino for medical testing such as temperature reading, heart rate monitor and et cettera.

Code:
/*
  ReadAnalogVoltage
  Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
 
 This example code is in the public domain.
 */


// the setup routine runs once when you press reset:
voidsetup(){
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
voidloop(){
  // read the input on analog pin 0:
  int sensorValue =analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue *(5.0/1023.0);
  // print out the value you read:
  Serial.println(voltage);
}

Step 13: Usng the Nexus 7 As a Terminal.

If you want to use the Nexxus as a terminal see: https://www.instructables.com/id/Nexus-7-and-the-Arduino/

Mote:: All connections are to a standard Arduino board.  This instructable is for users very familiar with the Arduino boards. If you are a novice, you may want to get additional help.  More In the following frames are other simple projects to learn with some examples aka basic building blocks to play with. Some of frames  are still under construction or to be completely revised..

1.  EMF (Electomotive force) field reader
2. Capacitive reader
3. Temperature reading
4. Flood detection.

Step 14: Emf Detection.

Test anything that might be emitting EMF. A bug detector? Mostly tongue in cheek, but you could check in on your tin foil hat.

<code>
// EMF Detector for LED Bargraph v1.0
// 5.12.2009
// original code/project by Aaron ALAI - aaronalai1@gmail.com

#define NUMREADINGS 15 // raise this number to increase data smoothing

int senseLimit = 15; // raise this number to decrease sensitivity (up to 1023 max)
int probePin = 5; // analog 5
int val = 0; // reading from probePin


// variables for smoothing

int readings[NUMREADINGS];                // the readings from the analog input
int index = 0;                            // the index of the current reading
int total = 0;                            // the running total
int average = 0;                          // final average of the probe reading


void setup() {


  Serial.begin(9600);  // initiate serial connection for debugging/etc

  for (int i = 0; i < NUMREADINGS; i++)
    readings[i] = 0;                      // initialize all the readings to 0
}

void loop() {

  val = analogRead(probePin);  // take a reading from the probe

  if(val >= 1){                // if the reading isn't zero, proceed

    val = constrain(val, 1, senseLimit);  // turn any reading higher than the senseLimit value into the senseLimit value
    val = map(val, 1, senseLimit, 1, 1023);  // remap the constrained value within a 1 to 1023 range

    total -= readings[index];               // subtract the last reading
    readings[index] = val; // read from the sensor
    total += readings[index];               // add the reading to the total
    index = (index + 1);                    // advance to the next index

    if (index >= NUMREADINGS)               // if we're at the end of the array...
      index = 0;                            // ...wrap around to the beginning

    average = total / NUMREADINGS;          // calculate the average

    Serial.println(val); // use output to aid in calibrating
  }
}
</code>

Step 15: Touch Sensor.

Touch sensor or field sensor. gret for using on doors or near something that should not be touched.


<code>
#include <CapacitiveSensor.h>

/*
 * CapitiveSense Library Demo Sketch
 * Paul Badger 2008
 * Uses a high value resistor e.g. 10 megohm between send pin and receive pin
 * Resistor effects sensitivity, experiment with values, 50 kilohm - 50 megohm. Larger resistor values yield larger sensor values.
 * Receive pin is the sensor pin - try different amounts of foil/metal on this pin
 * Best results are obtained if sensor foil and wire is covered with an insulator such as paper or plastic sheet
 */


CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add wire, foil
CapacitiveSensor   cs_4_5 = CapacitiveSensor(4,5);        // 10 megohm resistor between pins 4 & 6, pin 6 is sensor pin, add wire, foil
CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);        // 10 megohm resistor between pins 4 & 8, pin 8 is sensor pin, add wire, foil

void setup()                    
{

   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   Serial.begin(9600);

}

void loop()                    
{
    long start = millis();
    long total1 =  cs_4_2.capacitiveSensor(30);
    long total2 =  cs_4_5.capacitiveSensor(30);
    long total3 =  cs_4_8.capacitiveSensor(30);

    Serial.print(millis() - start);        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug windown spacing

    Serial.print(total1);                  // print sensor output 1
    Serial.print("\t");
    Serial.print(total2);                  // print sensor output 2
    Serial.print("\t");
    Serial.println(total3);                // print sensor output 3

    delay(10);                             // arbitrary delay to limit data to serial port 
}


</code>

Step 16: Temp Sensor.

Temp sensor. Isit too hoo for you or your equipment, so now you can tell. Using an ice cube  will gve you a good test of the unit.Could also be the start of a sous vide machine.

<code.>

//declare variables
float tempC;
int tempPin = 0;

void setup()
{
Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
}

void loop()
{
tempC = analogRead(tempPin);           //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0;  //convert the analog data to temperature
Serial.print((byte)tempC);             //send the data to the computer
delay(1000);                           //wait one second before sending new data
}

</code>

Step 17: Flood Sensor.

This is a short circuuit sensor that could easily be used to detect where there is liquid such as wter flowing into the rool. Did a pipe break or a window break during a storm.

<code>
 /* Flood Sensor
 
 This sketch Display message when water (anything conductive) bridges the gap in the sensor.
  
   created 02/09/09
   by n00b
 

 */
 
 const int floodSensors = 2;     // the number of the Flood Sensor pin

 // variables will change:
 int floodSensorState = 0;         // variable for reading the floodSensors status

 void setup() {
   // initialize the flood Sensor pin as an input:
   pinMode(floodSensors, INPUT);    
   Serial.begin(9600);
 }

 void loop(){
   // read the state of the flood Sensor value:
   floodSensorState = digitalRead(floodSensors);

   // check if the flood Sensor is wet.
   // if it is, the floodSensorState is HIGH:
   if (floodSensorState == HIGH) {    
     // turn LED on:   
    Serial.println(floodSensorState); 
    Serial.println("Warning there is a flood");
   }
   else {
     // Not flood:
     // Serial.println(floodSensorState);
    // Serial.println(floodSensorState);
   }
 }
 
</code>

Step 18: Ping Sensor.

Use pin 7 for data.

/* Ping))) Sensor
 
   This sketch reads a PING))) ultrasonic rangefinder and returns the
   distance to the closest object in range. To do this, it sends a pulse
   to the sensor to initiate a reading, then listens for a pulse
   to return.  The length of the returning pulse is proportional to
   the distance of the object from the sensor.
    
   The circuit:
    * +V connection of the PING))) attached to +5V
    * GND connection of the PING))) attached to ground
    * SIG connection of the PING))) attached to digital pin 7

   http://www.arduino.cc/en/Tutorial/Ping
  
   created 3 Nov 2008
   by David A. Mellis
   modified 30 Aug 2011
   by Tom Igoe
 
   This example code is in the public domain.

 */

// this constant won't change.  It's the pin number
// of the sensor's output:
const int pingPin = 7;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
}

void loop()
{
  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
 
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
 
  delay(100);
}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}

Step 19: Servo

Use pin 9 for data.


 // Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.


#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}
 
 
void loop()
{
  for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Step 20: Pir Sensor

Use pin 2 for data.

/*
 * PIR sensor tester
 */
 
int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
 
void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
 
  Serial.begin(9600);
}
 
void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
    digitalWrite(ledPin, LOW); // turn LED OFF
    if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}

Step 21: Arduino Plus Ethernet Adapter.

If your arduino has an ethernet adapter you can try this setup. Just connect to http://192.168.1.17 from another system on the network to turn on or turn off an led. Home automation basic idea to start with.

<code>
/*
Web Server
A simple web server
Circuit:
* Ethernet shield attached to pins oA, 0B 0C, 0D
*/
//——————————————————————————————————-
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
byte mac[] = {0×90, 0xA2, 0xDA, 0x0D, 0×48, 0xD3 };
// The IP address will be dependent on your local network:
// assign an IP address for the controller:
IPAddress ip(192,168,1,17);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255, 255, 255, 0);
// Initialize the Ethernet server library with the port you want to use.
EthernetServer server(80);
String readString;
//——————————————————————————————————-
//————————————————-
// Any extra codes for Declaration :
// Declare Pin 8 as an LED because thats what we will be connecting the LED to.You could use any other pin and would then have to change the pin number.
int led = 8;
//————————————————-
//——————————————————————————————————-
void setup()
{
//————————————————-
// Extra Set up code:
pinMode(led, OUTPUT); //pin selected to control
//————————————————-
//——————————————————————————————————-
//enable serial data print
Serial.begin(9600);
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.print(“Server is at “);
Serial.println(Ethernet.localIP());
Serial.println(“LED Controller Test 1.0″);
}
//——————————————————————————————————-
//——————————————————————————————————-
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client)
{
Serial.println(“new client”);
while (client.connected())
{
if (client.available())
{
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100)
{
//store characters to string
readString += c;
//Serial.print(c);
Serial.write(c);
// if you’ve gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
//if HTTP request has ended
if (c == ‘\n’) {
Serial.println(readString); //print to serial monitor for debuging
//——————————————————————————————————–
// Needed to Display Site:
client.println(“HTTP/1.1 200 OK”); //send new page
client.println(“Content-Type: text/html”);
client.println();
client.println(“<HTML>”);
client.println(“<HEAD>”);
//——————————————————————————————————–
//————————————————-
// what is being Displayed :
client.println(“<TITLE>Home Automation</TITLE>”);
client.println(“<center>”);
client.println(“</HEAD>”);
client.println(“<BODY>”);
client.println(“<H1>Home Automation</H1>”);
client.println(“<hr />”);
client.println(“<center>”);
client.println(“<a href=\”/?lighton\”\”>Turn On Light</a>”);
client.println(“<br />”);
client.println(“<br />”);
client.println(“<a href=\”/?lightoff\”\”>Turn Off Light</a><br />”);
client.println(“</BODY>”);
client.println(“</HTML>”);
delay(1);
//stopping client
client.stop();
//————————————————-
// Code which needs to be Implemented:
if(readString.indexOf(“?lighton”) >0)//checks for on
{
digitalWrite(8, HIGH); // set pin 4 high
Serial.println(“Led On”);
}
else{
if(readString.indexOf(“?lightoff”) >0)//checks for off
{
digitalWrite(8, LOW); // set pin 4 low
Serial.println(“Led Off”);
}
}
//clearing string for next read
readString=”";
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println(“client disonnected”);
}
}
}
}
}
}
</code>

Step 22: Standalone Arduino.

Building a stanalone arduino is like being a shadetree mechanic, but wihtout all the grease.  If you have the original Arduino board with the removable dip Atmega328 chip you can very easily create your own standalone Arduino after programming the atmega chip while socked on the board.   In this case, I purchased a single atmega328 chuip added a 16 mhz resnator and a 10k resistor to make the basic circuit. Using a crystal and two capacitors is more accurate especially for communication circuits. You can get prettier schmatics on line. With the aruino chip removed, you can even program it from the standalone circuit.  http://arduino.cc/en/Tutorial/ArduinoToBreadboard has more information about setting up a standalone arduino.

Simple blinky routine.

<code>
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);    
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}
</code>

Step 23: Parallel Port Programmer

Notice: try this at your own risk. If you have a pre-usb computer
system, you can still program your Arduino (with built in boot-loader). Stand alone Arduino chips are much cheaper than purchasing the retail board. There are two ports to consider. First is the parallel port and the second is the pin-out on the Arduino.

You will need three resistors. Two 470 and one 220 ohm resistors go build the circuit. Parallel connector with a 470 ohm resistor soldered to pin 1. Solder a 220 ohm resistor to pin 11 of the connector. Solder, in order, the three wires of one of the cables to the resistor on pin 11 (which goes to pin 18 on the Atmega8), to the resistor on pin 1 (which goes to pin 19 on the Atmega8), and directly to pin 16 (which goes to the reset, pin 1). Parallel connector with two of the three wires of a cable soldered to pins 11 and 1, respectively. Solder the middle wire of the second cable to the resistor on pin 2 (which goes to pin 17 on the Atmega8), and one of the other wires to pin 18 (which goes to ground). (The third wire is not used and may be cut short).

Once you have your circuit built, you will need to find the hex file (we
used the blink demo for compiling) for sending to the Arduino. If you use the gui environment, the file will be in a build directory under /tmp.

After you install uisp, you should be able to install the binary file with:

$ uisp -dprog=dapa -dpart=ATmega8 if=Blink.cpp.hex -dlpt=0x378 --erase --upload

Step 24: Ethernet Shield + Bare Arduino

In progress Still have to set up power/ground lines and the crystal/

Going to try and experiment to hook a bare arduino to an ethernet board.
According tp the documentation for the board only six intelligent pins are connected directly. We will see how true that is.

D2 - Connects the INT pin of the W5100
D3 - Contral the reset of the W5100 D10 - Used for SPI Chip Select D11 - Used for SPI MOSI D12 - Used for SPI MISO D13 - Used for SPI SCK

Step 25: Nirf and the Standalone Arduino

In progress:

Some people recommend a 100 nf capacitor between +5 and ground.

Incase you do not have a standalone chip, I have added other schematics.

Step 26: Add a New Controller

Compatible to computer networks.

What is the ESP8266?

The ESP8266, is a cheap WiFi module which you can address using the UART protocol. It’s been featured on Hackaday and other DIY electronics blogs very recently, and lots of DIY electronics tinkers are very excited at the doors this module opens for their projects. The module is:

Small Footprint

Easy to integrate with (using UART)

Takes care of all other overheads for getting WiFi up-and-running (TCP/IP Stack etc…)

. . . and, perhaps more importantly than all the other factors, very cheap – it can be purchased from China in a quantity of one for less than £4 !

There are no market equivalents for the DIY community – the XBee has been a popular choice for adding WiFi to DIY projects up until now, but the ESP8266 module is close to one tenth the price making it easily accessible for all types of low cost applications.

The ESP8266 is the name of the chip it’s self manufactured by a company called Espressif, but it is sold in modules manufactured in China which look as seen below,

The module can be addressed using a series of AT commands. These are simple commands sent UART at 115200 baud. For example, once the module is wired up, you can send the command

AT+RST will perform a software reset on the device. AT+CWLAPwill displat all of the currently available WiFi networks etc. – simple enough!

How do I set up the ESP8266 Module?

Here is a simple pin-out for the module (the pin numbers are defined in the table

and relate to the image):

Pin Number Pin Function Pin Number Pin Function 1RX 5GPIO2 2VCC6CH_PD 3 GPIO0 7 GND 4RST 8TX

Note: Under normal operation Pin 6 (CH_PD) should be tied high (3V3) to ensure correct operation

As such, you can easily wire up the module to an Arduino or just a simple USB to serial converter and start sending AT commands (Remember: RX on the module joins to TX on the connection device and vice versa!).

What are the drawbacks of using this module?

As we’ve seen above, this is shaping up to be a very good value-for-money solution for adding WiFi capabilities to DIY projects, so what are the limitations.

The module is rather ‘power thirsty’. The current supplied via USB to an Arduino is barely enough to power this module. Other websites have recommended that you should have easily 1A available, but I have not measured this myself. This makes integrating the module slightly more tricky as a second, separate voltage regulator is required and it also rules out any battery powered projects.

It is temperamental – I’ve had a chance to play with this module, and although it works most of the time, all of the sample code I have found provides far from a solid solution – there are plenty of quirks to using it.

Code examples: https://github.com/esp8266/Arduino/archive/esp826...

Adding support for the esp8266 in the arduino ide 1.6.4 Depending on the speed of your internet connection how long it will take

Installing with Boards Manager

Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager.

We have packages available for Windows, Mac OS, and Linux (32 and 64 bit). The 1.7.3 version did not have this option.

Install Arduino 1.6.4 from the Arduino website

Start Arduino and open Perferences window.Enter http://arduino.esp8266.com/package_esp8266com_ind... into Additional Board Manager URLs field.

You can add multiple URLs, separating them with commas.

Open Boards Manager from Tools > Board menu and install esp8266 platform (and don't forget to select your ESP8266 board from Tools > Board menu after installation).