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?