Related articles: FBLR Mind-Controlled Robot | Processing + EPOC via OSC
This Processing sketch demonstrates a simple interface between the Emotiv EPOC and Arduino via Processing and OSC. When the operator wearing the EPOC thinks “disappear,” the LED connected to the Arduino turns off; when the operator ceases thinking “disappear,” the LED turns back on. The sketch requires the arduino and oscP5 libraries for Processing, and the Mind Your OSCs application for EPOC.
(There exists one OSC library for Arduino, that I know of, that has been reportedly updated for build 0021, but I have not used it. I typically use Processing in conjunction with Arduino, for developing graphical interfaces such as the one shown here.)
Here is the Processing code:
/** * EPOC-to-Arduino "Goodbye, World" * by Joshua Madara, hyperRitual.com * * This sketch demonstrates a simple interface between * Emotiv EPOC and Arduino via Processing and OSC. When the * operator wearing the EPOC thinks "disappear," * the LED connected to the Arduino turns off; * when the operator ceases thinking "disappear," * the LED turns back on. * * The sketch requires the arduino and oscP5 libraries * for Processing, and the Mind Your OSCs application for EPOC. */ // import libraries needed for Arduino and OSC import processing.serial.*; import cc.arduino.*; import oscP5.*; Arduino arduino; // declare object OscP5 oscP5; // declare object float disappear = 0; // holds the value incoming from EPOC int LED = 13; // LED connected to Arduino pin 13 void setup() { println(Arduino.list()); // look for available Arduino boards // start Arduino communication at 57,600 baud arduino = new Arduino(this, Arduino.list()[1], 57600); // set LED as output pin arduino.pinMode(LED, arduino.OUTPUT); // start oscP5, listening for incoming messages on port 7400 // make sure this matches the port in Mind Your OSCs oscP5 = new OscP5(this, 7400); /* plug automatically forwards OSC messages having address pattern /COG/DISAPPEAR to getDisappear() which updates the disappear variable with the value of the OSC message */ oscP5.plug(this,"getDisappear","/COG/DISAPPEAR"); } void draw() { /* the following block evaluates disappear and if it is greater than or equal to .5, turns LED off, otherwise it turns/keeps LED on */ if(disappear >= 0.5) { arduino.digitalWrite(LED, arduino.LOW); } else { arduino.digitalWrite(LED, arduino.HIGH); } } /* the following function updates disappear with the value of any incoming OSC messages for /COG/DISAPPEAR/, plugged in setup() */ void getDisappear (float theValue) { disappear = theValue; println("OSC message received; new disappear value: "+disappear); }