Difference between revisions of "Implementing Arduino using Generic Serial Device"

From LinuxMCE
Jump to: navigation, search
Line 37: Line 37:
 
  #include <Ethernet.h>
 
  #include <Ethernet.h>
 
  int switchPin = 2;
 
  int switchPin = 2;
  int LEDpin = 5;       //LED set to pin 5
+
  int LEDpin = 5; //LED set to pin 5
 
  int x;
 
  int x;
 
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //must give WIZnet a MAC
 
  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //must give WIZnet a MAC
  byte ip[] = { 192, 168, 80, 129 };       //must configure WIZnet IP
+
  byte ip[] = { 192, 168, 80, 129 }; //must configure WIZnet IP
  EthernetServer server = EthernetServer(69);       //TCP port the server is listening on
+
  EthernetServer server = EthernetServer(69); //TCP port the server is listening on, I'm using port 69, but you could use any
            //I'm using telnet, but you could use any
+
 
  void setup()
 
  void setup()
 
  {
 
  {
 
   Ethernet.begin(mac, ip);
 
   Ethernet.begin(mac, ip);
 
   server.begin();
 
   server.begin();
   Serial.begin(9600);       //for troubleshooting purposes (not needed)
+
   Serial.begin(9600); //for troubleshooting purposes (not needed)
 
   pinMode(LEDpin, OUTPUT);
 
   pinMode(LEDpin, OUTPUT);
   pinMode(switchPin, INPUT);                                         // sets the digital pin as input to read switch
+
   pinMode(switchPin, INPUT);                                   // sets the digital pin as input to read switch
 
  }
 
  }
 
  void loop () {
 
  void loop () {
  EthernetClient client = server.available();     //client connects to server
+
  EthernetClient client = server.available(); //client connects to server
  if (client){     //if connection present
+
  if (client){ //if connection present
   x = client.read();     //read information coming from server
+
   x = client.read(); //read information coming from server
   Serial.println(x);}     //print to serial (troublshooting only)
+
   Serial.println(x);} //print to serial (troublshooting only)
  if (x == 49){     //if information sent is a zero
+
  if (x == 49){ //if information sent is a zero
   digitalWrite(LEDpin, LOW);}     //turn of LED
+
   digitalWrite(LEDpin, LOW);} //turn of LED
  else if (x == 48){           //if information sent is a one
+
  else if (x == 48){ //if information sent is a one
   digitalWrite(LEDpin, HIGH);}     //turn on LED
+
   digitalWrite(LEDpin, HIGH);}         //turn on LED
  else if (x == 2){           //if information sent is a two
+
  else if (x == 2){ //if information sent is a two
   digitalWrite(LEDpin, HIGH);     //blink the LED
+
   digitalWrite(LEDpin, HIGH); //blink the LED
 
   delay(500);
 
   delay(500);
 
   digitalWrite(LEDpin, LOW);
 
   digitalWrite(LEDpin, LOW);
Line 67: Line 66:
 
  if (digitalRead(switchPin) == 1){
 
  if (digitalRead(switchPin) == 1){
 
   Serial.println("Button has been pressed " );
 
   Serial.println("Button has been pressed " );
   server.write("Button has been pressed ");}                           // Read the pin and display the value
+
   server.write("Button has been pressed ");}                   // Read the pin and display the value
 
  }
 
  }
  

Revision as of 19:31, 3 September 2012

Version Status Date Updated Updated By
710 Unknown N/A N/A
810 Unknown N/A N/A
1004 Working 3th September 2012 Daballiem0
1204 Unknown N/A N/A
1404 Unknown N/A N/A
Usage Information

General Info

Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.

Arduino can sense the environment by receiving input from a variety of sensors and can affect its surroundings by controlling lights, motors, and other actuators. The microcontroller on the board is programmed using the Arduino programming language (based on Wiring) and the Arduino development environment (based on Processing). Arduino projects can be stand-alone or they can communicate with software running on a computer (e.g. Flash, Processing, MaxMSP).

Arduino uno test.jpg

Arduino Uno - 1004 Setup

Prepare the Arduino Uno;

Shopping list:

Arduino Uno Ethernet Shield IDE installed on computer

sketch to upload to Arduino

/*
 * Arduino LMCE interlink
 *
 * A basic example displaying the ability of LinuxMCE
 * to control an LED on an Arduino with
 * an ethernet shield.
 * 
 * Han van Akker
 * http://linuxmce.org
 */
#include <SPI.h>
#include <Ethernet.h>
int switchPin = 2;
int LEDpin = 5;						//LED set to pin 5
int x;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };		//must give WIZnet a MAC
byte ip[] = { 192, 168, 80, 129 };				//must configure WIZnet IP
EthernetServer server = EthernetServer(69);			//TCP port the server is listening on, I'm using port 69, but you could use any
void setup()
{
 Ethernet.begin(mac, ip);
 server.begin();
 Serial.begin(9600);						//for troubleshooting purposes (not needed)
 pinMode(LEDpin, OUTPUT);
 pinMode(switchPin, INPUT);                                    // sets the digital pin as input to read switch
}
void loop () {
EthernetClient client = server.available();			//client connects to server
if (client){							//if connection present
 x = client.read();						//read information coming from server
 Serial.println(x);}						//print to serial (troublshooting only)
if (x == 49){							//if information sent is a zero
 digitalWrite(LEDpin, LOW);}					//turn of LED
else if (x == 48){						//if information sent is a one
 digitalWrite(LEDpin, HIGH);}				        //turn on LED
else if (x == 2){						//if information sent is a two
 digitalWrite(LEDpin, HIGH);					//blink the LED
 delay(500);
 digitalWrite(LEDpin, LOW);
 delay(500);}
if (digitalRead(switchPin) == 1){
 Serial.println("Button has been pressed " );
 server.write("Button has been pressed ");}                    // Read the pin and display the value
}



Prepare the LMCE Enviroment;

Setting up the Arduino to be controlled through GSD