I want to save data received serially on arduino to a text file using processing. Right now my code is for processing is as shown below.
import processing.serial.*;
Serial myPort;
int val;
void setup()
{
myPort = new Serial (this, "COM3", 1200);
}
void draw()
{
if ( myPort.available() > 0)
{
val = myPort.read();
print((char)val);
}
}
The arduino receives aaaaaaaaa and it's also received by processing like that. What do I do to save it into a text file? Can someone modify my code? I'm a bit new to processing.
Also, if my received text was : aaaaaaaaaa bbbbbbbbbb
then how can i save the new paragraph as a new paragraph in the text file?
All help appreciated. Thanks!
Follow up:
import processing.serial.*;
Serial mySerial;
//import java.text.*;
//import java.util.*;
PrintWriter output;
String[] list;
void setup() {
size(720,700);
background(255);
mySerial = new Serial( this, "COM3", 1200 );
output = createWriter("test5.txt");
}
void draw() {
if (mySerial.available() > 0 ) {
String value = mySerial.readString();
if ( value != null ) {
fill(50);
text(value,10,10,700,700);
output.println(value);
saveStrings("test5.txt", value);
}
}
}
//void keyPressed() {
//output.flush(); // Writes the remaining data to the file
//output.close(); // Finishes the file
//exit(); // Stops the program
//}
I tried this code for saving data into a text file and got an error that said "The method saveString(String, String[]) in the type PApplet is not applicable for the argument (String, String) "