[SOLVED] Error, disabling serialEvent() for COM3

Hey, I'm using Arduino to gather a string of data which looks like this in the serial monitor of Arduino:

200,0,0,79188,259228,102427,41468,112985,135554,35911,182789

200,0,0,1240804,785300,292349,440138,262836,288606,132864,693346

200,0,0,1237910,1015913,144220,750405,60550,144449,133690,754115

I'm wanting to take this into Processing and split the strings so i can access a certain column from the data. The code I have at the moment is running the error in the discussion title every time I try to run it though. I've tried to solve the problem but with no luck, so I think there must be an error in my code somewhere in the serial event maybe?

I will post the code below, thanks for taking a look!

import processing.serial.*;

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph

void setup () {
  // set the window size:
  size(400, 300);     

  // List all the available serial ports
  println(Serial.list());

  myPort = new Serial(this, Serial.list()[0], 9600);
  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');
  // set inital background:
  background(0);
}
void draw () {
  // everything happens in the serialEvent()
}

void serialEvent (Serial myPort) {
  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');
  int[] list = int(splitTokens(inString, ","));

  if (inString != null) {
    // trim off any whitespace:
    println( "Recieving:" + inString);
    inString = trim(inString);
    // convert to an int and map to the screen height:
    float inByte = float(list[4]);
    inByte = map(inByte, 0, 1023, 0, height);

    // draw the line:
    stroke(127, 34, 255);
    line(xPos, height, xPos, height - inByte);

    // at the edge of the screen, go back to the beginning:
    if (xPos >= width) {
      xPos = 0;
      background(0);
    } else {
      // increment the horizontal position:
      xPos++;
    }
  }
}

UPDATE: I think this error code was just a bug cause it fixed once I restarted processing + my computer

Sign In or Register to comment.