Is there such a thing as fast Serial.println in a library some one has developed.
Similar to the fast digitalWrite functions.
The println's below tell me that loop() executes in 53 millisecods, but I would say that the vast majority of that time is in doing the serial output stuff.
I need to get a reasonably accurate execution time for these functions minus the serial output.
use Serial.write( ptr, len ); for a slight speedup.
Most of serial's work is done in interrupts. If you want to time your loop properly disable interrupts for the portion of code in test. This will prevent serial from clearing its buffers while your critical code is running. This is useful if you have a portion of code that must run uninterrupted :P.
If you forget to turn interrupts back on Serial will stop sending and also loose data once the buffer is full.
The library linked in my sig makes it easy.
{
AtomicBlock< Atomic_RestoreState > a;
//Code here is protected from interrupts.
}
//Code here is not protected.
If you forget to turn interrupts back on Serial will stop sending and also loose data once the buffer is full.
No, it won't. It will block waiting for room in the outgoing buffer. Of course, that will never happen, since room is made only by interrupts happening to shift data out, making room, and interrupts won't happen with interrupts disabled. So, the Arduino will hang.
If you forget to turn interrupts back on Serial will stop sending and also loose data once the buffer is full.
No, it won't. It will block waiting for room in the outgoing buffer. Of course, that will never happen, since room is made only by interrupts happening to shift data out, making room, and interrupts won't happen with interrupts disabled. So, the Arduino will hang.
Yeah I forgot that part, however the hang will only occur if the buffer is filled. I've had an app work fine, but no serial output until I intentionally sent large strings of frustration.
I'm hoping that my answer, which has to be the best one 8), and is about taking the serial prints out of the thing to be timed, has not been lost to the OP in the clutter arcane discussion.
JimboZA:
I'm hoping that my answer, which has to be the best one 8), and is about taking the serial prints out of the thing to be timed, has not been lost to the OP in the clutter arcane discussion.
Your answer is the most to the point one! The best way to minimize time spend is not doing it
robtillaart:
please post the whole sketch..... as this way no one can reproduce the problem.
You can use a higher baudrate e.g. 230400 and 345600 and 500000.
However the receiving end must support this speed.
I tried that.
Even if I go into Windows device manager and change the baud rate of the arduino com port and then use that baud rate in the call to Serial.begin I get total garbage in the serial monitor window.
boylesg:
if I go into Windows device manager and change the baud rate of the arduino com
That was news to me. So far all the programs I've used (Arduino IDE; Delphi, Processing ... ) you set the baud rate in the program when you "open" the port. Iif you set it i the window manager then the program will reset it to it's setting ... which fits you problem description.
robtillaart:
The Arduino IDE does not support higher than 115200 baud.
Use a terminal program like putty.exe (not the best but it works)
I like putty better than the serial monitor. No need to press the "send" button to transmit data. It's also more robust - if your sketch sends garbage serial data it's easy to crash the Arduino serial monitor.
I think managed to get a bit of a rough idea of how long serial.print takes to execute with a numerical string of 3-4 characters via a couple of consecutive calls to it and using a 'micros() - nLastCount' sort of thing.
It appears to be 400 - 500us with a string a 3-4 characters long.
So the function I am actually testing appears to take roughly 5ms to execute, taking into account the above.