Implementing Arduino using Generic Serial Device

From LinuxMCE
Revision as of 08:54, 7 September 2012 by Daballiemo (Talk | contribs) (Setting up Arduino Uno and LinuxMCE to be able to control a RGB LED string)

Jump to: navigation, search
Version Status Date Updated Updated By
710 Unknown N/A N/A
810 Unknown N/A N/A
1004 In Progress 3th September 2012 Daballiem0
1204 Unknown N/A N/A
1404 Unknown N/A N/A
Usage Information

General Info (Information not valid yet)

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

Setting up Arduino Uno and LinuxMCE to be able to control a RGB LED string

In the following I want to give an overview what needs to be done to have LinuxMCE control a RGB LED (string) through an Arduino. The string is within brackets as the only added to the Arduino to be able to control a ledstring is some mosfets and a powerblock.

First is setting up Linuxmce.

1) For now define Arduino as a vendor via Advanced -> Device Templates. Select the "Add Manufacturer" button and provide "Arduino" as manufacturer followed by save and close. 2) Define a new template for the Arduino Uno (which I am using atm)

Advanced -> Device Templates, selected "Add device template". Name the template "Arduino Uno", select Implements DCE, Device Category is "Interfaces - Specialized #97", set "This device is controlled via" to device #1 (the core). As I am using an Ethernet shield select "Is IP based", set "Comm Method" to Ethernet and under "Device data" add #69 TCP Port (int). Give the TCP Port the value "69", set it to required and allowed to modify.

Now set up the rest of the template according to http://wiki.linuxmce.org/index.php/How_to_add_your_own_GSD_device

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.
 * 
 * Daballiemo
 * 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