Program starts twice when downloading.

Hi,
I'm new to Arduino. I'm using the Uno and IDE 1.0.5 to program and download.
Each time when I download a program it starts running then it is aborted and started again.
In my program I print some strings to the Serial Monitor. After download I see a few strings in the Monitor, then I see
the first strings again (indication that program is restarted), and it will run to the end (printing all the strings).

How can i make sure the program is nicely started only once?

(deleted)

spycatcher2k:
Read the stickies and then POST YOUR CODE

Sorry, I was thinking this problem is not related to specific code. But here it is:

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // send
  Serial.println("\nString  11111111111111111111111111111111111111111");
  Serial.println("\nString  22222222222222222222222222222222222222222");
  Serial.println("\nString  33333333333333333333333333333333333333333");
  Serial.println("\nString  44444444444444444444444444444444444444444");
  Serial.println("\nString  55555555555555555555555555555555555555555");
  Serial.println("\nString  66666666666666666666666666666666666666666");
  Serial.println("\nString  77777777777777777777777777777777777777777");
  Serial.println("\nString  88888888888888888888888888888888888888888");
  Serial.println("\nString  99999999999999999999999999999999999999999");
}

void loop() {
}

And this is the output to the Serial Monitor:

Str88888888888

String  99999999999999999999999999999999999999999
7777777777777777777777

String  88888888888888888888888888888888888888888

String  99999999999999999999999999999999999999999

String  11111111111111111111111111111111111111111

String  22222222222222222222222222222222222222222

String  33333333333333333333333333333333333333333

String  44444444444444444444444444444444444444444

String  55555555555555555555555555555555555555555

String  66666666666666666666666666666666666666666

String  77777777777777777777777777777777777777777

String  88888888888888888888888888888888888888888

String  99999999999999999999999999999999999999999

I forgot to mention I'm running the IDE on a Mac.

I load the program and then switch the Serial Monitor on.

(deleted)

spycatcher2k:
You are running out of Ram, try this :

Serial.println(F("\nString 11111111111111111111111111111111111111111"));

Same problem.

(deleted)

spycatcher2k:
Did you make the change to all the print lines

Yes

(deleted)

I noticed this curious thing:

After downloading the program, it probably automatically starts the program.
When I wait a long time before opening the Serial Monitor. I initially see first this on the Serial Monitor:

Str9999999999999
7777777777777777777777

String  88888888888888888888888888888888888888888

String  99999999999999999999999999999999999999999

And then I see it runs the program again and it finally shows:

Str9999999999999
7777777777777777777777

String  88888888888888888888888888888888888888888

String  99999999999999999999999999999999999999999

String  11111111111111111111111111111111111111111

String  22222222222222222222222222222222222222222

String  33333333333333333333333333333333333333333

String  44444444444444444444444444444444444444444

String  55555555555555555555555555555555555555555

String  66666666666666666666666666666666666666666

String  77777777777777777777777777777777777777777

String  88888888888888888888888888888888888888888

String  99999999999999999999999999999999999999999

Thus it seems that when running the first time (immediately after download) some serial information is lost.
And when opening the Serial Monitor the program is running again.

Can I somehow disable the automatic run after download? And only run when opening the Serial Monitor?
That would give me a nice clean start of the program.

spycatcher2k:
1st remove :
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

as it says, its for the Loenardo

2nd - it works on my UNO , so im lost to why it will not work

When removing those lines, the result is the same.

Don't forget that opening the serial monitor causes a reset.

Unless you put a wait in the code, your sketch start running immediately, reset when you open the monitor, and then keep running.

The buffer on your PC will show you the whole mess.

So it would be much cleaner to keep the Serial Monitor open when downloading. But that seems not possible.

Is it possible to:

  • download
  • connect to Serial Monitor
  • finally do the Arduino reset

That would also be cleaner

mechamania:
So it would be much cleaner to keep the Serial Monitor open when downloading.

That's not how Serial works. One device at a time.

A simple 2-5 second wait at the start of the program would be one way. Another is to sit in this loop right after Serial.begin. Then use the Serial monitor (once connected) to send a single character (w/ LF and CR turned off)

while(Serial.read() == -1);