创客百科

姿势共享,有节操无门槛参与的创客百科,创客动力之源 \ (^_^) /

用户工具

站点工具


en:arduino:language:serial_begin

Serial

begin()

Description

Sets the data rate in bits per second (baud) for serial data transmission. For communicating with the computer, use one of these rates: 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200. You can, however, specify other rates - for example, to communicate over pins 0 and 1 with a component that requires a particular baud rate.

Syntax

Serial.begin(speed)

Arduino Mega only:
Serial1.begin(speed)
Serial2.begin(speed)
Serial3.begin(speed)

Parameters

speed: in bits per second (baud) - long

Returns

nothing

Example:

void setup() {
    Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
 
void loop() {}

Arduino Mega example:

// Arduino Mega using all four of its Serial ports 
// (Serial, Serial1, Serial2, Serial3), 
// with different baud rates:
 
void setup(){
  Serial.begin(9600);
  Serial1.begin(38400);
  Serial2.begin(19200);
  Serial3.begin(4800);
 
  Serial.println("Hello Computer");
  Serial1.println("Hello Serial 1");
  Serial2.println("Hello Serial 2");
  Serial3.println("Hello Serial 3");
}
 
void loop() {}

Thanks to Jeff Gray for the mega example

See also

  • begin()
  • end()
  • available()
  • read()
  • peek()
  • parseInt()
  • flush()
  • print()
  • println()
  • write()
  • SerialEvent()

Reference Home

本页面的其他翻译:
en/arduino/language/serial_begin.txt · 最后更改: 2016/12/25 22:15 (外部编辑)