Serial in atmega328p printing twice

I burnt a freshly bought Atmega328p using the arduino IDE. Later I uploaded the following program:

char a;

void setup() {
Serial.begin(9600);
}

void loop() {
while (Serial.available() > 0) {
a = Serial.read();
Serial.println("I received: ");
Serial.println(a);
break;
}
}

So if I entered 'a' in the serial monitor it was supposed to print,

I received:
a

but instead it is showing:

I received:
a
I received:

I'm using FTDI breakout board as UART.

What to do?

(A snippet of the serial monitor is attached with this post)

Capture.PNG

Capture.PNG

The "ENTER" key or in ASCII term "\r"

Thanks. But how to correct it?

Something like an if-else statement


a = Serial.read();
if(a == '\r') {
// do nothing
}
else {
print(a);
}

You can have a look at the line ending setting in the serial monitor.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.