Robots use communication buses to let microcontrollers, sensors, motor drivers, and displays exchange data. This cheat sheet compares I2C, SPI, and UART so students can choose the right connection and wire it correctly. It focuses on the signals, timing ideas, addresses, baud rates, and common setup rules needed in robotics projects.
Key Facts
- I2C uses two shared signal lines, SDA for data and SCL for clock, plus ground, and devices are selected by unique addresses.
- A common I2C address is 7 bits, so the normal address range is 0 to 127, often written in hexadecimal such as 0x3C.
- SPI usually uses SCLK, MOSI, MISO, and one CS or SS line per device, so adding devices often requires more chip select pins.
- SPI data rate is controlled by the clock frequency, and the approximate transfer time is time = bits transferred / clock frequency.
- UART uses TX, RX, and ground, and the TX pin of one device must connect to the RX pin of the other device.
- UART bit time is bit time = 1 / baud rate, so 9600 baud gives a bit time of about 104 microseconds.
- UART settings must match on both devices, commonly written as baud rate, data bits, parity, and stop bits, such as 9600 8N1.
- All wired communication between robot electronics needs a shared ground reference unless the interface is specifically isolated.
Vocabulary
- I2C
- I2C is a two-wire synchronous communication bus where one controller uses addresses to talk to multiple devices.
- SPI
- SPI is a synchronous communication bus that uses a clock, data lines, and chip select signals for fast device communication.
- UART
- UART is an asynchronous serial communication method that sends bits over TX and RX lines without a shared clock line.
- Baud rate
- Baud rate is the number of signal changes or bits sent per second in a serial communication link.
- Chip select
- Chip select is an SPI control signal that tells one specific device to listen while other devices ignore the transfer.
- Pull-up resistor
- A pull-up resistor connects a signal line to a positive voltage so the line returns to a known high state when not driven low.
Common Mistakes to Avoid
- Swapping UART TX to TX and RX to RX is wrong because UART devices must cross connections, with TX connected to RX and RX connected to TX.
- Forgetting a shared ground is wrong because the devices may not agree on what counts as high or low voltage.
- Using two I2C devices with the same address is wrong because the controller cannot tell which device should respond.
- Ignoring SPI clock mode is wrong because CPOL and CPHA settings control when data is sampled, and mismatched settings can shift or corrupt bits.
- Connecting 5 V signals directly to a 3.3 V device is wrong because the higher voltage can damage the lower-voltage input pins.
Practice Questions
- 1 A UART link runs at 9600 baud. What is the approximate time for one bit in microseconds?
- 2 An SPI sensor sends 16 bits of data at a clock frequency of 2 MHz. What is the minimum transfer time for the 16 bits?
- 3 A robot has one microcontroller and four I2C sensors. How many signal lines are needed for the I2C bus, not counting power and ground?
- 4 A robot needs to connect a fast display, several addressable sensors, and a simple GPS module. Which protocol would you likely use for each device, and why?
Understanding I2C, SPI & UART Communication
Communication works only when every device agrees about voltage levels, timing, and who is allowed to speak. A data wire does not carry useful information by itself. The receiver must know when to sample each bit and how to tell one message from the next.
This is why wiring diagrams and library settings matter as much as program code. Before connecting a module, check whether it uses three point three volt or five volt logic.
A five volt output connected directly to a three point three volt input can damage some boards. Check the module datasheet for its supply voltage, logic level limits, default address, supported speed, and required pullup resistors.
I2C is convenient when several low speed modules share the same connection. The lines are normally held high by pullup resistors. Devices pull a line low when they need to send a zero.
This shared electrical method means the bus needs suitable resistor values and short, tidy wires. Too much wire length adds capacitance, which rounds off signal edges and can cause missed bits. Address conflicts are a common classroom problem.
Two identical sensors may start with the same address, so one controller cannot tell them apart. Some boards provide address jumpers.
Others need an enable pin or an I2C multiplexer. A scan program can help find devices, but it cannot prove that a device is working correctly.
SPI is often chosen when a sensor produces data quickly or when a screen needs frequent updates. Its separate input and output paths allow data to move in both directions during the same clock sequence. The clock has several modes based on its resting level and the edge used for reading data.
A device may appear completely dead if its mode is wrong, even when every wire is connected properly. Chip select lines keep inactive devices from responding, so they must be set to the correct level before a transfer begins. SPI has no universal addressing system.
The controller selects a device through its chip select wire. This makes the protocol predictable, though it uses more pins as the robot gains modules.
UART is useful for links that are simple and direct, such as a microcontroller talking to a GPS receiver, Bluetooth module, computer, or motor controller. Each character is sent as a small frame. A start bit marks the beginning, data bits follow, then optional parity and stop bits finish the frame.
Since there is no clock wire, both ends must keep close enough timing on their own. Wrong baud settings usually produce random symbols or no readable output. Serial monitors can help diagnose this, but they must use the same settings as the device.
In a real robot, choose the protocol from the job. Use I2C for many modest sensors, SPI for fast peripherals, and UART for point to point serial devices. Keep wires short, connect ground first, and test one device at a time before combining the full system.