Serial Monitor gives wrong time stamp

When you switch-on the time stamping in the Serial monitor, you get printouts like this:

13:45:23.848 -> getData: 
13:45:24.553 -> getData: 

This looks like the 2nd getData command came ~700ms after the first, while in reality it came several minutes later!

The problem is that the time stamp seems to get printed out with a \n character. This thus becomes a meaningless value when the next print comes much later.

Instead, the timestamp should only be printed at the time-point a new print has begun!

How do you define " the time-point a new print has begun!"? On my system it prints when a new line starts to print, it could simply be a space which you did not see. Look at your print statement and see if you have a loose space at the end of the string.

I interact with the code via a web page, and trigger a printout. You see that the line is printed, PLUS the time stamp on the next line.

The next print is not using a new line, but follows directly the outdated time stamp. Thus the timestamp for this line is wrong.

But it is easy to test: make a loop to print out every minute, and compare with your computer time.

Like this you mean ?

void setup()
{
  Serial.begin(115200);
  while (!Serial);
}

void loop()
{
  static byte x = 0;
  Serial.println(x);
  delay(60000);
  x++;
}

Which gives this output

08:22:16.184 -> 0
08:23:16.098 -> 1
08:24:16.064 -> 2
08:25:15.978 -> 3

which in turn matches the time display on my PC

Exactly. I took your code and got this:

10:0:32.336 -> 0
10:0:32.440 -> 1        # computer time: 10:01:32
10:1:32.440 -> 2        # computer time: 10:02:32
10:2:32.446 -> 

The '1' is printed at computer time: 10:01:32, the time stamp on the 3rd line, not the '10:0:32.440' on the 2nd line! And you see that the last line in the monitor already has a time stamp, although nothing was printed!

The above was obtained with the Arduino IDE 2.0 Beta7. After starting Arduino IDE 1.8.13, and looking at the running dvice, I get this:

10:23:39.489 -> 13
10:24:39.464 -> 14
10:25:39.474 -> 15

This is how it should be; and no extra line!

Obviously a regression in Beta7!

1 Like

I have repeated my test with IDE 2.0.0-beta.7 and can confirm your observations

Thanks for the report, I tested it and have the same issue.

I created an issue on Github to keep track of it.

1 Like