Serial.available() doesn't return 0 when no data has been entered into the Serial Monitor when the baud rate set higher than 9600 #1297
Labels
conclusion: duplicate
Has already been submitted
topic: code
Related to content of the project itself
topic: serial monitor
Related to the Serial Monitor
type: imperfection
Perceived defect in any part of project
Describe the problem
I was working on a program that requires the use of
Serial.available()
and it was working fine with the baud rate set to 9600. However, I started running into an issue when increasing the baud rate to 19200 or higher (with both in the code and the Serial Monitor set to the same). The issue is thatSerial.available()
returns 2 instead of 0 when called without entering anything into the Serial Monitor. This also happens regardless of whether you change "New Line" to any of the other options including "No Line Ending". I can easily replicate the issue with the following code:Something else I noticed is that when running that snippet if you change "New Line" to any of the other options, the value returned increases from 2 to 8 to 14. Not sure if that is related.
Another oddity is that if I change the code to:
Then it works correctly and the buffer will decrease (even if you enter data) if you read from it like this:
However removing the
Serial.println()
line and running the modified code doesn't work the same way. The buffer doesn't reach 0 like it was before with theSerial.println()
line included.To reproduce
You can also try changing the baud rate to 9600 in the sketch and Serial Monitor. With just that change the code now works correctly and only returns a number greater than 0 if you enter data in the Serial Monitor.
Expected behavior
I would expect that no matter what the baud rate is set to in the IDE 2's Serial Monitor that
Serial.available()
would return 0 unless there was data in the buffer from you entering it.Arduino IDE version
2.0.0-rc9.1-nightly-20220805
Operating system
Windows
Operating system version
Windows 10 Pro - OS build 19044.1826
Additional context
I tried running the same code snippet in the IDE 1.8.19 version and it works correctly without reuploading the code. Also, using another serial port monitor like PuTTy works fine too with the same code uploaded from the IDE 2. So it seems like the issue lies in the Serial Monitor at least to me.
Issue checklist
The text was updated successfully, but these errors were encountered: