Use ← → to move, Home / End to jump, and F for fullscreen.
Figure descriptions
Slide 2 · Part 1 · Three ways to talk to a chip
Three panels compare serial protocols. UART: the Pi's TX goes to the device's RX and back on a second wire, with no clock, so both ends must agree on the baud rate. I2C: the Pi and two chips at addresses 0x18 and 0x19 share two pulled-up wires, SDA and SCL, and each byte has an ACK or NAK bit. SPI: the Pi and one chip are joined by four wires, SCLK, MOSI and chip select from the Pi and MISO back; drivers are push-pull, the chip is picked by its own select wire, and there is no acknowledgment.
Slide 3 · Part 2 · SPI: four wires, and the Pi runs the clock
The Raspberry Pi as SPI controller and the MCP3008 as peripheral. SCLK from BCM 11 to CLK carries one bit per tick; MOSI from BCM 10 to DIN carries the request; MISO from DOUT back to BCM 9 carries the answer; chip select from BCM 8 (CE0) to the chip's CS/SHDN pin, active low, tells the chip to listen.
Slide 4 · Where SPI lives on the Pi header
Raspberry Pi 40-pin header map distinguishing physical pin positions from BCM GPIO numbers and marking 3.3 V, 5 V, ground, I²C, UART, and SPI connections. Power pins are not GPIO inputs.
Slide 5 · Chip select: one wire per chip, not an address
One Pi with three SPI chips. SCLK, MOSI and MISO are shared by all three. Each chip has its own select line: CE0, CE1 and an ordinary GPIO. CE0 is low, so the MCP3008 is talking; the other two chips have their select high and have released MISO to high impedance.
Slide 6 · Inside: two shift registers joined in a ring
Two 8-bit shift registers joined in a ring. The Pi's register holds 1100 1010 and the MCP3008's holds 0110 1100. MOSI carries the Pi's most significant bit out into the chip's least significant end; MISO carries the chip's most significant bit out into the Pi's least significant end. Each clock tick moves every bit one place.
Slide 7 · Tick by tick: the two bytes trade places
The two shift registers after each of eight clock ticks, with the Pi's original bits shaded slate and the chip's shaded rose. At each tick one slate bit leaves the Pi and enters the chip while one rose bit enters the Pi. After tick 8 the Pi holds 0110 1100 and the chip holds 1100 1010: the bytes have traded places.
Slide 8 · One byte on the wire, both directions at once
Timing of one SPI byte in mode 0. Chip select goes low, SCLK makes eight pulses, and on the same eight ticks MOSI carries the Pi's byte 0xCA (1100 1010) while MISO carries the chip's byte 0x6C (0110 1100). Both sides read at each rising edge and change their data on the falling edge.
Slide 9 · To read, you must write
The call spi.xfer2([0x01, 0x80, 0x00]) sends three bytes and receives three: 0x01 (start bit) returns an unknown byte, 0x80 (channel 0, single-ended) returns 0x?2 holding the null bit and B9 B8, and the dummy byte 0x00 returns 0x6C holding B7 to B0. Each byte takes 8 ticks in both directions.
Slide 10 · Four clock modes: idle level and reading edge
The four SPI clock modes drawn against one row of data bits D7 to D0. Mode 0 (CPOL 0, CPHA 0) idles low and reads on the rising edge; mode 1 (CPOL 0, CPHA 1) idles low and reads on the falling edge; mode 2 (CPOL 1, CPHA 0) idles high and reads on the falling edge; mode 3 (CPOL 1, CPHA 1) idles high and reads on the rising edge. In every mode the reading edge falls in the middle of each data bit.
Slide 11 · The MCP3008 reads on the rising edge: mode 0
MCP3008 datasheet Figure 1-1, serial interface timing: chip select falls at least t_SUCS before the first rising clock edge; DIN must be valid t_SU before and t_HD after each rising edge; DOUT leaves high impedance with a null bit, then MSB out, each changing t_DO after a falling clock edge, and returns to high impedance t_DIS after chip select rises, which must stay high for t_CSH.
Slide 12 · SPI and I²C side by side
Illustration of a 1 MHz square wave on two kinds of line. Top, SPI push-pull: the driver pulls the line up and down, so both edges are sharp. Bottom, I2C open drain: the line falls fast but rises along an RC curve with time constant 1.5 kilohms times an illustrative 100 pF, 150 ns, barely reaching 3.3 V before the next fall.
Slide 13 · Part 3 · A GPIO pin sees 0 or 1; an ADC sees a number
The same slowly varying voltage between about 0.3 and 3.1 V read two ways over 10 seconds. A GPIO input reports only 0 or 1, switching at an illustrative threshold of 1.65 V. The MCP3008 reports a count from 0 to 1023 that follows the voltage in steps of 3.2 mV.
Slide 14 · Ten bits: 1024 steps of 3.22 mV
Ten-bit ADC transfer function with a 3.3 V reference. Full scale, output code against input voltage from 0 to 3.3 V looks like a straight line from 0 to 1023. Zoomed to 1.985 to 2.013 V, it is a staircase of steps 1 LSB = 3.22 mV wide; 2.000 V gives code 620.
Slide 15 · Inside the MCP3008
MCP3008 datasheet functional block diagram: inputs CH0 to CH7 pass through an input channel multiplexer to a sample and hold; a comparator compares the held voltage with a DAC driven from VREF under a 10-bit successive-approximation register; control logic driven by CS/SHDN, DIN and CLK moves the result into a shift register that drives DOUT.
Slide 16 · Successive approximation: a binary search
Successive approximation of 2.00 V with a 3.3 V reference. Over ten clocks the DAC tries codes 512, 768, 640, 576, 608, 624, 616, 620, 622 and 621; each trial at or below 2.00 V keeps its bit and each above drops it. The kept bits B9 to B0 read 1001101100, which is 620. A zoomed panel shows the last six trials within a few millivolts of 2.00 V.
Slide 17 · Sample and hold: charge 20 pF in 1.5 clocks
MCP3008 datasheet Figure 4-1, analog input model: a signal source with source impedance drives the channel pad, which has 7 pF pin capacitance, clamp diodes to VDD and VSS, and about 1 nA leakage; a sampling switch with 1 kilohm resistance connects it to the 20 pF sample capacitor.
Slide 18 · Wire it: MCP3008 to the Pi
Wiring the MCP3008 to the Pi header, pins 17 to 26. VDD (pin 16) and VREF (pin 15) go to the 3.3 V rail from header pin 17; AGND (14) and DGND (9) go to the ground rail from header pin 25. CLK (13) goes to SCLK pin 23, DOUT (12) to MISO pin 21, DIN (11) to MOSI pin 19, and chip select (10) to CE0 pin 24. A 10 kilohm potentiometer across the rails feeds its wiper to CH0 (pin 1).
Slide 19 · Part 4 · The datasheet's three-byte conversation
MCP3008 datasheet Figure 6-1, SPI communication in 8-bit segments, mode 0,0: over 24 clocks the MCU transmits 0000 0001 (start bit), then SGL/DIFF D2 D1 D0 and four don't-care bits, then eight don't-care bits. It receives eight unknown bits, then five unknown bits, the null bit 0, B9 and B8, then B7 to B0. Data leaves the converter on falling edges and the MCU latches it on rising edges.
Slide 20 · Build the request, decode the reply
The three bytes of one MCP3008 reading, bit by bit. The Pi sends 0000 0001 (the start bit), then 1 D2 D1 D0 followed by don't-care bits, which is 1000 0000 for channel 0, then a dummy byte. The chip returns unknown bits, then five unknown bits, a null 0 and B9 B8 = 10, then B7 to B0 = 0110 1100. Notes explain that (8 + ch) << 4 builds the channel byte, and that ((r[1] & 3) << 8) + r[2] gives 512 + 108 = 620, which is 1.998 V.
Slide 22 · How fast can you sample? Nyquist and aliasing
Sampling at 1000 samples per second: a 100 Hz sine wave is resolved, while samples of a 900 Hz sine wave appear to follow a 100 Hz wave. Sample points alone cannot distinguish these frequencies.
Slide 23 · Part 5 · SSH: the Pi's terminal on your laptop
SSH: a laptop terminal logged in to the Raspberry Pi over the same network on port 22, encrypted. Keystrokes go to the Pi and text output comes back; the terminal shows the ADC program printing counts 620 and 621 with voltages 1.998 and 2.001 V. The program runs on the Pi, whose pins stay on the bench.
Slide 24 · VNC: the Pi's whole desktop in a window
VNC: a laptop shows the whole Raspberry Pi desktop in a viewer window, including a live plot. Screen pixels travel from the Pi to the laptop and mouse and keyboard events go back, over the same network on port 5900.
Slide 25 · Part 6 · The final project
Final-project timeline over eight weeks. Week 1: proposal and initial BOM, order parts. Weeks 2 to 5: build, wire and code, and film every week. Week 6: test with customers and finish. Week 7: the Expo, with the team video, a technical presentation and a live demo. Week 8: the final report. A weekly report is due at the start of weeks 3 to 7, and a peer evaluation at the start of weeks 2 to 7.







![The call spi.xfer2([0x01, 0x80, 0x00]) sends three bytes and receives three: 0x01 (start bit) returns an unknown byte, 0x80 (channel 0, single-ended) returns 0x?2 holding the null bit and B9 B8, and the dummy byte 0x00 returns 0x6C holding B7 to B0. Each byte takes 8 ticks in both directions.](/_astro/spi-xfer-list.B8y2ts94_Z2qsyYK.webp)










![The three bytes of one MCP3008 reading, bit by bit. The Pi sends 0000 0001 (the start bit), then 1 D2 D1 D0 followed by don't-care bits, which is 1000 0000 for channel 0, then a dummy byte. The chip returns unknown bits, then five unknown bits, a null 0 and B9 B8 = 10, then B7 to B0 = 0110 1100. Notes explain that (8 + ch) << 4 builds the channel byte, and that ((r[1] & 3) << 8) + r[2] gives 512 + 108 = 620, which is 1.998 V.](/_astro/mcp3008-bytes.CxtlT_e-_1eMN59.webp)



