Arduino IDE/Serial Monitor runtime

Hello, fellow researchers :slight_smile:

So, the specific question is: Is there a way to know the refresh rate/runtime of the Arduino IDE and/or the serial monitor on an operating system? ::slight_smile:

So here¬īs the setup and background:
1.- The board is an Arduino Mega (Mega 2560 Rev3).
2.- I am reading the UTC time from a GPS receiver (GY-GPS6MV2) at 9600 baud. I am using the millis() command for interpolating each second and to be able to get the UTC ‚Äúevery milisecond‚ÄĚ. After a lot of measurements, i know that the internal Arduino clock is not perfect, since a drift of 3-4 ms appears every second. Whatever clock drift inside the arduino is irrelevant, since i¬īm making a sync with every PPS from the GPS.
3.- I am printing this UTC+ms time over the serial to a computer that is running the serial monitor. The baudrate of the serial connection is 2000000.
4.- I am recording a video of the monitor of a computer running the IDE and showing the serial monitor. The computer monitor runs at 60 fps (a picture every ~16 ms). The camera recording takes 50 fps (one picture every 20 ms).
5.- What i see from the serial monitor (by deactivating the autoscroll), are two identical utc+ms measurements. This would mean two readings per milisecond (right?).
What i would expect: 8)
Since the arduino delivers the information twice every milisecond, the screen running at 16 ms should show a different utc+ms each time it refreshes.
Since the camera records one picture every 20 ms, then it should get a different monitor picture every time.
What actually happens: :confused:
The pictures from the camera show twice the same utc+ms time. :frowning:
When the UTC+ms time changes on the video, it shows an increment in the miliseconds of 32 ms (see pictures) :frowning:
Do note that the Serial Monitor seems to be printing when the camera took the picture.
What is known: :sunglasses:
The camera is taking a picture every 20 ms. This is proven since the surrounding environment does change every frame, even when the utc+ms time from the arduino serial monitor does not. (See the attached pictures, and how the flowers move)
The Arduino is delivering two measurements every milisecond. This is seen by manually proving the serial monitor prints.
The prime suspects: :smiling_imp:
The serial monitor/Arduino IDE may update only every 32 ms. Considering that, by deactivating the autoscroll, one is able to see the ms count, if the IDE updates every 32 ms, then we would only see an update every 32 ms. :roll_eyes:
The computer monitor updates only every 32 ms. This could make sense, since the apparent 32 ms update correlate to the ‚Äúsupossedly‚ÄĚ 16 ms update rate claimed by the manufacturer. :roll_eyes:
The Arduino Serial Communication. If the arduino sends information only every 32 ms, and it buffers internally in the meantime, this could also explain the 32 ms updates seen on the monitor. :roll_eyes:
I am aware that an operating system will allocate only so much resources on an application at any given time, but we are talking about an i7 Intel processor, with 8 Gb of RAM, and a computer that is only running the Arduino IDE with the serial monitor.

It will be interesting if anyone else has had this issues :slight_smile: :slight_smile:

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

//x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-
//accelerometer stuff
#include "GY_85.h"
#include <Wire.h>

GY_85 GY85;     //create the object
int delta = 0;
long OldUTC = 0;
int msec = 0;

void setup()
{
  Serial.begin(2000000);
  Serial3.begin(GPSBaud);
  Wire.begin();
  GY85.init();
  pinMode(31, OUTPUT);
}

void loop()
{
  while (Serial3.available() > 0)
    gps.encode(Serial3.read());
  if (gps.time.value() != OldUTC) {
    msec = millis();
    delta = 0;
    OldUTC = gps.time.value();    
  }
  else {
    delta = millis() - msec;
  }
  Serial.print(OldUTC);
    Serial.print('-');
    Serial.print(delta);
    Serial.print('\n');
}

Try using micros() for your time tracking reporting, see what kind of results you get. That should get you down to around 4uS resolution.

2,000,000 bit per second output data rate is a complete character at 200,000/sec output rate (start bit, 8 data bits, stop bit). That means putting a new character in the serial output register every 5uS. That's every 80 clock cycles. Doesn't seem to leave much time for processing a GPS sentence, which can be a pretty long string of characters, doing the mS interpolation, and serial printing your output sequence.

A few observations.
You're including SoftwareSerial but don't seem to use it, why?
You're communicating with your GPS at a snail's pace (9600 bps). That means transmission takes about 1 ms per character.
You're making the typical beginner's mistake of using while (Serial3.available() > 0) { ... } - there's no reason to expect more than one character at a time in the Serial3 buffer as they come in at just 1 per ms (or not at all, if the GPS isn't sending anything), and you may actually be stuffing the Serial buffer with print() jobs as the loop() will run many times before the next character has come in.