Serial monitor 2.0.0 not working?

What should these two lines do?? Note that I input nothing into the serial monitor. It should send zero to the serial monitor repetitively, right?

void setup() 
{
  Serial.begin(9600);
}
void loop() 
{
Serial.println(Serial.available());
delay(2000);
}

Instead, I get numbers counting up usually by 1's, like so:

18:33:12.144 -> 0
18:33:14.131 -> 1
18:33:16.160 -> 2
18:33:18.142 -> 3
18:33:20.157 -> 5
18:33:22.131 -> 6
18:33:24.144 -> 8
18:33:26.140 -> 9
18:33:28.156 -> 11

Def. not random.
HP laptop, win10, new Due board on programming port, 9600 baud on both ends.
Tried:

  1. Arduino IDE 2.0.0 rc3 and rc4. No difference, same problem.
  2. compiled same code using IDE 1.8.18. Output is 0's, as you would expect.
  3. compiled same code using IDE 1.8.18. Output as you would expect. Then moved that Due to IDE 2.0.0 without re-compiling. Displays same flaky problem when proven-to-work-properly-Due is connected to (IDE 2.0.0) Serial monitor.

Sure does imply serial problems in the IDE somewhere. Please forgive me if a solution has been posted - I've seen similar problems described here, but I couldn't find a solution. (e.g., Serial.read() and Serial.available() are working not as expected in the code

What gives?

/*
  SerialEvent occurs whenever a new data comes in the hardware serial RX. This
  routine is run between each time loop() runs, so using delay inside loop can
  delay response. Multiple bytes of data may be available.
*/
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}

Source: Arduino IDE: File > Examples > 04.Communication > SerialEvent

https://docs.arduino.cc/built-in-examples/communication/SerialEvent/

Hi @laramsey. Thanks for giving the Arduino IDE 2.0.0 release candidate a try!

This bug is being tracked by the IDE developers here:

If you have a GitHub account, you can subscribe to that issue to get notifications of any new developments related to this subject.

I'm seeing the same problem with the serial monitor in Web editor, also in IDE 2.0.0 rc5. IDE 2.0.0 is heavily promoted in the pro section of the website and elsewhere... seems like a pretty significant bug affecting a fundamental feature. Hope you guys can fix asap. Thank you!!

If I understand correctly, April will be a year?? Say it aint so!

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