🐮 Tutorial 25 - 74HC595

The 74HC595 is an 8-bit serial-in, parallel-out shift register that allows data to be shifted in and then latched onto its output pins. It is commonly used in electronic projects to control large numbers of LEDs, motors, or other digital devices that require multiple control signals.

The 74HC595 is compatible with a wide range of microcontrollers and other digital devices, and can be easily interfaced with them using just a few digital input and output pins. It uses a serial input signal to shift data into the register, and a clock signal to synchronize the shifting of data. The output data can then be latched onto the output pins using a separate latch signal.

The 74HC595 also features an output enable pin that can be used to disable the output pins, as well as a clear pin that can be used to clear the register.

One of the key benefits of using the 74HC595 shift register is that it allows you to control multiple digital devices using just a few microcontroller pins. By cascading multiple shift registers together, you can control even larger numbers of devices using the same microcontroller.

The 74HC595 is available in a variety of package types, including DIP, SOIC, and TSSOP, making it easy to integrate into a wide range of electronic projects. It can be programmed using a variety of programming languages, including C, C++, and Python.

Overall, the 74HC595 shift register is a versatile and widely-used electronic component that provides a simple and effective way to control large numbers of digital devices using just a few microcontroller pins. Its ease of use and compatibility with a wide range of devices make it a popular choice for hobbyists and professionals alike.

Components Needed

ComponentQuantity
Raspberry Pi Pico W1
Micro USB Cable1
Breadboard1
WiresSeveral
Resistor8 - 220Ω
LED8
74HC5951

Fritzing Diagram

Code

import machine
import time

sdi = machine.Pin(0,machine.Pin.OUT)
rclk = machine.Pin(1,machine.Pin.OUT)
srclk = machine.Pin(2,machine.Pin.OUT)

def hc595_shift(dat):
    rclk.low()
    time.sleep_ms(5)
    for bit in range(7, -1, -1):
        srclk.low()
        time.sleep_ms(5)
        value = 1 & (dat >> bit)
        sdi.value(value)
        time.sleep_ms(5)
        srclk.high()
        time.sleep_ms(5)
    time.sleep_ms(5)
    rclk.high()
    time.sleep_ms(5)

num = 0

for i in range(16):
    if i < 8:
        num = (num<<1) + 1
    elif i>=8:
        num = (num & 0b01111111)<<1
    hc595_shift(num)
    print("{:0>8b}".format(num))
    time.sleep_ms(200)

Code Explanation