Neurosky MindWave and Processing

This is my first trial run of a Neurosky MindWave sensor with a custom program written in Processing. The connection architecture is quite straight forward. The ThinkGear connector is a background process that reads from the IR serial port to obtain the brainwave signals and distributes them through a TCP socket server (localhost with port 13854).
 

 
There are a number of Java socket clients implementation. I use the ThinkGear Java library from Creation.

Eric Blue has another Processing based visualizer using the MindWave.

ZeroShore has another implementation with an animation called HyperCat.
 
Sample Code

import processing.video.*;
import neurosky.*;
import org.json.*;
 
ThinkGearSocket neuroSocket;
int attention = 0;
int meditation = 0;
int blinkSt = 0;
PFont font;
int blink = 0;
Capture cap;
 
void setup() 
{
  size(640, 480);
  ThinkGearSocket neuroSocket = new ThinkGearSocket(this);
  try 
  {
    neuroSocket.start();
  } 
  catch (ConnectException e) {
    e.printStackTrace();
  }
  smooth();
  font = loadFont("MyriadPro-Regular-24.vlw");
  textFont(font);
  frameRate(25);
  cap = new Capture(this, width, height);
  noStroke();
}
 
void draw() 
{
  background(0);
 
  image(cap, 0, 0);
  fill(255, 255, 0);
  text("Attention: "+attention, 20, 150);
  fill(255, 255, 0, 160);
  rect(200, 130, attention*3, 40);
  fill(255, 255, 0);
  text("Meditation: "+meditation, 20, 250);
  fill(255, 255, 0, 160);
  rect(200, 230, meditation*3, 40);
 
  if (blink>0) 
  {
    fill(255, 255, 0);
    text("Blink: " + blinkSt, 20, 350);
    if (blink>15) 
    {
      blink = 0;
    } 
    else 
    {
      blink++;
    }
  }
}
 
void captureEvent(Capture _c) 
{
  _c.read();
}
 
void attentionEvent(int attentionLevel) 
{
  attention = attentionLevel;
}
 
void meditationEvent(int meditationLevel) 
{
  meditation = meditationLevel;
}
 
void blinkEvent(int blinkStrength) 
{
  blinkSt = blinkStrength;
  blink = 1;
}
 
void stop() {
  neuroSocket.stop();
  super.stop();
}
This entry was posted in Research, Testing and tagged , . Bookmark the permalink. Both comments and trackbacks are currently closed.

6 Comments

  1. melih
    Posted 2014/02/20 at 4:32 pm | Permalink

    hi,

    I am new in neurosky mindwave ..
    could you please send me a sample code that read attention on java programming.
    email : mmelihcoskun@gmail.com

  2. timo
    Posted 2014/01/03 at 11:44 pm | Permalink

    i keep getting this ConnectException also. seems like a good program, anyone know how to overcome this ?

  3. cari
    Posted 2013/01/28 at 1:29 pm | Permalink

    hallo
    I am a beginner of the programing.
    Thank you for the detailed code.
    Although I tried this code in Processing
    catch (ConnectException e) {
    e.printStackTrace ();
    }
    Places ConnectException
    proccesing tell “can not class or type named”
    I try
    IOException and changing parts of the ConnectException.
    Nothing but pass on the application debugging
    Not indicated
    ( work think gear conector)

    I hope you told me there was a solution.
    thank you

    • Posted 2014/02/19 at 5:43 pm | Permalink

      If you are using processing 2.x versions then try importing this

      import java.net.*;

      sorry for late reply 🙂

  4. Posted 2012/04/28 at 9:25 pm | Permalink

    I checked your page out over the winter – thanks! Since then I put together a few objective c classes that make ThinkGearConnector + cocoa pretty easy. Yes, this is a plug… but at least it’s relevant!

    • bryan
      Posted 2012/04/29 at 2:37 pm | Permalink

      Hi Ben,
      Thanks for sharing.

      Bryan