I am facing the following error in a Processing application off and on, and sometimes it works perfectly.
Error, disabling serialEvent() for COM2
null
Here is the code:
Arduino's:
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
Serial.print(sensorValue1);
Serial.write("-");
Serial.println(sensorValue2);
delay(1);
}
Processing's
import processing.serial.*;
Serial myPort; // The serial port
void setup () {
size(1043, 102);
background(255);
myPort = new Serial(this, Serial.list()[1], 9600);
println(Serial.list());
myPort.bufferUntil('\n');
}
void draw () {
// Everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
background(255);
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
// String inByte = inString;
int[] inStr = int(split(inString, '-'));
println(inStr);
fill(0);
rect(10, 2, inStr[0], 46);
rect(10, 52, inStr[1], 46);
fill(255);
rect(400, 14, 245, 21);
fill(0);
textAlign(CENTER);
textSize(14);
text("1st value: " + inStr[0] + " 2nd value: " + inStr[1], width/2, 30);
}
}
When I remove following part of code, the application works fine.
fill(0);
rect(10, 2, inStr[0], 46);
rect(10, 52, inStr[1], 46);
fill(255);
rect(400, 14, 245, 21);
fill(0);
textAlign(CENTER);
textSize(14);
text("1st value: " + inStr[0] + " 2nd value: " + inStr[1], width/2, 30);
I am using Windows 7, Processing version 2.2.1, and Arduino version 1.0.5-r2.
I'm new to all serial communication stuff...