Pages: [1]   Go Down
Author Topic: Serial.begin confusion  (Read 382 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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??
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/en/Serial/Begin
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Finland
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Finland
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
void setup() {
    Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18806
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Pages: [1]   Go Up
Jump to: