Communicating Using I2C and SPI
13.0 Introduction
The I2C (Inter-Integrated Circuit) and SPI (Serial Peripheral Interface) standards were created to provide simple ways for digital information to be transferred between sensors and microcontrollers such as Arduino. Arduino libraries for both I2C and SPI make it easy for you to use both of these protocols.
The choice between I2C and SPI is usually determined by the devices (for example, sensors, actuators, other boards) you want to connect. Some devices provide both standards, but usually a device or chip supports one or the other.
I2C has the advantage that it only needs two signal connections (clock and data) to Arduino, while SPI needs four. With I2C, you also get acknowledgment that signals have been correctly received. The disadvantages are that the data rate is slower than SPI and data can only be traveling in one direction at a time, lowering the data rate even more if two-way communication is needed. It is also necessary to connect pull-up resistors to the connections to ensure reliable transmission of signals (see the introduction to Chapter 5 for more on pull-ups). The exact value of an I2C pull-up resistor varies depending on a number of factors, such as the length and type of wire you are using. Generally, you will probably find that 4.7K works best.
If you are connecting to an I2C device that’s on a breakout board or shield, it’s possible that the manufacturer has included pull-ups. You won’t know for sure, so you ...
Get Arduino Cookbook, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.