pizazz

Easy configuration and control of 74HC595 Shift Registers with a Raspberry Pi

https://github.com/stephen-ra-king/pizazz

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.6%) to scientific vocabulary

Keywords

74hc595 led leds monitoring-tool python python3 raspberry-pi shift-register

Keywords from Contributors

python-version-management energy-system-model profiles mesh data-profiling benchmarking regionalization parallel energy-system exoplanet
Last synced: 6 months ago · JSON representation ·

Repository

Easy configuration and control of 74HC595 Shift Registers with a Raspberry Pi

Basic Info
  • Host: GitHub
  • Owner: Stephen-RA-King
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 677 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • Open Issues: 1
  • Releases: 7
Topics
74hc595 led leds monitoring-tool python python3 raspberry-pi shift-register
Created almost 4 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog License Citation Authors

README.md

Pizazz

A utility class to leverage 74HC595 shift register chips with a Raspberry Pi.

PyPI version Documentation Status Downloads pre-commit Imports: isort Code style: black Checked with mypy security: bandit licence: mit

The 74HC595 shift register is an incredibly useful chip. A single chip has 8 output pins which can be controlled with only 3 input pins (excluding Vcc and Gnd of course). That is great in itself however 595's can be daisy-chained together to give you multiples of 8 pin outputs yet still always controlled by only 3 input pins! Wow!

If you are not sure why this is useful then let me explain.

