Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pyStringToSevenSegmentDisplay

A Python port of the stringToSevenSegmentDisplay Arduino library for Raspberry Pi. Drives 7-segment displays via 74HC595 shift registers using RPi.GPIO.

Requirements

  • Raspberry Pi with GPIO
  • RPi.GPIO

Installation

Either copy src/string_to_seven_segment_display.py into your project directory, or install via pip:

pip install git+https://github.com/neoge/pyStringToSevenSegmentDisplay.git

# upgrade (for later)
pip install --upgrade git+https://github.com/neoge/pyStringToSevenSegmentDisplay.git

On Raspberry Pi OS Bookworm and later, pip requires a virtual environment:

python3 -m venv venv  # run in your project directory
venv/bin/pip install git+https://github.com/neoge/pyStringToSevenSegmentDisplay.git
venv/bin/python your_script.py

Usage

import string_to_seven_segment_display as seg

latch_pin = 11  # Board pin numbering
clock_pin = 13
data_pin  = 12

display = seg.string_to_seven_segment_display(latch_pin, clock_pin, data_pin)
display.string_to_segments("!TEST!", auto_latch=True)
  • seg.string_to_seven_segment_display(latch_pin, clock_pin, data_pin, reverse_strings=False): Creates the display driver. Set reverse_strings=True for displays that shift data from the opposite end.
  • string_to_segments(input_string, auto_latch): Converts and sends the string to the display.

Supported characters: 0-9, A-Z (case-insensitive), and symbols like . , - _ = ° " ' [ ] ( ) { } / \ < > ^ : ; | ! ?.

Unknown characters default to underscore (_).

Examples

See the examples/ folder:

  • seven_segment_clock.py — displays the current time, blinking the colon every second
  • seven_segment_pipe.py — reads from stdin and displays each line:
    echo -n '!TEST!' | venv/bin/python seven_segment_pipe.py
    some_script.sh | venv/bin/python seven_segment_pipe.py

Autostart seven_segment_clock.py with systemd

A service template is included at examples/seven_segment_clock.service. To run the clock automatically at boot:

  1. Copy the script to the target directory (e.g. /opt/segment/):
    sudo mkdir -p /opt/segment/
    sudo cp examples/seven_segment_clock.py /opt/segment/
    If the library is not installed via pip, also copy the library file:
    sudo cp src/string_to_seven_segment_display.py /opt/segment/
  2. Edit the service file to match your paths and user, then install it:
    sudo cp examples/seven_segment_clock.service /etc/systemd/system/
    sudo systemctl daemon-reload
    sudo systemctl enable seven_segment_clock
    sudo systemctl start seven_segment_clock

Hardware

The matching PCB designs are available via OSHWLab or in the main repository stringToSevenSegmentDisplay (Arduino library + Gerber files).

Design OSHWLab (open & edit live)
6x7 Segment Display (main) Open Project
74HC595N Binary Display Open Project
DIP Switch Serial Shift Open Project

License

MIT License. See LICENSE file for details.

About

Python port of the stringToSevenSegmentDisplay Arduino library for Raspberry Pi — drives 7-segment displays via 74HC595 shift registers using RPi.GPIO.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages