Raspberry Pi SPI and I2C Tutorial
Contributors:
Byron J., Shawn Hymel
Introduction
There are many peripherals that can be added to a microprocessor over the I2C and SPI serial interfaces. These include atmospheric sensors, EEPROMS, and several types of display.
The Pi Wedge helps access the I2C and SPI signals.
This tutorial will walk you through getting the I2C and SPI interfaces of your Raspberry Pi working. These interfaces aren't enabled by default, and need some extra configuration before you can use them.
Recommended Reading
Before we get started, you might want to review some related background material.
- I2C is a useful bus that allows data exchange between microcontrollers and peripherals with a minimum of wiring.
- SPI is a cousin of I2C with similar applications.
- For the C/C++ examples, we'll be using the wiringPi library to interface with these buses
- For the Python examples, we'll be using spidev for SPI and smbus for I2C.
Updated Aug 17, 2018: Added Python examples, added suggestions for alternative ways of installing Raspbian, updated screenshots to show newer raspi-config, and added suggested projects in the "Resources and Going Further" section.
Looking to get hands-on with Raspberry Pi?
We've got you covered!