Go Down

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


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.

Go Up