Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

Robots depend on communication buses to move data between a microcontroller and parts such as sensors, motor drivers, displays, GPS receivers, and wireless modules. I2C, SPI, and UART are three common ways to connect these devices using only a few wires. Choosing the right bus affects wiring complexity, speed, reliability, and how many modules can share the same controller pins.

Understanding these interfaces helps you design robots that are easier to debug and expand.

Understanding Robotics: I2C, SPI, and UART

I2C works because the connected chips do not force a signal high. Instead, they can pull a line low, while pullup resistors bring it back high when nobody is pulling. This design lets several chips use the same pair of wires safely.

It has limits. Long wires and too many modules add electrical capacitance. The signal then rises slowly, which can cause missed bits at higher speeds.

Address conflicts are another common problem. Two breakout boards may use the same fixed address, so a controller cannot tell them apart.

Some boards provide address pins, while others need an I2C multiplexer. I2C is often a good fit for small sensors, real time clocks, and simple displays where wiring needs to stay compact.

SPI sends bits in a steady rhythm set by the controller. Each clock pulse moves one bit through shift registers inside the connected chips. This makes SPI simple to run quickly, especially for screens, memory cards, radio chips, and fast measurement devices.

The chip select signal matters because it marks which device is allowed to respond. If two devices are selected at once, their output signals can fight each other. SPI has several clock modes.

A mode defines the clock resting level and the clock edge used to read data. A device can appear completely dead when the wires are correct but the selected mode is wrong. Students should check the data sheet for clock mode, maximum clock rate, and the required timing around chip select.

UART sends data as separate frames rather than following a shared clock. A receiving chip uses the start bit to begin timing each frame, then samples the incoming bits at expected moments. A stop bit marks the end.

This is why a small mismatch in data rate can sometimes seem to work briefly, yet produce random characters or corrupted commands later. UART is common on GPS modules, Bluetooth modules, serial motor controllers, and computer debugging ports. The transmit pin of one device must connect to the receive pin of the other.

Both devices normally need a common ground as well. UART does not automatically identify message boundaries beyond its individual frames. Robot code often needs a clear packet format, such as a known starting byte, a length value, and an error check.

Good communication depends on more than choosing a protocol. Every module must use compatible logic voltages. A three point three volt sensor can be damaged by direct five volt signals, so level shifting may be needed.

Loose ground connections, weak power supplies, and motor electrical noise can create faults that look like software bugs. Keep signal wires short when possible and route them away from motor power wires. Start testing with one module and a simple program that reads a known register or sends a short command.

A logic analyzer can show the actual bits on the wires, making timing mistakes visible. Reading the device data sheet is essential. It tells you which pins are required, how the device starts up, and what each byte in a message means.

Key Facts

  • I2C uses two shared signal lines: SDA for data and SCL for clock.
  • SPI commonly uses four signal types: SCLK, MOSI, MISO, and CS or SS.
  • UART uses two main signal lines: TX and RX, with no separate clock line.
  • I2C devices share a bus and are selected by address, such as 0x3C or 0x68.
  • SPI devices share clock and data lines but usually need one chip select line per device.
  • UART timing must match on both devices, such as 9600 baud, 115200 baud, or another agreed data rate.

Vocabulary

Bus
A bus is a shared communication path that carries signals between electronic devices.
I2C
I2C is a two-wire synchronous bus that lets one controller communicate with multiple addressed devices.
SPI
SPI is a fast synchronous bus that sends data using separate clock, input, output, and device select signals.
UART
UART is an asynchronous serial interface that sends data over transmit and receive lines without a shared clock.
Baud rate
Baud rate is the number of signal changes per second used to time serial communication.

Common Mistakes to Avoid

  • Connecting TX to TX and RX to RX is wrong for UART because transmit on one device must go to receive on the other device.
  • Forgetting I2C pull-up resistors is wrong because SDA and SCL usually need pull-ups to return to a logic high state.
  • Using the same I2C address for two devices on one bus is wrong because the controller cannot tell which device should respond.
  • Leaving all SPI chip select lines active is wrong because more than one device may drive MISO at the same time and corrupt the data.

Practice Questions

  1. 1 An I2C bus has a 400 kHz clock. If one useful data byte requires 9 clock pulses including the acknowledge bit, about how many bytes per second can be transferred before other overhead is included?
  2. 2 A robot has one SPI display and three SPI sensor modules. If SCLK, MOSI, and MISO are shared, how many chip select lines are needed so each device can be selected separately?
  3. 3 A robot uses a microcontroller, an IMU, a small OLED display, a GPS module, and a fast motor driver. Choose I2C, SPI, or UART for each module and explain your choices based on wiring, speed, addressing, and data timing.