Arduino Serial Monitor printing setup output twice

1.4k Views Asked by At

While working on a project, I found out that the Arduino Serial Monitor was printing the output of the setup() function twice.

So, in order to test what was actually happening, I tried it out with the following sample code:

const uint16_t MOD = 150;
const uint16_t val = 53314;
const uint16_t m = 30;
static uint16_t count = 0;

void setup() {
  uint16_t A[m][m];
  
  Serial.begin(9600);

  for (int i=0; i<m; i++) {
    for (int j=0; j<m; j++) {
      A[i][j] = val % MOD;
    }
  }

  Serial.println("DONE");
  Serial.println(A[0][0]);
  count++;
  Serial.println(count);
}

void loop() {}

And found out that every time I upload the code to Arduino it prints the setup() output twice.

Sample code execution

Can someone please provide an explanation as to why this is occurring?

The configuration of the system that I am using to upload the code:

System config

And, I am using an Arduino UNO board.

Arduino UNO board

1

There are 1 best solutions below

1
On

Even a delay of 200ms worked for me. Any Lower and I have double prints