Serial parsing from eeg string

edited August 2017 in Arduino

Hi everyone, I am doing a brainwave eeg project now and I have already got the raw brainwave values in Arduino. It is a string of 11 values. But when I want to parse the eeg string in processing, I got the error 'disabling serialEvent() for /dev/cu.usbmodem1411 null'. I am quite new to processing and I totally have no idea about that. Is there anyone could help me to see this code? Thanks in advance. Sorry for my English if there is any mistake.

PS: I even didn't get the 11 varying values in the below monitor. I can only get data like this: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Here is the code:

import processing.serial.*;
Serial serial;

int signal_strength;
int attention; 
int meditation; 
int delta;
int theta;
int low_alpha;
int high_alpha; 
int low_beta;
int high_beta;
int low_gamma; 
int high_gamma;  


void setup() {


  println("Find your Arduino in the list below, note its [index]:\n");

  for (int i = 0; i < Serial.list().length; i++) {
    println("[" + i + "] " + Serial.list()[i]);
  }

  serial = new Serial(this, Serial.list()[3], 9600);
  serial.bufferUntil(10);

}

void draw() {

  println(signal_strength, attention, meditation, delta, theta, low_alpha, high_alpha, low_beta, high_beta, low_gamma, high_gamma);

}

void serialEvent(Serial serial) {

  String incomingString = serial.readString().trim();

  int[] incomingValues = int(split(incomingString, ","));
    signal_strength = incomingValues[0];
    attention = incomingValues[1];
    meditation = incomingValues[2];
    delta = incomingValues[3];
    theta = incomingValues[4];
    low_alpha = incomingValues[5];
    high_alpha = incomingValues[6];
    low_beta = incomingValues[7];
    high_beta = incomingValues[8];
    low_gamma = incomingValues[9];
    high_gamma = incomingValues[10];

  }

Answers

  • First thing, make sure you are connecting to the right serial port.

    You should consider checking the following posts and the provided links there: https://forum.processing.org/two/discussion/comment/101770/#Comment_101770 It is important that you make sure to handle cases where the serial event return null when retrieving data.

    PS: I even didn't get the 11 varying values in the below monitor.

    You only get 0 for all your values? What do you get from the code below? Notice: Code below is untested.

    Kf

    import processing.serial.*;
    Serial serial; 
    
    void setup() { 
      size(200,200); 
      serial = new Serial(this, Serial.list()[3], 9600);
      serial.bufferUntil(10); 
      noLoop();
    }
    
    void draw() {
    }
    
    void serialEvent(Serial serial) { 
      String incomingString = serial.readString().trim();
      if(incomingString!=null){
         String[] in=split(incomingString,",");
         println("Current time [msec]: "+millis()+" Tokens received: "+in.length); 
      }
      redraw(); 
    }
    
  • edited September 2017

    Hi kfrajer , thanks for your advice. I have tried the above code and get the result like this:

    Current time [msec]: 340 Tokens received: 1
    Current time [msec]: 340 Tokens received: 9
    Current time [msec]: 2024 Tokens received: 1
    Current time [msec]: 2082 Tokens received: 11
    Current time [msec]: 3028 Tokens received: 1
    Current time [msec]: 3094 Tokens received: 11
    Current time [msec]: 4024 Tokens received: 1
    Current time [msec]: 4090 Tokens received: 11
    Current time [msec]: 5019 Tokens received: 1
    Current time [msec]: 5085 Tokens received: 11
    Current time [msec]: 6018 Tokens received: 1
    Current time [msec]: 6079 Tokens received: 11
    

    I am sure I am using the right serial port. Do you have any other advice?

  • Answer ✓

    I am guessing you have the right port. Can you share your ino code?

    You can check what you get in every event:

    void serialEvent(Serial serial) { 
      String incomingString = serial.readString().trim();
      if(incomingString!=null){
         String[] in=split(incomingString,",");
         println("Current time [msec]: "+millis()+" Tokens received: "+in.length); 
         println(in);
      }
      redraw(); 
    }
    

    After you check what you receive, then you could process only those lines with 11 items.

    Kf

  • Kfrajer, thanks a lot, I fixed it finally.

Sign In or Register to comment.