Description
Output to serial monitor is 'loosing' some characters
Text that is output fast by successive fmt.Println, fmt.Printf, print, println statements, result after a few lines in 'randomly missing' characters.
func main() {
time.Sleep(time.Second)
startTime := time.Now()
fmt.Printf("\033[2J")
fmt.Printf("\033[H")
numLines := 600
delayMicroseconds := 0
for range numLines {
fmt.Println("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
time.Sleep(time.Microsecond * time.Duration(delayMicroseconds))
}
fmt.Printf("in %v - Printed %d lines with delay %d microseconds", time.Since(startTime), numLines, delayMicroseconds)
time.Sleep(time.Second * 2)
}
When run on a pico2-w and pimoroni tiny2350 (only boards I have to test this), results in some characters to be 'lost' and not output trough the serial interface. Tested with tinygo monitor, SerialTools (macOs) and Screen (also on macOs).
If we add a delay of a few microseconds before printing the next line, this behaviour stops and no characters are lost, if the delay is enough.
- When using fmt.Println - or fmt.Printf("...80 cols of text...\n") it requires a delay of 11 or 12 micro seconds to not 'loose characters'.
- When printing with print or println, the required delay is 24 to 25 micro seconds, any less and some characters are 'lost'.
Compiling with "-opt 2" or "-gc leaking" did not change this behavior.
Running the program on macOS with "go run ." and "tinygo run ." doesn't exhibit this behavior.
Sample output of Characters 'missing' - every line should be 80 characters (1->0 8times) with a trailing line break.
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
12345678901234567890123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567890123678901234567890
123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901901234567890
1234567890123456789012345678901234567890123456789011234567890
12345678901234567890123456789012345678901234567890123234567890
1234567890123456789012345678901234567890123456789012344567890
123456789012345678901234567890123456789012345678901234564567890
123456789012345678901234567890123456789012345678901234567890
123456789012345678901234567890123456789012345678901234567897890
1234567890123456789012345678901234567890123456789012345678990
12345678901234567890123456789012345678901234567890123456789011234567890123456789012345678901234567890123456789012345678901234123456789012345678901234567890123456789012345678901234567890123490123456789012345678901234567890123456789012345678901234567890