Skip to content

Instantly share code, notes, and snippets.

@Thermoflux
Created March 8, 2017 14:01
Show Gist options
  • Save Thermoflux/a5948c5b2e93d5695b3c81fdc290966c to your computer and use it in GitHub Desktop.
Save Thermoflux/a5948c5b2e93d5695b3c81fdc290966c to your computer and use it in GitHub Desktop.
Read Serial Data and save to txt file
import processing.serial.*;
Serial mySerial;
PrintWriter output;
void setup() {
mySerial = new Serial( this, Serial.list()[1], 9600 );
println(Serial.list());
output = createWriter( "data.txt" );
}
void draw() {
if (mySerial.available() > 0 ) {
String value = mySerial.readStringUntil('\n');
if ( value != null ) {
output.printf("%d/%d/%d %d:%d:%d ,",year(),month(),day(),hour(),minute(),second());
output.println( value );
}
}
}
void keyPressed() {
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment