Thank you very much!
Your hints are very helpfull. I wrote a new Sketch after checking the “serialEvent” command. With the new sketch (see below). I already can save my data, line after line, from the Arduino in a .txt file. Now I have another problem with the saving of the data. My first line after the setup is “Millis Value1 Value2”. After this line I expect my values from the Arduino but before they are indicated, random numbers are indicated. You can see this in the Picture below. Every time I start the Processing-sketch from the beginning, the “random” numbers have another value. Do you have any ideas how I can fix this or where they come from?
Processing sketch:
import processing.serial.*;
Serial myPort;
PrintWriter output;
String val;
void setup()
{
myPort = new Serial (this, Serial.list()[2], 115200);
output = createWriter("myFile.txt");
output.println("Millis"+ "\t" + "Value 1" + "\t" + "Value 2");
}
void draw ()
{
output.println(val);
}
void serialEvent(Serial s)
{
String rx = myPort.readStringUntil('\n');
if (rx!=null)
{
val = rx;
}
}
void keyPressed()
{
output.flush();
output.close();
exit();
}
Picture of the .txt file:
