UART, I2C and SPI. They are one of the most common and baisc hardware communication peripherals that makers and electricians use in microcontroller development. Similarly, for the Arduino, they contain UART, I2C and SPI peripheral too.
For Arduino users, it would not be long before you have to switch from its digital and analog pins to using its onboard communication peripherals as digital and analog pins can only do so much for you.
Through this blog, we are going to talk about:
- UART, SPI, I2C pins on Arduino boards examples
- Introduction to UART on Arduino
- Advantages and Disadvantages of using UART
- Related UART Arduino accessories
- Introduction to I2C on Arduino
- Advantages and Disadvantages of using I2C
- Related I2C Arduino accessories
- Introduction to SPI on Arduino
- Advantages and Disadvantages of using SPI
- Related SPI Arduino
UART, SPI, I2C Pins on Arduino Boards Examples
Before we start, you may be wondering, where are the UART, SPI and I2C Pins on the different Arduino boards since they are onboard peripherals. Here are some examples:
- The Arduino Uno Rev 3 is a microcontroller board based on the ATmega328, an 8-bit microcontroller with 32KB of Flash memory and 2KB of RAM.
- It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button
- Seeeduino V4.2 is an Arduino-compatible board, which is based on ATmga328P MCU. There’re so many Arduinos and Arduino-compatible boards in the world, and we think that compared to other Arduinos, it is much more stable, easy-to-use and even good looking.
- Seeeduino V4.2 is based the Arduino UNO bootloader, and with an ATMEGA16U2 as a UART-to-USB converter, which means that the board can basically work like a FTDI chip.
- The Seeeduino Nano is a compact board similar to the Seeeduino V4.2/Arduino UNO, and it is fully compatible with Arduino Nano on pinout and sizes.
- The same as Seeedunio V4.2, Seeeduino Nano is built around Atmega328P — 8-bit AVR microcontroller. However, the dimensions of the two are significantly different. Less than a quarter of the size, but with almost the same features, Seeeduino Nano will save more space for your project, more suitable for space-constrained scenes.
- Compared to the Arduino Nano, it has a Type C USB instead of Mini USB and also an additional Grove I2C connector.
- About Grove:
- Grove is Seeed very own modular, standardized connector prototyping system.
- Grove takes a building block approach to assembling electronics, compared to the jumper or solder based system. It is easier to connect, experiment and build and simplifies the learning system for makers.
Without further ado, let us jump right in to the first communication peripheral for Arduino: UART
Introduction to UART on Arduino
- UART, which stands for Universal Asynchronous Reception and Transmission, is a simple serial communication protocol that allows the host (Arduino) to communicate with serial devices.
- UART supports bidirectional, asynchronous and serial data transmission.
- It uses 2 data lines to communicate between each other which are: TX (Pin 1) and RX (Pin 0).
- TX – Used for transmitting
- RX – Used for receiving
- They are connected between two devices (eg. USB on Arduino and computer)
- UART are found on all types of Arduino boards which allows the Arduino to communicate with a computer due to its onboard USB to Serial converter
- If your program is written on a Windows, Mac or Linux OS and want to use it with your Arduino, just connect them together via their USB port as if it was a serial port.
For more information on the UART working protocol and operation, check out our other blog here!
Advantages and Disadvantages of using UART with Arduino
Advantages of using UART with Arduino
- Simple to operate and use with the Arduino. It is well documented online as it is a widely used method by Arduino users with many resources and tutorials online.
- No clock neede
Disadvantages of using UART with Arduino
- Lower speed compared to I2C and SPI
- Baud rates of each UART must be within 10% of each other to prevent data loss.
- Cannot use multiple master systems like the Arduino and slaves.
Related UART Arduino accessories
- The USB CP2102 Serial Converter is a small adapter required for the RF Explorer 3G+ IoT for Arduino/Seeeduino board to accept firmware upgrades from a computer.
- It can also be used as an extra Arduino Serial port if a Seeeduino or other small-form factor board is used with the RF Explorer 3G+ IoT board.
- Grove – UART WiFi V2.0(ESP8285) is a serial transceiver module featuring the ubiquitous ESP8285 IoT SoC. With integrated TCP/IP protocol stack, this module lets your microcontroller interact with Wi-Fi networks with only a few lines of code.
- ESP8285 can perform either as a standalone application or as the slave to a host MCU. When ESP8285 hosts the application, it promptly boots up from the flash. The integrated high-speed cache helps to increase the system performance and optimize the system memory.
- Isn’t it frustrating when your project involves many sensors, LEDs and jumper wires which causes a mess?
- With this Base Shield V2, it gets rid of your bread board and jump wires and allow you to add all your Grove Modules to the Arduino UNO very conveniently with 16 Grove connectors on the base shield including analog, digital, UART and I2C.
Introduction to I2C on Arduino
- I²C, which stands for inter-integrated-circuit, is a serial communication interface designed for microcontrollers.
- Compared to UART, it is similar but I2C are not used for PC – Device communication but are used with your modules and sensors.
- It is a simple, bidirectional two-wire synchronous serial bus and only 2 wires (SDA and SCL) to transmit information between devices connected to the bus.
- With I2C, they are useful for Arduino projects as they would sometimes require many different parts (eg. sensors, expansions, drivers) working together and with I2C, you can connect up to 128 devices on the main board while maintaining a clear communication pathway between the master (Arduino) and slave (Modules and sensors) devices!
For more information on the I2C working protocol and operation, check out our other blog here!
Advantages and Disadvantages of using I2C with Arduino
Advantages of using I²C with Arduino
- Low pin/signal count even with many devices on the bus
- Flexible = supports multi master and multi slave communication (eg. can connect the Raspberry Pi together with Arduino)
- Simple = uses only 2 wires
- Adaptable = Adapt to the needs of various slave devices.
Disadvantages of using I²C with Arduino
- Slower speed compared to SPI (next communication peripheral) as it uses pull-up resistors.
- Open-drain design = limited speed.
- Requires more space due to the use of resistors
- Can get complex as number of devices increase
Related I2C Arduino accessories
- The Brushless Motor Shield is a Brushless Motor Driver for Arduino.
- With the onboard potentiometer, you can adjust the motor speed easily. This shield offers a variety of modes to choose from, you can use the four onboard switches to switch functions.
- With the onboard Grove I2C interface, you can work with other grove modules with this shield easily, for instance, you can use a Grove – LCD RGB Backlight to display the Motor speed.
- I²C Driver is an easy-to-use, open source tool for controlling I²C devices.
- It works with Windows, Mac, and Linux, and has a built-in color screen that shows a live “dashboard” of all the I²C activity.
- Afraid that your I²C connection may go wrong? Do you want to avoid the painful debugging? Well, this I²CDriver right here makes I²C much more user-friendly and it can prevent just that.
Introduction to SPI on Arduino
- SPI, which stands for serial peripheral interface, is similar to I2C where it is a different form of serial-communications protocol specially designed for microcontrollers to connect.
- SPI operates at full duplex where data can be sent and received simultaneously.
- Compared to UART and I2C, it is the fastest communication peripheral with a 8Mbits or more data transmission rates.
- It is typically faster due to its simple protocol. Data/clock lines are shared between devices and each device will require a unique address wire
- SPI are used in places where speed is important like SD cards, display modules or when info updates and changes quickly like thermometers.
- However, SPI can only be used with a single master device which is an Arduino with a maximum of 4 slave devices.
For more information on the SPI working protocol and operation, check out our other blog here!
Advantages and Disadvantages of using SPI with Arduino
Advantages of using SPI with Arduino
- Protocol is simple as there is no complicated slave addressing system like I2C
- The fastest protocol compared to UART and I2C
- No start and stop bits unlike UART which means data can be transmitted continuously without interruption.
Disadvantages of using SPI with Arduino
- More Pin ports are occupied, practical limit to number of devices. (1 master and 4 slave devices)
- There is no flow control specified, and no acknowledgment mechanism confirms whether data is received unlike I2C
- Uses four lines – MOSI, MISO, NCLK, NSS
- No form of error check unlike in UART (using parity bit)
- No multiple masters.
Related SPI Arduino accessories
- The Serial CAN Bus module provides your Arduino with CAN bus capabilities and allows you to hack your vehicle.
- It lets you to read and write messages to the CAN bus. The Serial CAN Bus module can be connected to your Arduino through the on-board Grove connector through SPI.
- E-Ink screen is also known as E-paper screen. E-Ink eliminates the need for backlighting and therefore power consumption is ultra low. And the E-Ink has an extremely wide viewing angle with very high contrast so that it even can be clearly displayed in direct sunlight.
- The 2.7” Triple-Color E-Ink Display is an Arduino E-Ink display shield, which contains 264×176 pixels, and can display white/black/red for each pixel.
- This shield communicates with Arduino via the SPI interface and it reserves a Grove I2C interface for use with other modules.
- This SD card V4.0 shield provides a storage space for your Arduino.
- Users can read/write SD card via Arduino’s built-in SD library. It supports SD, SDHC and Micro SD cards and will only occupy the SPI port of your Arduino.
- You can stack this on other shields that work with the unused pins. Additionally, there are preformed I2C and UART port facilitate your connection with Grove modules.
Even though the 3 different communication peripheral UART, SPI and I2C seems complicated for you to use with the Arduino be it you are a beginner or and experienced engineer, knowing which communication peripheral to use for your projects will definitely save you time and from frustrating moments when your devices doesn’t work the way you want to.
I have compiled all the various advantages / disadvantages and functions of the various communication peripherals and compared them using a table so you can easily pick which communication peripheral suits your project the most to save you some time:
|Complexity||Simple|| Easy to|
|Complex as device|
|Speed||Slowest ||Faster than|
|Number of devices||Up to 2|
|Up to 128|
get complex as devices
|1 Master and up to 5 Slave devices,|
|Number of wires||1||2||4|
|Duplex||Full Duplex||Half Duplex||Full Duplex|
|Number of masters and slaves||No multiple slaves and masters||Multiple|
slaves and masters
|Only 1 master but can have multiple slaves.|