Go Down

Topic: 2 values sent when sending data from serial monitor (Read 314 times) previous topic - next topic

ian-northpb

Whenever I send any value to the serial monitor, it returns the value I sent, as well as the value for the return key. It does this when I press enter to send the data, or when I click send, it doesn't matter. How do I prevent this because it prevents me from using the serial monitor to control my Arduino functions? My code is pasted below, and I have attached a jpg of the serial monitor data. When you look at the serial monitor data, the first value it prints is the value I typed, then immediately after it prints -38, the enter key/send button. Any help is appreciated, thanks.
I am working with an Arduino Uno and am running Arduino IDE 1.8.9 on Mac OS Mojave.

Code: [Select]
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available())
  {
    Serial.println(Serial.read()-48); // Print actual value of digit (0-9) sent from serial monitor
  }
}

pert

In the Serial Monitor, you can select the line ending that it will insert from a menu. If you set that menu to "No line ending", then you will not receive any line ending at all.

Alternately, you could write your code so that it can handle any line ending.

ian-northpb


pert

You're welcome. I'm glad to hear it's working now. Enjoy!
Per

Go Up