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:
Arduino IDE 2.0.0 rc3 and rc4. No difference, same problem.
compiled same code using IDE 1.8.18. Output is 0's, as you would expect.
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:
opened 04:26AM - 16 May 21 UTC
closed 10:13AM - 01 Dec 22 UTC
conclusion: resolved
topic: code
type: imperfection
topic: serial monitor
## Describe the bug
π Spurious data is sent by the Serial Monitor over the coβ¦ nnected serial port.
## To Reproduce
### Equipment
- One of the following Arduino boards:
- Arduino Uno
- Arduino Mega
- Arduino Due
### Steps
1. Paste the following simple serial echo sketch into the Arduino IDE:
```cpp
void setup() {
Serial.begin(115200);
}
void loop() {
if(Serial.available()){
Serial.println(Serial.read());
}
}
```
1. Upload to the Arduino board.
1. Open Serial Monitor
1. Set the baud rate menu to 115200.
π The Serial Monitor's output field shows unexpected data is being received by the Arduino board and echoed back by the sketch. Something like this:
```text
240
240
240
240
240
240
```
... and so on
## Expected behavior
Data is only sent over the serial port by Serial Monitor when the user sends it via the input field.
## Desktop
- OS: Windows 10
- Version: Version: 2.0.0-beta.6-nightly.20210515
Date: 2021-05-15T03:10:15.375Z
CLI Version: 0.18.2 alpha [7b5a22a4]
## Additional context
I have only been able to reproduce this on my Arduino Mega, Arduino Uno, and Arduino Due (via Programming Port only). Based on the commonality of their ATmega16U2 USB chip, I expected to also be able to reproduce it on my Arduino Uno Mini LE, but I was not able to.
On my Leonardo and Micro boards, the RX LED flashes at 1 Hz while the Serial Monitor is connected, indicating unexpected data is being received, but I don't get any output from the echo sketch.
---
I notice that the ~1 Hz frequency of the spurious data appears to match the frequency of the notification displayed repeatedly after the board is disconnected while Serial Monitor is open (https://github.com/arduino/arduino-ide/issues/314):
> Reconnecting Arduino Mega or Mega 2560 to COM18 in 1 seconds...
This makes me wonder if already open ports are constantly being reopened at 1 Hz the whole time Serial Monitor is running. Further evidence supporting this is that I get the RX blink on the Leonardo whenever I do a manual [`StreamingOpen` gRPC request](https://arduino.github.io/arduino-cli/latest/rpc/monitor/#cc.arduino.cli.monitor.v1.StreamingOpenRequest) to the port.
---
It appears the data is sent at 115200 baud.
---
As reported at at https://github.com/arduino/arduino-ide/issues/1297, changing the selection in the line ending menu triggers the immediate sending of additional spurious data in addition to the regular periodic data reported above.
I notice the same happens when you toggle the "**Toggle Autoscroll**" or "**Toggle Timestamp**" icons.
None of these should result in any data being sent to the board.
---
Originally reported at: https://forum.arduino.cc/t/serial-monitor-sends-random-f0/850819
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!
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 -> recβ¦
system
Closed
September 6, 2022, 9:08pm
6
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.