Sparkfun RedBoard serial monitor problem

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.

Hi @Lagom,

that sounds really weird ...

Looks like other people also had problems with RedBoards and Serial. Not sure whether it helps you but you may have a look here [RedBoard Artemis Nano Serial NOT Working - SparkFun Electronics Forum](RedBoard Artemis Nano Serial NOT Working - SparkFun Electronics Forum

That's all I found in a hurry.

Good luck!

All right, I will check it out. At least all 10 boards serial print only once after the reset button is pressed.

Opening the serial monitor restarts the Arduino, there might be something left in the output buffer causing the problem.

Might be best to:

  • Power on the Arduino
  • Open the serial monitor
  • Clear the serial monitor screen
  • Press the reset switch on the Arduino

BTW

Consider this one change:

boolean hasRun = false;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  function();
}

void function()
{
  if (hasRun == false)
  {
    hasRun = true;
    int someValue = analogRead(A0);
    Serial.print("I ran only once ");
    Serial.print(someValue);
  }

}

Thanks, that four-step sequence of actions works with all 10 RedBoards.

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