Hi,
Oftentimes when I am printing data to the serial port, the Arduino prints values from a previous sketch (at least that's what I think is happening, the buffer is too full I suppose) before it starts printing the new data. So, let's say for instance I am printing two values that are comma separated. The first value is in the range of 0.2-0.4 and the second value is 70 followed by a new line character. So, whenever I open the serial port, the Arduino will print some data like this
0.2,70
0.21,70
0.22,70
0.23
Notice the last value is not accompanied by the comma and the second value. This makes me think that the Arduino is printing "old data" and that the buffer was just really full.
Then, the Arduino starts printing the new values from the current sketch.
0.20,70
0.21,70
0.22,70
0.23,70
0.24,70
My code is posted below. This is the specific program I am working on right now, but this problem occurs whenever I print serial data and open the serial port.
Any help would be appreciated, thanks.
const double x_initial = 0.2;
const double x_max = 0.4;
const double x_increment = 0.01;
double x = x_initial;
void setup()
{
Serial.begin(115200);
}
void loop()
{
x += x_increment;
Serial.println(x,5);
Serial.print(",");
Serial.println(70);
if (x >= x_max-x_increment)
{
x = x_initial-x_increment;
}
}