Data can be seen in the console but the data is not being written in the text file. The file is created but there is no data in it.
Here is my code in Processing,
import processing.serial.*;
Serial myPort; // Create object from Serial class
String val; // Data received from the serial port
PrintWriter output;
void setup()
{
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
output = createWriter( "my.txt" );
}
void draw()
{
if ( myPort.available() > 0)
{ // If data is available,
val = myPort.readStringUntil('\n');
output.print( val );
}
println(val); //print it out in the console
}
and in Arduino,
int potPin = 0; // initialize analog pin 0 for LM35 temperature sensor
void setup()
{
Serial.begin(9600);// set baud rate at”9600”
}
void loop()
{
int val;// define variable
int dat;// define variable
val=analogRead(0);
dat=(125*val)>>8;// temperature calculation formula
Serial.print("Tep:");//
Serial.print(dat);// output and display value of dat
Serial.println("C");// display “C” characters
delay(500);// wait for 0.5 second
}
Any answers are appreciated. Thank you!