I am currently trying to get a value (Yes!
) from the Arduino to a text file (data.txt
).
The problem is that the data isn't being read from the Arduino's Serial. When I tried to simple print the value to the prompt in processing
, I came out empty handed.
Below is my code for the Arduino
//Just a basic program to write to the Serial the word/phrase; `Yes!`.
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("Yes!");
}
Below is my code for processing
:
import processing.serial.*;
Serial mySerial;
PrintWriter output;
void setup() {
mySerial = new Serial( this, Serial.list()[0], 9600 );
output = createWriter( "data.txt" );
}
void draw() {
if (mySerial.available() > 0 ) {
String value = mySerial.readString();
if ( value != null ) {
output.println( value );
}
}
}
void keyPressed() {
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}
Yes, this code was found from this stackoverflow
question.
Any help would be greatly appreciated!