Thessaloniki, Greece
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« on: December 07, 2012, 05:10:55 pm » |
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 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
Brattain Member
Karma: 277
Posts: 25556
Solder is electric glue
|
 |
« Reply #1 on: December 07, 2012, 05:39:38 pm » |
Is this normal? No but then I run a Mac 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #2 on: December 07, 2012, 05:48:51 pm » |
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.
|
|
|
|
Thessaloniki, Greece
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #3 on: December 07, 2012, 06:12:08 pm » |
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
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #4 on: December 07, 2012, 06:18:34 pm » |
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.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #5 on: December 07, 2012, 09:18:51 pm » |
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
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #6 on: December 08, 2012, 02:19:20 am » |
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
|
|
|
|
|
Thessaloniki, Greece
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #7 on: December 08, 2012, 12:57:45 pm » |
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 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
Brattain Member
Karma: 277
Posts: 25556
Solder is electric glue
|
 |
« Reply #8 on: December 08, 2012, 01:08:17 pm » |
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
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #9 on: December 08, 2012, 02:34:46 pm » |
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
|
|
|
|
|
Thessaloniki, Greece
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #10 on: December 08, 2012, 04:33:02 pm » |
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
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #11 on: December 08, 2012, 04:42:00 pm » |
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
|
|
|
|
|
Thessaloniki, Greece
Offline
Newbie
Karma: 0
Posts: 7
|
 |
« Reply #12 on: December 08, 2012, 06:47:08 pm » |
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
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #13 on: December 08, 2012, 09:13:49 pm » |
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
|
|
|
|
|
Offline
Sr. Member
Karma: 11
Posts: 393
|
 |
« Reply #14 on: December 08, 2012, 09:52:11 pm » |
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
|
|
|
|
|
|