Arduino for BPI:bit 5 :how to use bpi:bit Serial port

The concept of > Serial Communications is simple, and Serial ports send and receive bytes by bit.In serial communication, the most important parameters are baud rate, data bit, stop bit and parity check.For two ports to communicate, these parameters must match.

ESP32 has three Serial ports, Serial, Serial1 and Serial2.Use Serial to communicate with the host on the bpibit board.

main function

  • ‘Serial. Begin (speed, config)’ : initializes the Serial port configuration

Parameter | function

–|-- speed | baud rate

‘config’ | data bit, check bit, stop bit configuration

Serial communication usually USES the following baud rate:

300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200

-’ config ': is configured using already defined configuration items

Config optionally configure | data bit | check bit | stop bit

--|--|--|--
 SERIAL_5N1 |5| without | 1
 SERIAL_6N1 |6| without | 1
 SERIAL_7N1 |7| without | 1
SERIAL_8N1(default configuration)| 8| without | 1
SERIAL_5N2 |5| without | 2
SERIAL_6N2 |6| without | 2
SERIAL_7N2 |7| without | 2
SERIAL_8N2 |8| without | 2
SERIAL_5E1 |5| even | 1
SERIAL_6E1 |6| even | 1
SERIAL_7E1 |7| even | 1
SERIAL_8E1 |8| even | 1
SERIAL_5E2 |5| even | 2
SERIAL_6E2 |6| even | 2
SERIAL_7E2 |7| even | 2
SERIAL_8E2 |8| even | 2
SERIAL_5O1 |5| odd | 1
SERIAL_6O1 |6| odd | 1
SERIAL_7O1 |7| odd | 1
SERIAL_8O1 |8| odd | 1
SERIAL_5O2 |5| odd | 2
SERIAL_6O2 |6| odd | 2
SERIAL_7O2 |7| odd | 2
SERIAL_8O2 |8| odd | 2
  • ‘Serial. Print (val)’ : print the information up to the computer Parameter | function –|-- ‘val’ | output data

use examples

# include < Arduino. H >
// implemented functions:
// displays the string sent to the PC on the serial helper.
// characters received from PC are sent back to PC
Void setup ()
{
Serial. The begin (9600, SERIAL_8E2);// configure serial port
Serial. Print ("Please enter a character: ");// sent via serial port
}
Void loop ()
{
If (Serial. The available ()!=0) // determine whether the serial port has received data
{
Char re = Serial. The read ();// serial port reads data
Serial. Println (re);// serial port sends data
}
}