Go Down

Topic: Serial.begin confusion (Read 411 times) previous topic - next topic

Rohitchampion

What is exact meaning and use of Serial.begin?? What does Serial.begin(9600) mean? What will happen if i change number inside parentheses?? What is exact meaning of 'communication between arduino board and pc'?? what will happen if i don't add that command??
please describe in details.. I am confused when i need to use this command??

Nick Gammon

http://arduino.cc/en/Serial/Begin
http://www.gammon.com.au/electronics

Rohitchampion

what is exact difference between Serial.begin(9600) and Serial.begin(4800)? How to decide what value to use??

Chaul

It's the communication speed. Doesn't really matter, except that the serial monitor may default to 9600 baud and you'll see garbage in there if the rate didn't match.

Edit: Yea, well, it does matter, but I hope you get the point..

Rohitchampion

Yeah. chaul, I got the point. but still confused where exactly to use Serial.begin command ?? what does this command exactly do?? in which programs is it supposed to use serial.begin?

Chaul

In the most typical case, you'd want to write debug messages from your code and you can monitor it with serial monitor. Another case is communicating with other devices through the serial port(s).

If you don't set up the communication by calling Serial.begin from within setup() once, those messages could not be sent out. Serial.print etc just wouldn't work. You can call Serial.begin from elsewhere, but why would you, because it concerns initializing the serial port. Nick already gave you the documentation for what it does:
Code: [Select]
void setup() {
    Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

Nick Gammon


what does this command exactly do??


It "turns on" (activates) the serial hardware, setting it to the requested baud rate. Without it, attempts to do Serial.print will fail.

However if you don't plan to do Serial.print (or write) then you won't care. You would use it if you need to do Serial.write or Serial.read.

Otherwise, not.
http://www.gammon.com.au/electronics

Go Up