Seeing double with Mega2560

Environment: Win 10, Arduino 1.8.13, Genuine Arduino Mega2560

In this extremely simple sketch I would expect "Hello" to be sent to the serial monitor ONE time, but it appears twice each time it is run.

I have two Mega2560 boards on two different computers and it is doing the same thing on both.

Can someone explain this?

// example mega2560 problem
void setup()
{
  Serial.begin(115200);
  while (!Serial);
  Go();
}

void loop()
{
}

void Go()
{
  Serial.println("Hello");
}

So if you just clear the serial monitor then hit reset it does it twice?

In my MEGA, the message appears just for once.
smQ1.png

smQ1.png

ToddL1962:
So if you just clear the serial monitor then hit reset it does it twice?

No, in that case it works correctly.

So the problem is when I upload the code.

In this tiny example sketch, it's not a problem. In my actual sketch, it is causing a DC motor to operate twice the first time out of the gate.

I could post that code, but if this simple problem can be solved, it would most likely fix the main problem.

PickyBiker:
No, in that case it works correctly.

So the problem is when I upload the code.

In this tiny example sketch, it's not a problem. In my actual sketch, it is causing a DC motor to operate twice the first time out of the gate.

I could post that code, but if this simple problem can be solved, it would most likely fix the main problem.

That's because it runs when it is powered up and then the board is reset when the upload is done.

It is always powered up by the USB. It may reset it but the power is always there. i just tried it with a Teensy board and it doesn't have this problem.

GolamMostafa above doesn't have that problem either with his Mega2560.

I am going to try an older version or the Arduino software.

Deleted version 1.8.13 and installed version 1.8.6. The sketch runs fine with only a single "Hello" output.

Deleted 1.8.6 and installed 1.8.13 and the problem returns.

Somewhere between 1.8.6 and 1.8.13 the double output was introduced on the Mega2560 board.

GolamMostafa what version of Arduino software are you running?

Tried it with 1.8.11 and it works fine with that version too.

I am looking for a copy of 1.8.12 to try.

Found 1.8.12 and it works fine with that.

The problem only occurs in 1.8.13.

I will enter an issue on github.

I bet there is just a double reset going on.
You could toggle an LED during setup() and see if it flashes twice as a simple test.

CrossRoads:
I bet there is just a double reset going on.
You could toggle an LED during setup() and see if it flashes twice as a simple test.

Yes, that's what it is. I put a 100ms delay right after setting to the Serial port and no problem. It is starting twice so I just wait out the first one with a delay and it works okay.

There is a notable difference between my PC's.

On my fast PC, fast mem, fast ssd, there is no problem with 1.8.12. However, when I put 1.8.12 on my old and very slow pc, it still fails even with 1.2.12, and 1.2.11. So the speed of the PC affects this problem. I opened an issue on github and referred back to this post. For now on the slow PC I'm just using the 100ms delay.