I had a requirement to create a LED "Status Board" for a monitoring and automation application that I am also writing. The status board would reflect the current operation status of things like Jenkins jobs, Github Actions, Linux services etc etc. I needed a minimum of 16 LEDs. Now there already exists a status board HAT. However it only tracks 5 items (that is 10 LED's). However, each LED requires it's own GPIO and the HAT masks all other pins making them unavailable.

Using the Raspberry RPi.GPIO library it is possible to individually switch the 27 GPIO pins. However each LED would require a wire from the GPIO pin. This is very physically unwieldy and clunky to control in Python.

Enter the 74HC595...

This class enables you to individually control any number of LEDS (or other output devices) with only 3 GPIO pins.

Basic Wiring of the 74HC595 8-bit shift register to a Raspberry Pi

| Pin | Tag | Description | | ----- | ------- | ----------------------------- | | 1 - 7 | Q1 - Q7 | Parallel Data output pins 1-7 | | 8 | Gnd | Ground | | 9 | Q7-> | Serial data output pin | | 10 | MR | Master Reset | | 11 | SH | Clock pin | | 12 | ST | Latch pin | | 13 | OE | Output enable | | 14 | DS | Serial data input | | 15 | Q0 | Parallel data output pin 0 | | 16 | Vcc | Positive voltage supply |

Chaining 2 or more shift registers together

How the register works

The 595 has two registers (which can be thought of as “memory containers”), each with just 8 bits of data.

  1. The Shift Register
  2. The Storage Register

Whenever we apply a clock pulse to a 595, two things happen:

  1. The bits in the Shift Register move one step to the left. For example, Bit 7 accepts the value that was previously in bit 6, bit 6 gets the value of bit 5 etc.

  2. Bit 0 in the Shift Register accepts the current value on DATA pin. At the rising edge of the pulse, if the data pin is high, then a 1 gets pushed into the shift register. Otherwise, it is a 0.

On enabling the Latch pin, the contents of Shift Register are copied into the Storage Register. Each bit of the Storage Register is connected to one of the output pins Q0–Q7 of the IC, so in general, when the value in the Storage Register changes, so do the outputs.

Installation


Raspberry Pi:

sh pip3 install pizazz

Connecting the Raspberry Pi


The 40 pins of the Raspberry Pi are GPIO, 5v, 3.3V and ground. Some of the GPIO pins can have special purposes. However, all of them can be controlled by the RPi.GPIO Python Library. The RPi.GPIO requires that you specify how you will identify the pins that you use. There are 2 ways:

  1. GPIO.BOARD: option specifies that you are referring to the pins by the number of the pin.

  2. BCM: option means that you are referring to the pins by the "Broadcom SOC channel" number, these are the numbers after "GPIO"

So referring to the diagram below: BCM mode GPIO2 is the same as BOARD mode pin 2

Connect any GPIO's to the clock, latch and data pins of the register and connect the the 5v supply and earth as indicated in the register diagram. If you are connecting the outputs to LED's then you need to wire 330 ohm resistors serially to protect them in the usual way.

Library Usage examples


For more examples and usage, please refer to the Wiki.

https://user-images.githubusercontent.com/33905365/220999848-e6062e9d-af53-4c91-8db8-0f8b5fdf1ff3.mp4

Import the library

sh from pizazz.pizazz import HC595

Instantiate the library passing the initialisation arguments

sh shifter = HC595(mode="BCM", data=17, clock=27, latch=18, ics=2)

the 'ics' parameter defines the number of registers daisey-chained together.

There are four public methods in the library:

| Method | Description | | ------------- | ---------------------------------------- | | clear() | sets shift and storage registers to zero | | test() | Cycles sequentially through all outputs | | setoutput() | explicitly sets specific pin outputs | | setpattern() | sets output using a bit pattern |

1. Using the set_output(output, mask) method

Args:

output (int) - decimal value of the binary bits you want to set to "on"

mask (int) - decimal value of the binary bits to consider in this operation.

Consider the following setup:

Using a mask has 2 benefits:

  1. It enables the library to explicitly turn LEDS 'off'. e.g. sending an output value of 16 means turn pin 5 'on'. it has no concept of turning pin 6 'off'. Using a mask facilitates this.
  2. It isolates the pins to consider in the update. For a status board this is important. The inputs from the sensors can now be considered in isolation from the other sensors making asynchronous updates possible.

Consider sensor 2:

| method values | LED3 | LED4 | | ------------------ | ---- | ---- | | setoutput(0, 12) | OFF | OFF | | setoutput(4, 12) | ON | OFF | | setoutput(8, 12) | OFF | ON | | setoutput(12, 12) | ON | ON |

NOTE: All other LED outputs remain the same and are untouched by these operations

This now makes programming the shift register a simple process. e.g. consider a Jenkins job

```sh jenkinsmask = 48 jenkinspass = 16 jenkins_fail = 32

'sensor' receives a failing indication

shifter.setoutput(jenkinsfail, jenkins_mask)

'sensor' receives a passing indication

shifter.setoutput(jenkinspass, jenkins_mask)

```

The second value is the bit mask (similar to an IP bit mask) - Explained later

2. Using the setpattern(chippattern) method

Args:

chip_pattern (List or Nested List) - Bit pattern representing the pins to set 'on' or 'off'. If more than two registers are used then the pattern should be a nested list.

Using the bit pattern (for a two chip configuration)

sh shifter.set_pattern([[0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]])

For a single chip a simple list should be used:

sh shifter.set_pattern([0, 0, 1, 1, 0, 0, 0, 0])

Documentation


Read the Docs

Wiki

Meta


Stephen R A King : sking.github@gmail.com

Created with Cookiecutter template: pydough version 1.2.2

Digital object identifier: DOI

Owner

  • Name: Stephen King
  • Login: Stephen-RA-King
  • Kind: user
  • Location: Exeter, Devon, England

Software Engineer / Python Developer

Citation (CITATION.cff)

cff-version: 1.2.0
title: pizazz
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Stephen
    family-names: King
    email: sking.github@gmail.com
    orcid: "https://orcid.org/0009-0001-1939-6012"
identifiers:
  - type: doi
    value: 10.5281/zenodo.8118849

GitHub Events

Total
  • Push event: 21
Last Year
  • Push event: 21

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 95
  • Total Committers: 4
  • Avg Commits per committer: 23.75
  • Development Distribution Score (DDS): 0.053
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Stephen-RA-King 3****g 90
pre-commit-ci[bot] 6****] 3
dependabot[bot] 4****] 1
semantic-release s****e 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 24
  • Average time to close issues: N/A
  • Average time to close pull requests: about 1 month
  • Total issue authors: 0
  • Total pull request authors: 3
  • Average comments per issue: 0
  • Average comments per pull request: 0.42
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 24
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • pre-commit-ci[bot] (15)
  • dependabot[bot] (10)
  • lgtm-com[bot] (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (10)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 39 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 9
  • Total maintainers: 1
pypi.org: pizazz

Easy configuration and control of 74HC595 Shift Registers on a Raspberry Pi

  • Versions: 9
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 39 Last month
Rankings
Dependent packages count: 10.1%
Dependent repos count: 21.6%
Forks count: 22.7%
Average: 24.6%
Downloads: 29.8%
Stargazers count: 38.8%
Maintainers (1)
Last synced: 6 months ago

Dependencies

docs/requirements.txt pypi
  • myst-nb *
  • sphinx-autoapi *
  • sphinx-rtd-theme *
requirements/development.in pypi
  • bandit * development
  • black * development
  • build * development
  • click * development
  • colorama * development
  • coverage * development
  • coverage-conditional-plugin * development
  • flake8 * development
  • flake8-bandit * development
  • flake8-bugbear * development
  • flake8-comprehensions * development
  • flake8-docstrings * development
  • flake8-eradicate * development
  • flake8-pytest-style * development
  • flake8-simplify * development
  • flakeheaven * development
  • isort * development
  • jupyter * development
  • keyring * development
  • lxml * development
  • mypy * development
  • myst-nb * development
  • pep8-naming * development
  • pre-commit * development
  • pytest * development
  • python-semantic-release * development
  • pyyaml * development
  • safety * development
  • sphinx * development
  • sphinx-autoapi * development
  • sphinx-rtd-theme * development
  • tox * development
  • twine * development
  • watchdog * development
requirements/development.txt pypi
  • 175 dependencies
requirements/requirements_tox.txt pypi
  • black *
  • click *
  • flake8 *
  • lxml *
  • mypy *
  • pytest *
  • pyyaml *
  • safety *
requirements/test.in pypi
  • pytest * test
requirements/test.txt pypi
  • atomicwrites ==1.4.0 test
  • attrs ==21.4.0 test
  • colorama ==0.4.4 test
  • iniconfig ==1.1.1 test
  • packaging ==21.3 test
  • pluggy ==1.0.0 test
  • py ==1.11.0 test
  • pyparsing ==3.0.9 test
  • pytest ==7.1.2 test
  • tomli ==2.0.1 test