Error, disabling serialEvent() for /dev/tty.usbmodem411 null (Processing + Arduino)

edited April 2014 in Arduino

Hi!

Please help, new to Processing/Arduino here. I'm trying to receive data from the Arduino to be displayed in Processing. I have set up Arduino to serially print a new line with accelerometer values every 100 miliseconds in this format: xG,yG,zG (by example 0.09,0.08,0.99) That works fine. On the Processing side I modified the basic Graph sketch(http://arduino.cc/en/tutorial/Graph) to receive the serial data from Arduino as a string which is later converted to a list that holds the individual axes values.

However when I run the sketch I get this:

Error, disabling serialEvent() for /dev/tty.usbmodem411
null

I have tried with all my serial ports and Im sure im using the right one. What am I doing wrong? Please help! Thanks a lot! :D

Here is the Processing code:

import processing.serial.*;

Serial myPort;

void setup () {
size(400, 300);        
println(Serial.list());
myPort = new Serial(this, Serial.list()[10], 9600); // The same serial port I'm using to upload sketches with Arduino
myPort.bufferUntil('\n');
background(0);
}
void draw () {
}

void serialEvent (Serial myPort) {
String inString = myPort.readStringUntil('\n');
String[] gList = split(inString, ',');
float xg = Float.parseFloat(gList[0]);
float yg = Float.parseFloat(gList[1]);
float zg = Float.parseFloat(gList[2]);
}

Answers

  • Answer ✓

    Try to debug your serialEvent routine using println()

    Do a println(inString) to see if you are getting the serial data.

    Then try println for the gList[] values.

  • Thanks dttworld! I get the values right when I try to do println(inString). But Processing wont run the sketch if I replace inString with gList[0] inside the println parenthesis. I click the play button and nothing happens, not even an error message.

    Put inString back again and it works. Why?

  • Use a bunch of println() in the serial event to find out where the code is stalling. Line 16 seems to execute. Is it stalling at line 17 because at times there is no comma in inString?

    Keep in mind that just because you receive a '\n' in your serial data it doesn't necessarily mean that it contains the full string that you expect - this is especially true when you first run the Processing program and it "catches" the first bytes of data streaming from the Arduino at some arbitrary point in the transmissions. It might be a good idea to throw away the first inString read which could contain partial data.

Sign In or Register to comment.