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.
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...