Baud Rates, Data Bits, and Parity: Demystifying Serial Port Settings
You've connected your device, selected the port, and you see... gibberish. `⸮GJ⸮@*`. This is the most common problem new users face, and it's almost always caused by a mismatch in the serial port settings.
~8 minutes
You've connected your device, selected the port, and you see... gibberish. ⸮GJ⸮@*. This is the most common problem new users face, and it's almost always caused by a mismatch in the serial port settings.
For two devices to talk serially, they must agree beforehand on the exact rules of the conversation. These rules, often called line settings, define the speed, structure, and verification of the data being sent. Let's break down the most important settings you'll find in any serial terminal.
Baud Rate: The Speed of Conversation
The Baud Rate is the speed at which data is sent, measured in bits per second (bps). Think of it as how fast two people have agreed to talk. If one person talks at 200 words per minute and the other can only listen at 100, the message will be lost.
- Common Values: 9600 (very common for Arduinos), 57600, 115200 (common for ESP32 and Raspberry Pi), 921600.
- The Rule: The baud rate set in your serial terminal must exactly match the baud rate the device is configured to use. If they don't match, you'll see garbled, unreadable characters.
Data Bits: The Size of the Word
When a character (like the letter 'A') is sent, it's first converted into a binary number (01000001). The Data Bits setting defines how many bits are used to represent one character of data.
- Common Values: 8 and 7.
- The Rule: The vast majority of modern systems use 8 data bits. This allows for 256 possible characters, covering the full ASCII table and more. 7-bit data is a legacy standard and is rarely used today unless you're communicating with older equipment.
Stop Bits: The Pause Between Words
After the data bits for one character are sent, a Stop Bit is sent. This is a signal to the receiver that the character is complete and it should prepare for the next one. It's like the slight pause you take between words when you speak.
- Common Values: 1 or 2.
- The Rule: Almost every modern serial device uses 1 stop bit. Two stop bits were used on very old, slow, mechanical teletype machines to give them a moment to physically prepare for the next character. Unless you're working with antique hardware, this setting will always be 1.
Parity: A Simple Error Check
Parity is a very basic method of error checking. It adds one extra bit, the "parity bit," to each character. The sender and receiver agree on a parity rule:
- None: No parity bit is sent. This is the most common setting by far.
- Even: The sender counts the number of '1's in the data bits. If the count is odd, it makes the parity bit a '1' to make the total an even number. If the count is already even, the parity bit is '0'.
- Odd: The opposite of Even. The sender makes the parity bit a '1' or '0' to ensure the total number of '1's is always an odd number.
If the receiver gets a character where the parity doesn't match the rule (e.g., it was expecting Even parity but received an odd number of '1's), it knows the data was corrupted during transmission.
- The Rule: For most hobbyist and modern embedded use cases, parity is set to None. It's more common in industrial or noisy environments where data corruption is a higher risk.
Putting It All Together: "8N1"
You will often see these settings abbreviated. The most common configuration in the world is "8N1":
- 8 data bits
- No parity
- 1 stop bit
When in doubt, start with 8N1 and the baud rate recommended by your device's documentation. Understanding these settings turns frustrating gibberish into a clear, successful connection. To see how these bits actually look on the wire, check out our next article: Under the Hood: How Serial Communication Works (Bits, Bytes, and Voltages).