01Serial CommunicationSerial Port:The serial port, also known asserial communicationinterface orserial communication interface(usually referring toCOM port), is anexpansion interface that uses serial communication.USB (Universal Serial Bus)is a serial portbus standardand also atechnical specification for input and output interfacesthat is widely used inpersonal computersandmobile devicesand has expanded tophotographic equipment,digital televisions(set-top boxes),game consolesand other related fields.Serial communication: Refers to a communication method between peripherals and computers, where data is transmitted bit by bit through data signal lines, ground lines, control lines, etc. This communication method uses fewer data lines, which can save communication costs in long-distance communication, but its transmission speed is lower than parallel transmission.On the Arduino UNO controller, digital pins 0 and 1 are also the serial port of Arduino, which can be used to communicate with other serial devices or with a computer. When the Arduino Uno is connected to a computer via a USB cable, it creates a virtual serial port device on the computer, establishing a serial connection between the two. Through this connection, the Arduino Uno can exchange data with the computer.02Serial Port Initialization and ConfigurationUsed for communication between the Arduino development board and a computer or other devices. All Arduino development boards have at least one serial port (also known as UART or USART), and some models have multiple..
<span><span>Serial.begin(</span></span><span><span><span>speed[baud rate],</span></span></span><span><span>config[data format]</span></span><span><span>)</span></span>
:【Initialize serial port】
Baud rate: Must match between both communicating parties,Baud rate values are 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200;
Data format: Set data bits, parity bits, and stop bits.
03Serial Data Output
Outputs data in a readable ASCII text format to the serial port. This command supports various data type formats
<span><span>Serial.print</span></span><span><span>(</span></span><span><span><span>val[value],format[data format]</span></span></span><span><span>)</span></span>
:【Print without newline】
<span><span>Serial.println</span></span><span><span>(</span></span><span><span><span>val[value],format[data format]</span></span></span><span><span>)</span></span>
:【Print with automatic newline】
Value: The value to print, of any data type;Data format: The format of the output data, including the number of decimal places for integer and floating-point data.
04Serial Data Writing
Write binary data to the serial port. Data is sent directly in single-byte or byte sequence form (if sending the character representation of a number, use the output function).
Serial.write(val[value]):【Send a single byte】
Serial.write(str[string]):【Send a byte sequence of a string】
Serial.write(buf[byte array], len[length]):【Send a specified length of byte array】
05Other Functions
Serial.available():【Read buffer data: Check the status of the serial buffer】
Serial.read():【Read serial data】
Serial.flush():【Clear the serial buffer】
Serial.end():【Disable serial data】
Serial.peek():【Read the next byte of data in the serial buffer】
Serial.readBytes(buffer[buffer variable],length[read length]):【Read a specified length of serial data into the buffer array】
Serial.readBytesUntil(character[delimiter character],buffer[buffer variable],length[read length]):【Read a specified length of characters from the serial buffer into the buffer array, stopping at the delimiter character】
Serial.readString():【Read all data from the serial buffer into a string variable.】
Serial.readStringUntil():【Read characters from the serial buffer into a string variable until finished or until a delimiter character is encountered.】
Serial.parseFloat():【Read the first valid floating-point data from the serial buffer, skipping numbers. The function ends when a non-floating-point number is encountered.】
Serial.parseInt():【Read the first valid integer (including negative numbers) from the serial data stream】
Serial.find():【Read data from the serial buffer, searching for the target string target (char type)】
…
05Serial Output Testing
Mixly software does not require initialization when using the serial port, with a baud rate of 9600. No manual settings are needed.
Share
Collect
View
Like