The 74HC595 turns three Pico pins into eight outputs — and more if you chain chips. On the Raspberry Pi Pico it fits perfectly on SPI0: SCK on GP18 clocks the bits in, TX on GP19 carries the data, and GP17 latches them to the outputs.
Run it at 3V3 with an LED and 220 Ω resistor on each output. The script counts in binary from 0 to 255, then runs a Knight Rider sweep.
Wiring
| Raspberry Pi Pico | 74HC595 8-bit shift register (DIP-16) | Wire | Notes |
|---|---|---|---|
| — | Q0 | — | To LED 1 + 220 Ω to GND (not drawn) |
| — | Q1 | — | To LED 2 + 220 Ω to GND (not drawn) |
| — | Q2 | — | To LED 3 + 220 Ω to GND (not drawn) |
| — | Q3 | — | To LED 4 + 220 Ω to GND (not drawn) |
| — | Q4 | — | To LED 5 + 220 Ω to GND (not drawn) |
| — | Q5 | — | To LED 6 + 220 Ω to GND (not drawn) |
| — | Q6 | — | To LED 7 + 220 Ω to GND (not drawn) |
| — | Q7 | — | To LED 8 + 220 Ω to GND (not drawn) |
| 3V3 | VCC | red | Chip pin 16. Run the 595 at 3.3 V, the same as the Pico, so every logic level matches. |
| GND | GND | black | Chip pin 8. |
| GP19 | DS | green | SPI0 TX, physical pin 25 → serial data (chip pin 14). |
| GP18 | SH_CP | yellow | SPI0 SCK, physical pin 24 → shift clock (chip pin 11). |
| GP17 | ST_CP | orange | Physical pin 22 → latch (chip pin 12). |
| GND | OE | black | Chip pin 13: outputs always enabled. |
| 3V3 | MR | red | Chip pin 10: never reset. |
2–6 V part, 3.3 V board. Power it from the same voltage as your board: 3.3 V on ESP32 and Pico, 5 V on Uno. At 5 V the 74HC595 needs about 3.15 V for a HIGH, so a 3.3 V board driving a 5 V-powered chip is marginal — use a 74HCT595 at 5 V for that.
Board quirks
- A shift register is exactly what SPI was made for, so the Pico’s hardware SPI0 clocks the byte out in microseconds:
spi.write(bytes([b])), then pulse the latch. - At 3.3 V a 74HC595 output can supply a few mA per LED — fine with 220 Ω. For brighter LEDs or relays, follow it with a ULN2003.
- Chain more 595s by wiring Q7S of the first to DS of the next and sharing SH_CP/ST_CP; then write 2, 3, … bytes before the latch pulse.
- Don’t power the 595 from 5 V while driving it from the Pico: a 74HC595 at 5 V needs about 3.15 V for HIGH, which 3.3 V only just meets.
Code
# 74HC595 shift register driving 8 LEDs from a Raspberry Pi Pico (MicroPython, hardware SPI).
# Wiring: VCC -> 3V3 (pin 36), GND -> GND, DS -> GP19 (pin 25, SPI0 TX),
# SH_CP -> GP18 (pin 24, SPI0 SCK), ST_CP (latch) -> GP17 (pin 22), OE -> GND, MR -> 3V3.
# Q0-Q7 -> LED anode -> 220 Ohm -> GND (one resistor per LED).
from machine import Pin, SPI
import time
spi = SPI(0, baudrate=1_000_000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(19), miso=Pin(16))
latch = Pin(17, Pin.OUT, value=0)
def show(byte):
spi.write(bytes([byte])) # 8 bits out MSB first: bit 7 ends up on Q7, bit 0 on Q0
latch.value(1) # rising edge copies the shifted bits to the outputs at once
latch.value(0)
print("74HC595 on SPI0 (GP18/GP19), latch GP17")
while True:
print("Binary counter 0-255")
for n in range(256):
show(n)
time.sleep_ms(30)
print("Knight Rider")
for _ in range(3):
for i in list(range(8)) + list(range(6, 0, -1)):
show(1 << i)
time.sleep_ms(70)
show(0)
time.sleep(1)# 74HC595 shift register driving 8 LEDs from a Raspberry Pi Pico (MicroPython, hardware SPI).
# Wiring: VCC -> 3V3 (pin 36), GND -> GND, DS -> GP19 (pin 25, SPI0 TX),
# SH_CP -> GP18 (pin 24, SPI0 SCK), ST_CP (latch) -> GP17 (pin 22), OE -> GND, MR -> 3V3.
# Q0-Q7 -> LED anode -> 220 Ohm -> GND (one resistor per LED).
from machine import Pin, SPI
import time
spi = SPI(0, baudrate=1_000_000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(19), miso=Pin(16))
latch = Pin(17, Pin.OUT, value=0)
def show(byte):
spi.write(bytes([byte])) # 8 bits out MSB first: bit 7 ends up on Q7, bit 0 on Q0
latch.value(1) # rising edge copies the shifted bits to the outputs at once
latch.value(0)
print("74HC595 on SPI0 (GP18/GP19), latch GP17")
while True:
print("Binary counter 0-255")
for n in range(256):
show(n)
time.sleep_ms(30)
print("Knight Rider")
for _ in range(3):
for i in list(range(8)) + list(range(6, 0, -1)):
show(1 << i)
time.sleep_ms(70)
show(0)
time.sleep(1)Expected serial output
74HC595 on SPI0 (GP18/GP19), latch GP17
Binary counter 0-255
Knight Rider74HC595 on SPI0 (GP18/GP19), latch GP17 Binary counter 0-255 Knight Rider
Common errors
All LEDs on or flickering randomly
MR or OE is floating. Tie MR to 3V3 and OE to GND.
Pattern is mirrored
SPI sends bit 7 first, so it lands on Q7. Reverse the LED order on the breadboard or reverse the bits in code.