I've also asked this question over on stack exchange so I'll link the actual question here.
The short story is I have a plot that updates in real time from data collected on an Arduino. The plot updates on a 50ms + overhead interval and I can either choose on the Arduino side to either delay the loop 50ms + compensation or use flush()
. I'm running into some problems with the delay option where my program begins to lag (Python side). I'm wondering if flush will work as I expect and hold the output until my python program reads from the serial port. So then the Python program is completely controlling the flow of data every time it polls for an update.
Edit: Here's a snippet of the code.
void loop() {
// put your main code here, to run repeatedly:
val1 = analogRead(0);
val2 = analogRead(1);
Serial.print(val1);
Serial.print(" ");
Serial.print(val2);
Serial.print("\n");
//Serial.flush();
delay(50);
}