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.
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.
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.
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.