Contents
1. The "Invisible Dialogue" in Daily Life
- 5.1 Serial Communication (UART): One-to-One Chat
- 5.2 I2C Communication: One Teacher Leading Multiple Students
1.1 Start with examples around us
Class, let's start with a riddle-guessing game. Now, please think about this:
- 🏃♂️ How does a smart band know how many steps you've taken and then transmit the step count to your phone?
- 🚗 Why can a remote-controlled car understand your commands to move forward, backward, and turn?
- 🌡️ How does a thermo-hygrometer display the measured temperature and humidity on its screen?
Isn't it amazing? It's like these devices are "whispering to each other" secretly, yet we can't hear a sound from them at all!
Actually, the answer is quite simple — all these devices rely on "communication peripherals" to "communicate" with each other! Communication peripherals are like the dedicated "mouth" and "ears" of a development board: the "mouth" is responsible for sending out the development board's commands and data, while the "ears" handle receiving messages from other devices. With them, electronic devices can coordinate with one another to complete tasks.
1.2 Why Learn Communication Peripherals?
Some of you may ask, "I've already mastered the programming blocks, so why do I still need to learn about communication peripherals? " We can figure this out from two perspectives:
1.2.1 Sub-goal: Create more interesting small inventions
A development board alone can only do so much. But once you master communication peripherals, you can get it to "link up" with more devices and create really cool projects, such as:
- a remote environmental monitoring station that can transmit temperature and humidity data to a computer;
- controllable via commands sent from a computer "wireless remote-controlled car";
- a message-receiving and text-displaying "developer board message screen";
- It's a "smart mini alarm clock" that sends a reminder to your phone the moment you tap the sensor.
1.2.2 Fun Incentive: Become the "Communication Steward" of the Development Board
Communication peripherals act as a "communication bridge". Once you master them, you can help the development board "understand" signals from sensors (for example, a temperature and humidity sensor saying "It's 25°C now"), and also enable the development board to "command" other devices to operate (such as telling an OLED screen to "display my name" or instructing a motor to "spin faster"). From then on, the development board is no longer a standalone circuit board, but a "small core" that can work in coordination with all kinds of devices!
2. Core Understanding: What Are Communication Peripherals?
2.1 One-sentence Definition
A communication peripheral acts as a "bridge" that transmits information between a development board and external devices such as sensors, displays, computers, or another development board.
Without it, the development board is like a child playing alone, unable to communicate with other "little friends"(devices); with it, the development board can break out of its "isolated island" state, collaborate with various devices through division of labor, and accomplish more complex tasks.
2.2 The Two "Chat Methods" You Will Learn in This Chapter
There is not just one single way for devices to "chat" with each other. Just like how we communicate with friends, we can either have a private one-on-one conversation, or listen to a teacher giving a lesson to the whole class in a classroom. In this chapter, we will focus on learning the two most common methods, which can be easily distinguished with the help of everyday analogies:
Communication Method | Metaphors from daily life | Core Features |
|---|---|---|
UART serial port | One-on-one "whisper telephone line" | Chatting is only allowed between two devices, requiring the corresponding connection of the "transmitter"(TX) and the "receiver"(RX) |
I2C bus | A "classroom" where one teacher instructs a large number of students | One development board (acting as the teacher) can communicate with multiple devices (acting as students), and all devices can be connected using only two wires. |
Interactive Mini Exercise
Let's first brainstorm a bit: if we want to connect three devices to the development board at the same time — a temperature and humidity sensor, a light sensor, and an OLED screen — which interface is more convenient to use, UART or I2C? And why?
Answer: Using I2C is more convenient. Because I2C supports one-to-many communication, whereas UART only supports one-to-one connection, which means 3 sets of "telephone lines" are required for 3 devices, leading to numerous, messy wiring that is also prone to errors.
3. Comparison between I2C and UART
Compared with the previously learned UART (one-to-one walkie-talkie communication), I2C has obvious advantages as well as limitations, which can be easily understood at a glance from the following table:
Features | I2C (Teacher-led Instruction with Students) | UART (pair-to-pair walkie-talkie) |
|---|---|---|
Connection Method | One-to-many (one master device controlling multiple slave devices) | One-to-one (only two devices can communicate with each other) |
Number of connections | 2 wires (SDA + SCL), shared bus | At least 2 wires (TX+ RX), dedicated line |
addressing mode | Call the corresponding peripheral by device address | Identify devices by dedicated lines |
Applicable Scenarios | Multiple peripherals such as sensors and displays coexist | Two devices communicate independently (e. g. development board → computer) |