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

Install

$ pip install pi74HC595

Initialize pi74HC595 class

You should install the stockfish engine in your operating system globally or specify path to binary file in class constructor

from pi74HC595 import pi74HC595
import RPi.GPIO as gpio

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

This package uses gpio.BOARD (pin numbering as opposed to GPIO numbering)

There are some default settings:

def __init__(
        DS: int = 11,
        ST: int = 13,
        SH: int = 15,
        daisy_chain: int = 1,
        remember: bool = True,
    )

Pin Numbering

Raspberry Pi Numbering 74HC595 Pinout
Pin Numbering Example 74HC595 Pinout

Both Vcc and MR require 5V

You will likely need to change the Raspberry Pi pins during initialization.

shift_register = pi74HC595(7, 37, 22)

These can also be set after initialization with...

shift_register.set_ds(7)
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, daisy_chain = 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

Remembering Previous Statess

The default behaviour of a 74HC595 is that if the storage register is clocked, the old values are "forgotten".

If the current state is "10101010" and "1" is sent, the new state is "10000000". pi74HC595 preserves the previous state so if "1" is sent it will update to "11010101". This functionality can be removed during initialization.

shift_register = pi74HC595(7, 37, 22, daisy_chain = 2, remember = False)

shift_register = pi74HC595(remember = False)

# etc

This can also be done after initialization with...

shift_register.set_remember(False) # True or False

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 by converting 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 that is remembered to off (0)

shift_register.clear()

Get All Current Values:

Returns the current values, only when remember is set True

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

Good 74HC595 Tutorials

It took me awhile 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.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pi74HC595-1.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.8

File hashes

Hashes for pi74HC595-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b66cbc40306be614fd6196616bb2d58332071002c7fd34b2ccd82f0ebce3588c
MD5 ae470483dbf3a4eebb7e80de1bf5aa45
BLAKE2b-256 13257bd022bc888d6ad2bd837e2162aac45a6270074e20fa400baaf13c3a39fe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pi74HC595-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.8

File hashes

Hashes for pi74HC595-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ba9d985e6974a616141d460e0ad643399e596ab0efec5c01f1291f80d642dd4
MD5 c25fd906d0951b9e296e5b7ed06bc7c7
BLAKE2b-256 51566f2d54793839d795a36d71924234fa950c8db8ded8cd69be86a13ba58c53

See more details on using hashes here.

Supported by

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