Using SPI to control an LED matrix
In Chapter 10, Sensing and Displaying Real-World Data, we connected to devices using a bus protocol called I2C. Raspberry Pi also supports another chip-to-chip protocol called Serial Peripheral Interface (SPI). 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 Raspberry Pi
The SPI bus consists of the following four signals:
- SCLK: This allows 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 the...