first of al, english is not my first nor my second language so I'll try to do my best.
In the past few months I worked with the arduino 0022 software. Yesterday I finaly downloaded the new Arduino 1.0 software, where I found some interesting new feature in the serial.print function:
arduino reference page: "As of version 1.0, serial transmission is asynchronous; Serial.print() will return before any characters are transmitted."
So I made a little sketch to test this.
void loop() //Main Loop
{
timebegin = millis(); //take the time before sending data
Serial.print("lkjljlkjlkjljlkjlkjlkjlkjlkjlkjlkj"); // some random text, not important
timeend = millis(); //take the time afte sending data
Serial.println();
Serial.print(timeend);
Serial.print(",");
Serial.println(timeend);
delay(100); //wait some time before doing this loop again.
}
If I do timeend - timebegin. I get a value of 5ms. So the serial.print function took 5ms before returning. I compiled this sketch with arduino 0022 and arduino 1.0. There is no difference in time so where is the asynchronous ???
So if in arduino 1.0 the Serial.print() really would return before any characters are transmitted, why does It take 5ms to return and why is there no difference in time with the arduino 0022 version?
Moderator edit: </mark> <mark>[code]</mark> <mark>
If I do timeend - timebegin. I get a value of 5ms. So the serial.print function took 5ms before returning.
Since you didn't show setup, where Serial.begin() sets the speed, it's impossible for anyone else to replicate your test.
At reasonable baud rates, millis() is not particularly good as a timer. It's like using a calendar to time how long it takes your wife to get ready to go somewhere. Makes you feel like you are doing something, but that's about all.
Try using micros(), instead. Also, post ALL of your code.
Ok, now I see some difference. But still 2ms is a long time for just filling a streambuffer that will be send assync.
The fact is that I have another lager sketch with serial.print in it and a (fps) loopcounter. Logically I should, with the 1.0 version compared to the 0022 version now get more FPS/Counts in this sketch. But I don't :s
Moderator edit: </mark> <mark>[code]</mark> <mark>
So the time spend for serial.print() for sending the same string is less when decreasing baudrate. Increase the baudrate and the time spend by serial.print() will be larger. :s Can some explain this?
Moderator edit: </mark> <mark>[code]</mark> <mark>
The problem is that print(const char*) ends up writing to the buffer a character at a time. My new serial library is faster but still a bit slow since Print::print(const char*) calls Print::write(const char*) which does character at a time writes.
@Coding Badly:
thx for taking the time to do some tests. But you have a complete other sketch. Please try to use my sketch on a 8mhz board like I did. For most beginners, my sketch is more easy to understend. Your sketch does in fact the same but your code is more difficult for most beginners. So if you conclude that your timings are good with your code, then why are my timings bad with my code?
@fat16lib:
Also thx for taking your time to check out my problem. I'll check out your topic and test your code asap.
INFO: I use a atmega328 board running on 8mhz and downloaded the last arduino 1.0 version.
EXTRA: I took the time to compile some other sketches with arduino 1.0 and they are all slower compared to the same sketch compiled with arduino 0022. I do use micros() to compare timings en also use a simple loopcounter. I think I'll stay with arduino 0022 for a while.