Ok, i want to send x,y,z values (in one line) from my arduino to processing over serial then use split() on the string value and then display it ect...
example:
arduino sends this :
23.77,45.00,34.54
Processing receives it like this:
23.
77,
45.00
,3
4.54
Problem is this doesn't work, processing wont accept the one line value therefore i cant split or use the values .
is there any other sketch that works or another solution?
I dont think it the arduino code is wrong , (on the arduino serial window its being displayed correctly)
Its the processing code that the string comes incomplete.
processing code
import processing.serial.*;
int lf = 10; // Linefeed in ASCII
String myString = null;
Serial myPort; // Serial port you are using
String num1;
int ok1=1;
int ok2=2;
int x=0;
void setup() {
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.clear();
}
void draw() {
while (myPort.available() > 0) {
myString = myPort.readStringUntil(lf);
if (myString != null) {
//print(myString); // Prints String
num1=myString;
println(num1);
}
myPort.clear();
if (x==0){
myPort.write("1");
x=1;
}
}
}
I noticed "//print(myString); // Prints String" in your code. What do you mean by this ?
println uses "," (comma) as a seperator and will inset a line break. You probable want "print" instead, but I'm not sure what the statement above means.
Your processing sketch should have a myPort.bufferUntil() call, to define when a packet has been received. If the Arduino is sending a value, a comma, a value, a comma, a value, and a carriage return/line feed, processing should buffer data until the carriage return is received.
The Processing sketch should also have a serialEvent() method that gets called when the buffer until character arrives. The serialEvent() method should contain the code to parse the input.