ABC of Electronics cosycom.com
RASPBERRY PI 14 · Communication

SPI on the Raspberry Pi: Talking to a Device

Enable SPI and understand its wiring on the Pi — the same protocol from Lesson 34, now with the specific pins Raspberry Pi dedicates to it.

You'll need: an SPI device (the MCP3008 from Lesson rpi-12 works as a ready example), jumper wires, and your Pi.

Like I2C, SPI needs enabling once via sudo raspi-config → Interface Options → SPI → Enable, followed by a reboot. The Pi dedicates specific physical pins to its primary SPI bus:

Primary SPI pins on the 40-pin header
SignalPhysical pinRole (from Lesson 34)
MOSI19Master out, slave in — data from the Pi to the device
MISO21Master in, slave out — data from the device back to the Pi
SCLK23Serial clock, set by the Pi
CE0 / CE124 / 26Chip-enable (chip-select) — CE0 for one device, CE1 for a second on the same bus

Notice the Pi provides two chip-enable pins (CE0 and CE1) built directly into its SPI hardware — enough to address two SPI devices on the same bus without wiring an extra chip-select line yourself, exactly the per-device wire Lesson 34 described, just already broken out for you on the header.

In Python, the spidev library's spi.open(bus, device) call (seen in Lesson rpi-12's code) is where you choose CE0 or CE1 — spi.open(0, 0) uses CE0, spi.open(0, 1) uses CE1, letting one script talk to two different SPI devices by opening two separate connections.

Pi SPI Device (CE0) Device (CE1)abcofelectronics
Two built-in chip-enable lines let the Pi's SPI bus address two separate devices without extra wiring.
TRY THIS
The Pi's SPI header already breaks out two chip-enable lines (CE0, CE1) — use spi.open(0,0) and spi.open(0,1) in Python to talk to two SPI devices on the same bus.