Learn the differences between three common communication peripherals found on Arduinos: UART, SPI, and I2C.
Using digital and analog pins on the Arduino can only get you so far. It won’t be long before using the onboard peripherals becomes mandatory.
Traditionally with desktop computers, peripherals are external devices (computer mouses, keyboards, disk drives, etc.) that connect to the main computer but are independent of it. When talking about peripherals in regards to an Arduino or other microcontrollers, the term refers to a part on the board that is dedicated to a specific task that is unrelated to the CPU. Peripherals can be thought of as units integrated onto the Arduino boards that make specialized tasks easier.
While the Arduino contains many peripherals, we will briefly look at the common communication peripherals: UART, I2C, and SPI. These three serial data transmission formats are available on Arduino, though different iterations of Arduino have a varied amount of I2C and SPI pins.
The UART, I2C, and SPI pins on an Arduino UNO.
UART stands for Universal Asynchronous Reception and Transmission and is a simple communication protocol that allows the Arduino to communicate with serial devices. The UART system communicates with digital pin 0 (RX), digital pin 1 (TX), and with another computer via the USB port.
This peripheral, found on all Arduino boards, allows the Arduino to directly communicate with a computer thanks to the fact that the Arduino has an onboard USB-to-Serial converter. Therefore, programs written on a Windows, Mac, or Linux OS can be used with an Arduino connected to a USB port as if it was a serial port (serial port communication is trivial compared to USB communication).
For more detailed information, check out this article on All About Circuits: Back to Basics: The Universal Asynchronous Receiver/Transmitter (UART).
I2C, which stands for inter-integrated-circuit, is a serial communications protocol specially designed for microcontrollers.
While this peripheral is almost never used for PC-device communication, it is incredibly popular with modules and sensors, making it useful for projects that require many parts working together. In fact, I2C allows you to potentially connect up to 128 devices to your main board!
When connecting two circuits to one another, think of the main device as the “master” and the connected devices—such as sensors, pin expansions, and drivers—as “slaves”. I2C makes it possible to connect multiple masters and slaves to your board while maintaining a clear communication pathway.
Maintaining a clear communication pathway is possible because I2C uses an address system and a shared bus, meaning many devices can be connected to the exact same wires. However, the Arduino must first select a specific device by transmitting a unique address before sending data. This provides each slave device with what it needs while also supporting multiple masters. I2C uses fewer wires and all data is transmitted on a single wire, keeping your pin count low. The tradeoff for this simplified wiring is slower speeds than SPI.
You can learn more about I2C in Introduction to the I2C Bus from All About Circuits.
SPI stands for Serial Peripheral Interface. Like I2C, SPI is a different form of serial-communications protocol specially designed for microcontrollers to talk to each other. However, it has some key differences from its I2C counterpart.
The most notable difference right off the bat is that, while you can use multiples masters and slaves with I2C, SPI allows a single master device with a maximum of four slave devices.
SPI is typically much faster than I2C due to the simple protocol and, while data/clock lines are shared between devices, each device requires a unique address wire. SPI is commonly found in places where speed is important such as with SD cards and display modules, or when information updates and changes quickly, like with temperature sensors.
Learn about this finer point of SPI in Back to Basics: SPI (Serial Peripheral Interface) from All About Circuits.
The Importance of Familiarizing Yourself With Your Board’s Peripherals
Arduinos can help you make just about any project you can dream up, and learning the nitty gritty of how all of the boards’ peripherals work can feel daunting. However, taking the time to understand the pros and cons of different data communication peripherals helps you make the best decision for your project right from the start, saving you time (and hopefully some sanity) down the road!