Hello Everyone,
I completely new to Arduino so apologies in advance for the basic questions. Hopefully they'll get more complex with time!
I'm experimenting with my new Uno and have been checking out the time taken for the code to execute serial line commands.
Consider the following code:
unsigned long count = 0;
unsigned long bookmark = 0;
void setup()
{
Serial.begin(115200);
bookmark = micros() + 1000000;
}
void loop()
{
count++;
if(micros() >= bookmark)
{
Serial.print(count, DEC);
Serial.println(" counts achieved");
count = 0;
bookmark = micros() + 1000000;
}
}
I have deduced from the average output of 129284 counts that the Loop handling, increment and if statement comparison takes 7.545us each cycle.
Now consider the following with an extra Serial.println line:
unsigned long count = 0;
unsigned long bookmark = 0;
void setup()
{
Serial.begin(115200);
bookmark = micros() + 1000000;
}
void loop()
{
count++;
Serial.println(count,DEC);
if(micros() >= bookmark)
{
Serial.print(count, DEC);
Serial.println(" counts achieved");
count = 0;
bookmark = micros() + 1000000;
}
}
By introducing the extra serial command I am reduced to 2146 counts, thus implying that Loop handling, increment, if statement comparison AND Serial.println takes 465.98us each time
This means that the serial command, on its own, takes 458.435us, which seems massive in comparison.
My question, therefore... Am I right in my conclusion that the serial line is a massive bottleneck and should be avoided if fast execution is a must?
Are there any other protocols that would similarly hold up my code? - I2C, USB, etc? What would be recommended for speed?
Many thanks in advance,
Tim