23. UART, I2C & SPI Reference
Choose and troubleshoot common embedded communication buses.
Learning outcomes
- Compare UART, I2C and SPI
- Identify Uno bus pins
- Explain addressing and chip select
- Choose a bus for a practical requirement
Parts and preparation
Arduino Uno and any I2C/SPI modules available in the kit.
Before power: inspect wiring, confirm supply voltage and ensure all connected circuits share GND.
Libraries for this lesson
In Arduino IDE 2 open Tools → Manage Libraries…. Search by the Library Manager name and install the package by the exact author below. Similar names from other authors can use different APIs and will break the example.
| Include | Library Manager name | Author | Install note |
|---|---|---|---|
Wire.h | Wire | Arduino | Built into the Arduino core. No Library Manager install required. |
UART
Point-to-point asynchronous communication uses TX and RX plus common GND. It is simple and full-duplex but normally connects one partner per hardware UART.
I2C
A controller shares SDA/SCL with addressed devices. It uses two signal wires and pull-ups, making it convenient for several low-speed modules.
SPI
SCK clocks data, MOSI carries controller-to-device data, MISO returns data, and each device usually needs a CS pin. SPI is fast but uses more wires.
Uno pins
UART: D0/D1. I2C: A4/A5. SPI: D10 SS, D11 MOSI, D12 MISO, D13 SCK (also available on the ICSP header).
Wiring and safe build sequence
- Always connect common GND
- Check module logic voltage before connection
- Keep bus wires short in breadboard prototypes
- Do not assume every module is 5 V tolerant
Worked sketch
Download .ino sketch#include <Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin();
Serial.println("I2C addresses:");
for (byte address = 1; address < 127; address++) {
Wire.beginTransmission(address);
if (Wire.endTransmission() == 0) {
Serial.print("0x");
if (address < 16) Serial.print('0');
Serial.println(address, HEX);
}
}
}
void loop() {}How the code works
- The scanner attempts every valid 7-bit address.
- A zero return indicates an acknowledged address.
Test and record evidence
Practical evidence checklist
Common faults and checks
- No addresses: check power, GND, SDA/SCL order and pull-ups.
- Several unexpected addresses may indicate noise or voltage problems.
Check your understanding
Q1. Which bus uses a chip-select line per device?
Show answer
SPI.
Q2. Which bus uses device addresses on two shared wires?
Show answer
I2C.