Go Down

Topic: serial print speed (Read 9274 times) previous topic - next topic

theCellist

Hi,

I have a question.... i' ve tested my genuino mega 2560 for serial.print speed with this simply code:


int t = 0, t1 = 0;

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

void loop() {
  t = micros();
  Serial.println(t1);
  t1 = micros() - t;
}
 

On the serial monito i've read

0
72
116
160
160
156
160
156
168
156
160
156
160
156
176
5152
6232
6232
6232
6232
6232
6232
6232
6232
6232
6232
6232
6232
6232
6232
6232
6232
6232
6232
6232
6232

why speed decrease? How can I keep the first transfer time for ever?

Thank u very much (and excuse me for my bad english)

AWOL

Change this
Code: [Select]
Serial.begin(9600); to
Code: [Select]
Serial.begin(115200); then retest and see if you can figure it out.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Delta_G

Quote
why speed decrease? How can I keep the first transfer time for ever?
The first few time all print has to do is stick the characters in the buffer.  Going out from the buffer to the Serial line is interrupt driven.  So it just copies chars into the buffer and returns.  Super quick. 

Later once the buffer is full, print has to wait while chars are sent out to make room for the new stuff.  That takes some time.  If you increase the baud rate it goes faster. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Go Up