IDE 2.0 Beta 7 ; Serial monitor displays the wrong switching states HIGH/LOW

A simple sketch to query an input at the Arduino UNO the status is displayed wrong on the serial monitor. On the IDE 1.8.15 it works fine.

I have also output the status on the built-in LED and this also works fine.

const int impEingAne = 10 ;

void setup()
{
pinMode(impEingAne, INPUT);
pinMode(LED_BUILTIN, OUTPUT);

// Status Monitor
Serial.begin(115200);
}

void loop()
{
aImp=digitalRead(impEingAne);

if (aImp==LOW)
{
Serial.println("0");
digitalWrite(LED_BUILTIN, LOW);
}

if (aImp==HIGH)
{
Serial.println("1");
digitalWrite(LED_BUILTIN, HIGH);
}

}

Please clarify how the input pin is wired. Do you have a pullup or pulldown resistor in place to keep the input in a known state at all times ?

Please use code tags when posting code

See How to get the best out of this forum

Hi @xvs03. Thanks for giving the beta stage Arduino IDE 2.x a try!

The reason for the results your observing is that, unlike the classic Arduino IDE, Arduino IDE 2.x's Serial Monitor currently has a very poor throughput. It simply can't keep up with this sort of sketch that blasts it with data as fast as the microcontroller can pump it out. So what is happening is you are seeing older and older data in the Serial Monitor as it gets farther and farther behind on outputting the backlog. If you wait long enough, you will see the changed pin state come through, but of course we expect it to be immediate.

The deficiency is being tracked here:

If you add some code to your sketch to limit the serial prints to a reasonable rate, you'll find it works as expected. The easiest way to do that is to just add a delay(), but of course that can often cause problems. You could also modify your sketch to only print when the pin state has changed.

1 Like

Thank you for the explanation.
Yes the time difference I have also noticed. Thanks for your tips. I hope in the final version the problem will be overcome. I personally like the version 2.0 already very much.

Hello the problem has nothing to do with the wiring, because the LED shows everything correctly.
I will use the tags in the future, please excuse me.

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