I unpacked a class-pack of sparkfun RedBoards. To check them, I run the dummy code below. USB connection to laptop with original cable from each pack. With the serial monitor open, same baud rate, I get an inverted question mark and the serial printing occurs twice. In WOKWI only once. If I press the reset button on the RedBoard, serial printing only occurs once with 8 out of the 10 class-pack RedBoards. Any ideas for what's going on? Laptop issue? Cable issue? RedBoard issue? Thanks!
boolean hasRun = false;
void setup()
{
Serial.begin(9600);
}
void loop()
{
function();
}
void function()
{
if (hasRun == false)
{
int someValue = analogRead(A0);
Serial.print("I ran only once ");
Serial.print(someValue);
}
hasRun = true;
}
After uploading with the serial monitor window open, closing the serial monitor and then opening it often results in a single execution as expected, but not always. When double printing, the analogRead values are different, so the code gets executed twice for sure.