Pages: [1] 2   Go Down
Author Topic: Serial Monitor first message Delay  (Read 1742 times)
0 Members and 1 Guest are viewing this topic.
Thessaloniki, Greece
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 I noticed some delay in serial monitor.
 Running a simple code like this , first message "Hello world"
 appears after 10 secs (i think was much faster before) .
 Is this normal?
 H/w :Mega 2560, Serial port at 9600, PC runing Windows 7

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

void loop(){
  Serial.println("Hello world");
  delay(1000);
}
« Last Edit: December 07, 2012, 05:36:29 pm by Zeus » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is this normal?
No but then I run a Mac  smiley

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26626
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Running a simple code like this , first message "Hello world"
 appears after 10 secs
Describe what you mean by "running"
Logged

"Pete, it's a fool 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.

Thessaloniki, Greece
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Running a simple code like this , first message "Hello world"
 appears after 10 secs
Describe what you mean by "running"
running=executing
When upload is done, i press serial monitor and message "Hello world" appears after 10 secs.
After reset , appears immediately, without delay !
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26626
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Describe what you mean by "running"
running=executing
Still pretty ambiguous.

You're aware opening the serial monitor resets the Arduino?
Logged

"Pete, it's a fool 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.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you "run" from the arduino IDE, it compiles and re-uploads every time, which does take several seconds. Then the program starts.
If pressing reset gives an immediate response, then it's working as it should.
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19326
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When upload is done, i press serial monitor and message "Hello world" appears after 10 secs.
After reset , appears immediately, without delay !

Does the serial monitor window appear immediately?
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Thessaloniki, Greece
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, serial monitor window appears immediately, but message appears after 10 sec.
After code upload , Led starts blinking (immediately after upload finish message), but if i press
Serial Monitor, Led Turns OFF for 10 sec, and Monitor doesn't show any message.
After 10 sec, everything is OK..
Serial.begin(9600) needs 10 sec to initialize port !!
My question is: Is this 'dead' time normal or too much ?

Try this code
Code:
void setup(){
  Serial.begin(9600);
  pinMode(8, OUTPUT);             // Connect an Led at Dig Pin 8
}

void loop(){
  digitalWrite(8, HIGH);          // Turn ON Led for 0.5 sec
  Serial.println("LED is ON");    //Serial Monitor: Led is ON
  delay(500);                     // Keep it ON for 0.5 sec

  digitalWrite(8, LOW);           // Turn OFF Led
  Serial.println("LED is OFF");   //Serial Monitor: Led is OFF
  delay(500);                     // Keep it OFF for 0.5 sec
}
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
My question is: Is this 'dead' time normal or too much ?
No this is too much. However it sounds to me like a PC problem rather that an arduino problem.
When a port opens the arduino is reset, this triggers the boot loader to look to see if a program is being up loaded. It looks like your PC is doing something to to make the boot loader think something is being downloaded but when more fails to arrive it goes on and runs your sketch.
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19326
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Serial.begin(9600) needs 10 sec to initialize port !!
My question is: Is this 'dead' time normal or too much ?

It would take a couple of microseconds to initialize the port. Something else is wrong. You may have a bootloader that is not working quite right.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Thessaloniki, Greece
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick, Mike and other friends , thank you for your quick response.
I already tryed with another Pc, but the problem is the same.
I noticed that, when i start serial monitor,board's yellow Led L (Dig pin 13) stays always on, and turns OFF only after reset.
Probably Something is wrong with DTR or Atmega 16U2.
I will try to see the waveforms with my oscilloscope.
Is it possible to burn the bootloader without any external hardware (using Usb-Serial port) ?
Sorry for all these questions but even i have more than 30 years of experience in electronics, i'm learning Arduino programming right now !!
« Last Edit: December 08, 2012, 04:35:13 pm by Zeus » Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19326
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sometimes that LED stays on, I think that is an artifact of the bootloader.

You can't burn a new bootloader without some other hardware, for example an Arduino Uno. Or you can get a $10 ISP programmer from eBay or elsewhere.

It isn't necessarily the bootloader, it just sounds strange the way you describe it.

You have 9600 baud selected in the serial monitor, I take it? The only delay I can think of, though, is the bootloader is indeed holding up handing control over to the main sketch. Your scope might help. A logic analyzer might be better. One way or the other you should be able to see if the board is trying to communicate after the reset caused by the monitor being started up (or indeed if that even happens). Try monitoring the reset pin with your scope.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Thessaloniki, Greece
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's getting more and more mysterious!
Trying Serial.begin rates from 9600 to 115200, only at 57600 is Ok.
Yellow (L) Led blinks twice and messages appear immediately !
All other rates do what i described above!
So, the problem might be the timing during software reset.
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19326
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There could be some strange interraction between the USB interface chip and the processor. I presume the USB side has to auto-detect the baud rate.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
God Member
*****
Karma: 32
Posts: 830
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It's getting more and more mysterious!
Trying Serial.begin rates from 9600 to 115200, only at 57600 is Ok.
Yellow (L) Led blinks twice and messages appear immediately !
All other rates do what i described above!
So, the problem might be the timing during software reset.

This has had me scratching my head for a while. It does seem to be a problem specific to the latest bootloader on the mega2560, and the way it interacts with the IDE (1.0.2 at least - I haven't tested with other versions). I can confirm your observation that execution being passed to the main program is delayed several seconds (~5 or 6 seconds in my case) _except_ when the baud rate of the Serial monitor in the IDE is set to 57200.

No delay problem on Mega1280, Uno, Leo etc.

Two other things:

1) If you open the Serial monitor on the IDE at 57600, even if the Serial.begin on the board is set to a different baud rate (e.g., 115200), you still don't get the delay. (You get gibberish on the screen, of course, but you can see the sketch starts to execute without the delay).

2) If you open a Serial monitor _outside_ the IDE (e.g., using Putty), you don't get the delay, even if you open it at 115200. Works normally without a start-up delay for Putty at all baud rates I've tested.

So the problem seems to be an interaction specific to the IDE and the Mega2560 bootloader when the IDE opens a Serial monitor at any baud rate I've tested, except for 57600. Clearly nothing to do with USB hardware and bootloader interaction at all,

Which is good to know, because until I came across this thread I thought the new Mega2560 bootloader had a 5 second delay built-in on reset.  Now that I know it is just an artifact of interacting with the IDE, it sounds like a much less serious problem.

Good find on the 57600 "special case"!

 
« Last Edit: December 08, 2012, 10:31:15 pm by pico » Logged

WiFi shields/Yun too expensive? Embeddedcoolness.com is now selling the RFXduino nRF24L01+ <-> TCP/IP Linux gateway: Simpler, more affordable, and even more powerful wireless Internet connectivity for *all* your Arduino projects! (nRF24L01+ shield and dev board kits available too.)

Pages: [1] 2   Go Up
Jump to: