EPOC-to-Arduino “Goodbye, World”

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);
}

Arduino LED setup

12 Replies to “EPOC-to-Arduino “Goodbye, World””

  1. Hi Evan,

    bit of a tangent but you seem to know your stuff, i have already hacked a mindflex brainwave sensor unit and sent the data through an arduino uno and unpacked it all inside max/msp, the mindflex is unfortunately … not the best at a workable true representation of the data, so i am looking at getting the same data values (delta, theta, alpha ect) out of the EPOC and into max, i see you wrote the Mind your OSC doesn’t send this data only mediation and so forth if i understood it correctly? do you have any pointers how i could unpack the data?

    Thanks for your time.

  2. Hi Joshua,

    I’ve still been unable to figure out how to realize the concept I have, I was wondering if you had an idea of how I can move forward. I have processing communicating with the epoc, but I can’t figure out how to control the servos on an arduino mega board through processing. My main issue is how to make a processing script that moves servos, based on the input from the emotiv. How would I create/alter a processing script to react to the input from the emotiv?

    1. Hi again, Evan. For controlling servos on the Mega, you may need the servo library, in which case you will not use firmata on the Arduino (nor the arduino lib in Processing), but instead write an Arduino program that communicates with Processing over a serial connection, and changes the servo pins on the Mega accordingly. You should be able to find many online examples of how to get Arduino and Processing talking to each other over a serial connection. Also examples of how to control servos with Arduino.

    1. Hi, Evan. It works with the consumer edition! That’s what makes Mind Your OSCs so awesome: it works with the consumer edition to send EPOC output as OSC message to anything that can receive and parse them, such as Processing (and thus Arduino, in this case). Really opens up what you can do with the device.

      1. Thanks! I’m actually an architecture student, working on a robotics project that involves using feedback from the EPOC to affect an object/environment. Did this particular example require the Duemilanove board, since I currently only have the Uno board.

        Also, is there a way to use brainwave feedback from the EPOC in conjunction with arduino? I’m intending to use certain patterns in brainwave activity or facial expressions to set off certain ‘scripts’ in arduino. Would I need to buy the Mind Workstation application and connect it to arduino?

        Sorry for the amount of questions, I’m very excited to try to apply the emotiv to my project, but I don’t have much experience with arduino+emotiv.

        1. Cool! No worries about asking too many questions; I encourage it.

          The example should work fine with Uno, but I have not actually tried it. Re neurofeedback applications, that depends on what you intend to measure and map. Mind Your OSCs does not output brainwave data per se, only the discrete values for Emotiv’s Expressiv, Emotiv, and Cognitiv suites. So, e.g., you could not use this setup to trigger an Arduino event when a user’s beta wave frequency changes (because you do not have access to that data), but you could trigger an event when the user’s meditation value changes (since that is part of the Emotiv suite, and so you do have access to the data) or when the user smiles (data from the Expressiv suite). AFAIK, to accomplish the former, you would need a developer’s edition of the EPOC, and write your own software (or modify/extend Mind Your OSCs). I do not know whether or not Mind WorkStation would allow you to trigger Arduino events.

          1. I was able to get the EPOC to run the sketch, and turn the LED on and off with disappear, and was wondering about going further with the device. Is there a way I can use multiple outputs from mind your OSC’s to control different aspects of the arduino? For example, controlling the LED with COG/disappear, while at the same time controlling the motion of a servo with smiling, or a frustration value. Could I accomplish this by editing one processing sketch to incorporate multiple functions, or do I need several processing sketches open at once?

          2. Glad it worked for you. You should be able to accomplish what you want with one Processing sketch. Just need to map different EPOC values to different pins on the Arduino. The FBLR sketch maps four Cognitiv values to two motor outputs. There are ways to “plug” the oscP5 values to your own functions — the oscP5 docu shows how.

Leave a Reply