[Solved] web editor: Serial.available() receiving random 0's and other chars

Hello,

The web IDE seems good but I'm getting random 0's and other characters on Serial.available().

This code works well with the stand-alone Arduino IDE and sits for a long time quietly with no input or output, as expected. If you punch in a 1 or 0 it will report that but otherwise reports nothing on the serial console.

But on the Arduino online web IDE it gets lots of random 0's and other characters without entering anything into the serial monitor.

   void setup() {
     Serial.begin(115200);
     Serial.flush();
   }

   void loop() {
     if (Serial.available() > 0){
       int myCmd=Serial.parseInt();
       Serial.println("received ["+String(myCmd)+"]");
     }
   }

Why does the web ide's Serial.available() report these zero and other characters on the serial console as input by the user without the user actually punching anything in?

received [0]
received [0]
received []
received [0]
received [0]
received [0]
received [0]
received [0]rreceived [0]
received [0]
received [0]
received [55
received [0]
received [0]
received [0]
received [0]
received [0]
received [0]
received [0]
received [0]rreceived [0]
rec[0
[0
received [0]
rVV˕5
r5
received [0]
received [0]
received [0Crreceived [0]
received [0]
received [0]
received [0]
received [0]

Setup: Dell Inspiron with Windows 10 and Chrome (Version 62.0.3202.94) and Arduino Uno R3.

web IDE screenshot attached.

Thanks,
Marc Compere

Is this a particular board or all boards ?

The Arduinos are nearly all quite noisy especially on the analog inputs.
You can see that noise in the desktop IDE by watching any of the analog inputs on the graph function of the serial monitor.

Clones are a little quieter but not by much.
Power spikes or fluctuations are also a common issue especially on laptops.

Not able to reproduce your issue on an MKR zero on the web editor but saw it on the desktop IDE almost like a null echo as I got the zeros after any inputs.
Same results with a UNO which is opposite to what you are seeing.

EDIT... Can reproduce your findings now but so far only with a UNO.

Thanks for your report, we will look into it

Hi @comperem,

Do you have the same new line setting in the regular IDE?

The extra [0]'s are from parsing the new line characters sent by the monitor. I can reproduce this on the Java IDE on my Mac as well.

I haven't been able to reproduce the other characters though.

I've only tried this on the Arduino UNO R3.

ballscrewbob:
Is this a particular board or all boards ?

Have you tried as Sandeep suggests with changing the NL / CR termination etc.

I tried again this morning with similar results on the web-based IDE. All settings on the web IDE's serial monitor (No line ending, NL, CR, NL+CR) seemed to generate some level of zero's and occasionally others characters.

On the stand-alone IDE, I used the 'No line ending' setting for the original post. Attempting again produces similar results - it sits quietly until a user enters a number. The additional settings (NL, CR, NL+CR) on the stand-alone IDE serial monitor seem to add an additional trailing zero after a user enters a number. This is not exactly what you want but it's also very predictable after a user enters a number. None of the serial monitor settings generte random inputs from Serial.available().

It's an issue with the web IDE for sure. Not normal and not expected.

MDC

sandeepmistry:
Hi @comperem,

Do you have the same new line setting in the regular IDE?

The extra [0]'s are from parsing the new line characters sent by the monitor. I can reproduce this on the Java IDE on my Mac as well.

I haven't been able to reproduce the other characters though.

Capture.JPG

Noise or uncertainty on analog input pins is almost entirely unrelated.

This is the purpose of a pullup resistor. Arduino UNO R3's have pullup resistors on digital inputs and also analog inputs:

pinMode(A0,INPUT_PULLUP);

ballscrewbob:
The Arduinos are nearly all quite noisy especially on the analog inputs.
You can see that noise in the desktop IDE by watching any of the analog inputs on the graph function of the serial monitor.

Clones are a little quieter but not by much.
Power spikes or fluctuations are also a common issue especially on laptops.

Also testing on a MEGA now and if I turn off line endings on the desktop IDE the issue goes away.

Same setup in CREATE and I see the issue clearly despite having no line endings.

Hi everyone,
the problem should be gone with [WIN] avoid generating spurious USB transactions on Read() timeout · arduino/arduino-create-agent@906c87e · GitHub

I tested it on a Windows7 VM and it doesn't send spurious data anymore.

Before going live for everyone I'd ask you to test the -dev version of the agent from http://downloads.arduino.cc/CreateBridge/staging/ArduinoCreateAgent-1.0-windows-installer.exe.
Please report here if you experience any trouble (also totally unrelated) while using it.

Thanks!

The fix is now available on prod, you should see your plugin updating to 1.1.62 and this issue should be gone. Thanks again for your report.