I have an Arduino connected to a linux box (a Raspberry Pi). I'm reading an analog pin and writing it out with Serial.println()
together with the value of millis()
The serial port is running at 9600bps
Something in the lines of:
void Setup() {
Serial.begin(9600)
}
void loop() {
Serial.print(analogRead(A0));
Serial.print("\t");
Serial.println(millis());
}
On the receiving end I see a continuous stream of 5 or 6 seconds, then a gap of 2 seconds with no data, then another 5 o 6 seconds full of data. I'm not "seen" it live but plotting the value of millis() with a data read from the serial port.
I think it might be that the data is lost in the write buffer of the arduino, or that something else takes processor time every 5 or 6 seconds (there is an unused ethernet shield attached) or maybe the Serial port writes in bursts.
When I increase the baud rate to 115200 I still get time gaps, but they seem more random.
Update:
Increasing baud rate to 38400 removed the gaps in the samples (gaps measured in arduino millis() time)
Another strange thing was:
On the receiving end I was doing cat /dev/ttyACM0
and piping it to awk
which added the system clock to each line received. Then I plotted received time vs system time, and it was not a straight line, but a ladder like plot. Removed the innecesary cat
and the time was back to normal.
It turns out cat /dev/ttyACM0 | awk {print}
is not the same as </dev/ttyACM0 awk {print}
. It seems cat does some strange buffering.
Now I seem to get every value read by the arduino.