Implementing Arduino using Generic Serial Device
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).
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.
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.
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". Specify that your device is controlled via category "Device Category:Core" ("Computers - Core"). Otherwise the driver will not be started on 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
- 384 Process Receive Command For Child
cmdId = cmd.id_ # Command ID: ON, OFF, SET LEVEL cmdTo = cmd.devidto_ # Device ID in LinuxMCE devPort = device_.childdevices_[cmdTo].devdata_[12] # 12 contains a port/channel childType = device_.childdevices_[cmdTo].devtemplid_ # Template ID to know type of device: switch or dimmer deviceID = device_.childdevices_[cmd.devidto_].devdata_[12] command = [0,0,0,0,0,0] # define command array command [1] = deviceID # set the portnumber (.chomp.split('.')) command [2] = '' # Parameter 1 command [3] = '' # Parameter 2 command [4] = '' # Parameter 3 command [5] = '' # Parameter 4 command [6] = '' # Parameter 5 log ('logging from #384'); log ('Device ID'); log cmdTo; log ('Port used'); log command[1]; log ('Command given'); # orginal command from LMCE log cmdId; log ('Device Template'); # Template ID ie switch, dimmer or RGB log childType; log ('Level'); log cmd.params_[76]; # The level to set, as a value between 0 (off) and 100 (full). # It can be preceeded with a - or + indicating a relative value. +20 means up 20%. case cmdId when 192 # 192 is the 'ON' command command [2] = '1' when 193 # 193 is the 'OFF' command command [2] = '0' when 184 # 184 is Level of dimmer command [2] = '2' # indicate level command command [3] = cmd.params_[76] when 980 # 980 is color scenario command (template 1993) command [2] = '3' # indicate RGB command command [3] = cmd.params_[279] # red level command [4] = cmd.params_[280] # green level command [5] = cmd.params_[281] # blue level end 1.upto(6) {|x| log ('Sending'); log command[x] conn_.Send command[x]; }
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