Board stops listening after reading 73 bytes on /dev/ttyACM*

Hi there,

using the following piece of code written changing just few lines from what's been written by the user AlphaBeta (here)

int input;
int numberOfCharactersRead = 0;

void setup() { 
  Serial.begin(9600); 
} 

void loop() { 
  if (Serial.available()) {
    // Read next character ...
    input = Serial.read();
    
    Serial.print("DEBUG: numberOfCharactersRead ==");
    Serial.println(++numberOfCharactersRead);

    // Print just-read character ...
    Serial.print("DEBUG: Serial.println((char)input) ==");
    Serial.println((char)input);
  }
}

and typing from the command-line (using Bash)

$ cat theLog > /dev/ttyACM0    # theLog: ASCII text ; /dev/ttyACM0: serial port Arduino is listening to.

via the Serial Monitor (in the Arduino IDE) I see that only ~70 bytes are read -- doesn't matter how many bytes the file is filled with.

As for my understanding, the serial port gives up listening if it takes too long to read the file ... (?) Indeed, if one uses redirection to pass an infinite flow of bytes like

$ od /dev/urandom > /dev/ttyACM0

then problems disappear.

Any suggestion on how to fix that?

Thank you folks :slight_smile:

Remove the printout and see what happens. My guess is that you fill the output buffer and the Arduino then waits for space which then misses the receive.

To test this idea simply remove the printout in the sketch for each recieved character and do for instance one every 100 or a time limit.

My guess is also that od and cat give very different bursts of data to the driver. This also gives an idea on how to fix this. You can write your own version of cat that does not write so fast :wink: You can also use expect and look for "sync" messages. A bit like xon/xoff.

Cheers!