Transmiting data to Serial Monitor at low baudrate without Losing data

Hey all!
So I'm stumped with this, I'm currently learning the basics of using an arduino, more specifically the Serial and UART communication.
I've setup a 9600 baudrate, and made a loop to try and have a sampling frequency of an analogue signal of 1kHz. So in my head each milisecond, the analogue value goes through the ADC, is stored, and then a message is printed on the Serial Monitor . The message I'm printing is 25 characters long so i'm thinking it should be 250 bits per message, and since the loop should take a bit more than 1 ms in reality, I would be sending something like 250000 bits per second to the Serial Monitor on my PC. With a 9600 baudrate I should be losing the most part of this information I thought, but the serial monitor is showing almost all of it, with only one or two entries missing, and I dont get why. I used the code below and a Seeeduino Xiao.

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  analogReadResolution(12);
}

// the loop routine runs over and over again forever:
void loop() {
  int time = millis()
  // read the input on analog pin 0:
  float sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.print("Time:")
  Serial.print(time)
  Serial.print(" Value:")
  Serial.println(sensorValue);
  delay(1);  // delay in between reads for stability
}

Turn on timestamps in Serial monitor, and inspect the time it takes for your input to cycle.

Show us the serial output, too.

You won't lose data, you just won't be collecting data at 1 ms intervals.

At 9600 Baud, it take about 1 millisecond to transmit one character.

1kHZ Serial
I took this screenshot from the Serial Monitor

And it continues like that? Interesting. 25 chars of serial transmission in 1-2 ms. Implies 25k baud minimum.
What's the setting of Serial monitor?

Yep, while right now I can't test it again, when I took the screenshot I let it run a few seconds first since I thought I would need to fill up the serial buffer first. I set the serial monitor to 9600 bps as well.

Are you using an Arduino with native USB (Leonardo or Micro, for example)? They transfer data at USB rate regardless of the serial baud rate set.

I'm using a Seeduino Xiao with a USB-C cable from my cellphone charger. Would that mean that the baudrates I set are irrelevant and only the USB rate is actually used? And if so where can I know what speed it sends data?

Yes.

And if so where can I know what speed it sends data?

USB is "complicated", but the last time I tested it I got rates of about 6Mbps.

2 Likes

Got it, thank you!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.