Skip to main content

Use the 74HC595 Shift Register with a Raspberry Pi

Project description

pi74HC595

Allows for easy use of the 74HC595 Shift Register with a Raspberry Pi

Pypi version Python version License Downloads

Install

$ pip install pi74HC595

Hardware

Raspberry Pi Pinout 74HC595 Pinout
Raspberry Pi Pinout 74HC595 Pinout

You will need to connect:

  • Vcc and MR to 5V

  • GND to Ground

  • Ds to any GPIO pin (DS pin during initialization)

  • STcp to any GPIO pin (ST pin during initialization)

  • SHcp to any GPIO pin (SH pin during initialization)

  • Q0 -> Q7 to anything you want to output to (not all have to be used)

  • Q7' to Ds on the next pi74HC595 if Daisy Chaining (multiple 74HC595s in series)

Initialize pi74HC595 class

gpio.setmode() can be either gpio.BOARD or gpio.BCM (pin numbering vs GPIO numbering).

from pi74HC595 import pi74HC595
import RPi.GPIO as gpio

gpio.setmode(gpio.BOARD)
shift_register = pi74HC595()

This package's default pins assumes gpio.BOARD as default

There are some default settings:

def __init__(
        DS: int = 11, # gpio.BOARD
        ST: int = 13,
        SH: int = 15,
        daisy_chain: int = 1,
    )

Pin Numbering

You will likely need to change the Raspberry Pi pins during initialization. Remember to check whether you used gpio.BOARD or gpio.BCM in your program.

shift_register = pi74HC595(7, 37, 22)

These can also be set after initialization with...

shift_register.set_ds(7) # Any GPIO pin on Raspberry Pi
shift_register.set_sh(37)
shift_register.set_st(22)

Daisy Chaining

If you are daisy chaining multiple 74HC595s then you can set daisy_chain to your number of 74HC595s during initialization.

shift_register = pi74HC595(7, 37, 22, 2)

shift_register = pi74HC595(daisy_chain = 13)

# etc

This can also be done after initialization with...

shift_register.set_daisy_chain(3) # Any positive int

Usage

Set Values with a List:

Will accept both Integers (1 and 0 only) as well as Boolean values (True and False)

shift_register.set_by_list([0, 1, 0, 1, 1, 1, 0, 0])
shift_register.set_by_list([False, True, False,...])

Set Values with an Integer:

This was created with the intent to send a single 1 or 0 for on or off, but can also function with a larger int as it converts to binary

shift_register.set_by_int(0)
shift_register.set_by_int(1)

shift_register.set_by_int(12) #1100
shift_register.set_by_int(9999) #1111100111

Set Values with a Boolean:

Can send a single True or False for on or off.

shift_register.set_by_bool(True)
shift_register.set_by_bool(False)

Clear All Current Values:

Sets each value to off (0)

shift_register.clear()

Get All Current Values:

Returns the current values

shift_register.get_values()
[0, 0, 0, 0, 0, 0, 0, 0]

Good 74HC595 Tutorials

It took me a while to finally understand how the 74HC595 worked since I had no prior hardware experience. These are the tutorials I used to understand the shift register.

Great but with Arduino

Good and with Raspberry Pi

Credits

License

MIT License. Please see License File for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pi74HC595-1.2.3.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

pi74HC595-1.2.3-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file pi74HC595-1.2.3.tar.gz.

File metadata

  • Download URL: pi74HC595-1.2.3.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10

File hashes

Hashes for pi74HC595-1.2.3.tar.gz
Algorithm Hash digest
SHA256 45e9e44584f753b513c7ea158b66f100afd65e8bb8616b0468b90fa8e3226332
MD5 352bea3b0173070a50248d410091cee6
BLAKE2b-256 75df08a02aab0c0474b096877c0aac2b8ba7a55368277359092c151515596fc6

See more details on using hashes here.

File details

Details for the file pi74HC595-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: pi74HC595-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10

File hashes

Hashes for pi74HC595-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 401ccf0da43869eab88283e0f16a10c8bfeb7714816f2ebcdf250e0b5a8eb5cc
MD5 0be65ca9af2558f9622515e829da72a1
BLAKE2b-256 5355e86e2a3947f6a46097973038657cdc84a426115324742d9802f02a60faeb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page