Go Down

Topic: Arduino Nano isn't working well with Baud rate 9600 bps, why? (Read 1 time) previous topic - next topic

This is a newbie question.
I connect my Arduino nano with PC using USB. The following sketch is tested:
int out = 3;
void setup() {     
  Serial.begin(9600);
}
void loop() {
println(out);
}

I clicked the Serial Monitor button of Arduino 1.0 IDE to watch the results.
Why did it display gibberish when the Baud rate 9600 was chosen in the Serial Monitor ?
However, it displayed right when the rate 19200 was chosen. Obviously this setting was inconsistent with the Baud rate in the above sketch. Weird.
Anyone can help? Thank you!

el_supremo

Your code worked on my Nano after I changed println(out) to Serial.println(out).

Pete

Actually my code is Serial.print(out). Sorry for the typos when posting it.
I just checked again. It still wasn't working.
Did you check the serial monitor of your Arduino IDE with different baud rate? Why mine is outputting gibberish with 9600.

el_supremo

It works fine at 9600 and outputs junk at 19200

Pete

When I use Serial.begin(9600), the serial monitor of Arduino outputs junk at 9600 and works fine at 19200;
When I use Serial.begin(19200), the serial monitor outputs junk at both 19200 and 9600.
I don't why it could happen.

Nick Gammon

Looks like your Nano is running at 8 MHz. That would account for why you need to double the baud rate (from 9600 to 19200) to get 9600 actually being sent.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

mellis

Nick, I think it might be the opposite.  That is, the board is probably running at 16 MHz but the code is being compiled for 8 MHz.  So when you say Serial.begin(9600), you're actually getting 19200 baud. 

bigthunder, are you sure you have the right item selected in the boards menu?

Nick Gammon

Good point. I didn't think the arithmetic through enough. What you suggest is probably right, that the wrong board is selected in the menu, and the sketch is compiled with the wrong constants for the serial port, however the bootloader happens to match.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Thank you so much.
I made the mistake. I used the board Arduino Fio which I had set before. Now it's working perfect. Some coincidence did happen by this mistake.

Go Up