Serial Monitor sends random F0

I have a program that runs in a interrupt. I use the loop() to monitor the serial communication and turn the interrupt on and off depending on the number I send (10 for on / 20 for off).

This works wonderful with the Serial Monitor of the old IDE. But with the new IDE, the Serial Monitor is sending 0 about every second (actually it sends some symbol that cannot be displayed in the Serial Monitor, which is converted to 0 by the .toInt() function.)

17:10:50.480 -> received: 0
17:10:51.488 -> received: 0
17:10:53.508 -> received: 0
17:10:55.525 -> received: 0
17:10:56.536 -> received: 0
17:10:57.539 -> received: 0
17:10:59.546 -> received: 0
17:11:01.559 -> received: 0

Furthermore, when I try to send a command, it only works about 1 out of 10 times. (With the Serial Monitor of the old IDE it never missed a transmission so far). More precisely: 1 out of 10 times the Serial Monitor will get a "received: 10" response, while the other 9 times the message dissapears from the Message box after I hit Ctrl+Enter but there is no reaction from the Arduino Due.

Here the part listening for the serial communication in my code. I run the Serial at 115200 baud.

void loop ()
{
  while (Serial.available() > 0) {
    int incomingByte; // for incoming serial data

    // read the incoming byte:
    incomingByte = Serial.readString().toInt();

    Serial.print("received: ");
    Serial.println(incomingByte);

    if(incomingByte == 10){
      asvRun(); // enable my interrupt
    }
    else if(incomingByte == 20){
      asvClose(); // disable my interrupt
    }
  }
}

Serial.readString()does timeout after 1 second and returns nothing, which you'll see as number 0

I would suggest to study Serial Input Basics to handle this

Thanks for the reply! That is great to know. But why does it even get to Serial.readString() when there should be no Serial.available()? Or do I missunderstand that mechanism?

Usually I suspect such an error to be something with my code. But the different behaviour of the old and new Serial Monitor confuses me. And this also does not explain the missed messages...

fair point

you have at least 1 byte pending, but you might have characters that are not digits, like \r or \n or something else

can you try

void loop ()
{
  int r = Serial.read();
  if (r != -1) {
    if (r < 0x10) Serial.write('0');
    Serial.println((byte) r, HEX);
  } 
}

and see if you get constant chatter on your serial line

BTW - do you have stuff connected on pins 0 and 1? (which Arduino?)

I originally used a Arduino Due and tried it on the Arduino Uno now. Same issue but only on the Serial Monitor of the new IDE

Using your code I get constat F0 and still many of my sent messages don't get through

21:34:58.506 -> F0
21:34:59.505 -> F0
21:34:59.515 -> F0
21:35:00.521 -> F0
21:35:00.522 -> F0
21:35:01.520 -> F0
21:35:01.540 -> F0
21:35:02.537 -> F0

Using the old Serial Monitor, your code works just as I would expect (nothing happens until I send something, which I then get back inAscii code in hex followd by A0).

here the result of sending "a", "b", "ab" and "abc"

21:40:41.890 -> 61
21:40:41.890 -> 0A
21:40:43.293 -> 62
21:40:43.293 -> 0A
21:40:44.709 -> 61
21:40:44.709 -> 62
21:40:44.709 -> 0A
21:40:46.360 -> 61
21:40:46.360 -> 62
21:40:46.360 -> 63
21:40:46.360 -> 0A

what do you call old and new Serial Monitor? are you using version 2.0 of the IDE?

Yes exactly. I think this is a issue of the Serial Monitor in the new IDE 2.0

Hi @stleuch. Thanks so much for your report, and to J-M-L as well. I am able to reproduce this issue. I am still working on the investigation because so far I am finding that it only occurs with certain boards. For example, it occurs with:

  • Leonardo
  • Mega

It does not occur with:

  • MKR Zero
  • Zero
  • CH340-based Nano derivative

I also see that the spurious data from Serial Monitor is sent at 115200 baud, so it's necessary to use that rate in order to correctly see the data.

I'll submit a formal bug report to the IDE developers soon and report back here with my findings.

thx @pert

Hi all. Sorry for the slow follow up. Here is the bug report:
https://github.com/arduino/arduino-ide/issues/375

I had observed such a problem with a ESP32 when I had used an USBtoSerial connector attached to the ESP, but left it open - i.e. nothing connected to - at the USB end of it.

Though this was on Ar 1.8.13 with ESP core 1.0.4.

I'd say this was a hardware issue. Can you rule out a similar hardware problem?

@pert Thanks for the report and the update!

Also experienced spurious signals on a SparkFun Pro Micro using Version 2.0 IDE Serial.
Installed system has run for years, having been refined and tested several times with Version 1 IDE Serial - never encountered this issue until Version 2.0 IDE.

Thanks for the great work. Really like the new version. Much appreciated.

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