Book Image

Raspberry Pi cookbook for Python programmers

Book Image

Raspberry Pi cookbook for Python programmers

Overview of this book

Table of Contents (18 chapters)
Raspberry Pi Cookbook for Python Programmers
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using SPI to control an LED matrix


In Chapter 7, Sense and Display Real-world Data, we connected to devices using a bus protocol called I2C. The Raspberry Pi also supports another chip-to-chip protocol called SPI (Serial Peripheral Interface). The SPI bus differs from I2C because it uses two single direction data lines (where I2C uses one bidirectional data line). Although SPI requires more wires (I2C uses two bus signals, SDA and SCL), it supports the simultaneous sending and receiving of data and much higher clock speeds than I2C.

General connections of SPI devices with the Raspberry Pi

The SPI bus consists of the following four signals:

  • SCLK: This provides the clock edges to read/write data on the input/output lines; it is driven by the master device. As the clock signal changes from one state to another, the SPI device will check the state of the MOSI signal to read a single bit. Similarly, if the SPI device is sending data, it will use the clock signal edges to synchronize when it sets...