Read multiple variables with Processing, from Arduino

Hi to everyone,

someone of you could link me to a page in which is explained clearly how to read multiple variables in processing from a Serial port to which is connected an Arduino.

I need both the Arduino sketch and the Processing sketch.

I searched on the internet but I found too different solutions, with json, with firmata, with readuntil() etc...

Could you please tell me what is the most reliable?

Thanks,
Fab.

Could you please tell me what is the most reliable?

Write the values with start and end markers, and delimiters between the values.

Serial.print("<");
Serial.print(x);
Serial.print(", ");
Serial.print(y);
Serial.print(", ");
Serial.print(z);
Serial.println(">");

Processing will then receive something like "<12, 45, 78>". You can use bufferUntil() in Processing, to ensure that serialEvent() is only called when the carriage return/line feed is received. Then, the serial data will consist of the entire packet, which is then relatively easy to parse.