INTERACTION DESIGN STUDIO
Alis Blog Processing and EEG

PROCESSING AND EEG PART 1

BABY STEPS




Our first sketch will be very simple. We are going to make the connection between Mindwave Mobile and Processing through TGC. The data will be transferred as JSON packages which will be analyzed and be shown on the screen in real-time. The necessary socket connection will be taken care of by the Thinkgear.jar file contained in the library

...
   neuroSocket = new Socket("127.0.0.1", 13854);
...

 

and will be available to use by the neurosocket object.

...

  ThinkGearSocket neuroSocket;

...

  ThinkGearSocket neuroSocket = new ThinkGearSocket(this);

 

In this sketch, our goal is to grab the attention and meditation levels from TGC as well as the individual wave levels, signal level, and blink strength so that we can use these values in the following sketches.

void setup() {
    size(500,500);
    ThinkGearSocket neuroSocket = new ThinkGearSocket(this);
    try {
        neuroSocket.start();
    } 
    catch (Exception e) {
        println("Is ThinkGear running??");
    }
    smooth();
}

 

After setting our stage, we are creating text areas where we are going to display the values pushed by TGC to Processing.

void draw() {

  background(0,0,255,100);

  text("Attention: "+attention, 10, 30);
  text("Meditation: "+meditation, 10, 50);
  text("delta Level: " + delta, 10, 70);
  text("theta Level: " + theta, 10, 90);
  text("low_alpha Level: " + low_alpha, 10, 110);
  text("high_alpha Level: " + high_alpha, 10, 130);
  text("low_beta Level: " + low_beta, 10, 150);
  text("high_beta Level: " + high_beta, 10, 170);
  text("low_gamma Level: " + low_gamma, 10, 190);
  text("mid_gamma Level: " + mid_gamma, 10, 210);
  text("signal Level: "+ sig, 10, 230);
  text("blink strength: "+ blinkStrength, 10, 250);

// text("rawEvent Level: " + raw[], 10, 270);

}

 

Now, the thing that needs to be understood is, Processing does not request information from TGC, TGC pushes the values to Processing.That is why we need to have event listeners to catch the values and assign them to the global variables defined at the beginning of the code to use them.

void poorSignalEvent(int sigLevel) {
  sig=sigLevel;
}

void attentionEvent(int attentionLevel) {
  attention = attentionLevel;
}

void meditationEvent(int meditationLevel) {
  meditation = meditationLevel;
}

void blinkEvent(int blinkStrengthLevel) {
  blinkStrength = blinkStrengthLevel;
}


void eegEvent(int deltaLevel, int thetaLevel, int low_alphaLevel, int high_alphaLevel, int low_betaLevel, int high_betaLevel, int low_gammaLevel, int mid_gammaLevel) {

  delta = deltaLevel;
  theta = thetaLevel;
  low_alpha = low_alphaLevel;
  high_alpha = high_alphaLevel;
  low_beta = low_betaLevel;
  high_beta = high_betaLevel;
  low_gamma = low_gammaLevel;
  mid_gamma = mid_gammaLevel;
}

void rawEvent(int[] rawArray) {}

void stop() {
  neuroSocket.stop();
  super.stop();
}

 

The complete sketch can be downloaded from here and the final outcome will look as this:

Neurosky Mindwave Processing Sketch 01