I2C vs SPI vs UART: How to Choose and Use Serial Communication Protocols
Introduction
Every microcontroller project eventually needs to talk to something else — sensors, displays, memory chips, wireless modules, or another microcontroller. I2C, SPI, and UART are the three universal serial communication protocols that make this possible. Each has distinct strengths: I2C uses just two wires and supports multiple devices, SPI is blazing fast with full-duplex transfers, and UART is simple, universal, and works over long distances. This guide explains how each protocol works electrically, when to choose one over the others, how to wire them correctly, and complete Arduino and ESP32 code examples for real sensors and displays.
Quick Comparison
FeatureI2CSPIUART Wires2 (SDA, SCL) + GND4 (MOSI, MISO, SCK, CS) + GND2 (TX, RX) + GND SpeedUp to 3.4 Mbps (Fast Mode+)Up to 50+ MbpsUp to 1 Mbps (typical: 9600-115200 bps) DevicesUp to 127 on one busOne per CS pin (limited by GPIO)Point-to-point (1-to-1) DirectionHalf-duplexFull-duplexFull-duplex ComplexityMediumLowLowest DistanceShort (Related Guides
- I2C Wiring and Protocol Guide for Arduino, ESP32, and Raspberry Pi
- Shift Registers and I/O Expanders for Arduino and ESP32: 74HC595, MCP23017, and PCF8574 Explained
- How to Use a Logic Analyzer for Digital Signal Debugging: Saleae, Sigrok, and Protocol Decoding
- How to Use Sensors with Arduino and ESP32: Temperature, Distance, Load, Current, and Hall Effect
- How to Use the Flipper Zero GPIO for Hardware Hacking: UART, SPI, I2C, and Debugging
- Reading Sensors over I2C with Raspberry Pi
- Using Flipper Zero as a USB-to-UART Serial Bridge
- Flipper Zero GPIO Pinout and Hardware Expansion: UART, I2C, ADC, 1-Wire, and Sensor Wiring
Loading_