Setup function not executing

I am sure I am missing something extremely simple here. But why doesn't this code print "hi"?
When someFunc() is placed in the loop it works, but not in setup.

void setup() {
  Serial.begin(115200);
  delay(1000);
  someFunc();
}

void loop() {
  // put your main code here, to run repeatedly:
  //someFunc();

}

void someFunc()
{
  Serial.println("hi");
}

Does it print if you do this?

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println("hi");
}

void loop() {
}

Which Arduino board are you using ?

hmm, strangely no that doesn't print either...

I am using MKR Zero

Then the problem is unrelated to "External function scope"

Try this

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  someFunc();
}

void loop()
{
}

void someFunc()
{
  Serial.println("hi");
}
1 Like

what is your serial monitor bit rate?

That did it. Thanks!
I also found that adding a delay(1000); after the Serial.begin worked. So it must be firing before the serial has initialized. I thought it was some weird scope issue.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.