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.)
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
}
}
}
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...
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"
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.
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?
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.