Hi,
I'm having some problems importing a string of serial data, and converting it an int array inside processing.
I can't figure out what I'm doing wrong here; so I'm hoping someone in here can help me out.
The string looks like this when I get it inside Processing:
Quote:Ì811578757985
-7,10,4
-12,2,7
-8,3,5
.. and so on..
This is the Arduino code that I use to send it to Processing:
Code:void loop(){
receiveData(); //receive data and calculate yaw pitch and roll
Serial.print(outputarray[0]);
Serial.print(",");
Serial.print(outputarray[1]);
Serial.print(",");
Serial.println(outputarray[2]);
}
Here's the code I use to read the data, and split it in the sensors[] array inside Processing:
Code:void serialEvent(Serial myPort) {
String myString = myPort.readStringUntil('\n');
if (myString != null) {
int sensors[] = int(split(myString, ','));
println(sensors[0]);
println(sensors[1]);
}
}
The weird thing here is that println(sensors[0]); works just fine, and only shows the first value in the string, but sensors[1] and sensors[2] doesn't.
Any ideas as to why this is?
Also, I'm wondering if the weird garbled data at the beginning of my Arduino feed might have something to do with it. The garbled data changes at every run, so it's never the same.