Skip to main content

gpiodmonitor

Tiny wrapper around gpiod used to monitor and debounce button presses.

Callbacks are triggered on these events:

  • on change to active signal (e.g., button pressed)
  • on change to inactive signal (e.g., button released)
  • after the active signal has been stable for a certain period of time (e.g., button held down)
  • in regular interval while an "active" signal is recieved

Installation

You can isntall the package from pip:

pip install gpiodmonitor

Supports the libgpiod 1.x and 2.x Python APIs (including Bookworm and Trixie). The distro bindings must match the Python interpreter running this package. Under Ubuntu / Debian you can install it using:

sudo apt install python3-libgpiod

Usage:

from gpiodmonitor import gpiodmonitor

def dummy_active(pin: int):
    """Dummy function."""
    print(f'{pin} is active')

def dummy_inactive(pin: int):
    """Dummy function."""
    print(f'{pin} is inactive')

def dummy_pulsed_active(pin: int):
    """Dummy function."""
    print(f'{pin} is still active')

def dummy_long_active(pin: int):
    """Dummy function."""
    print(f'{pin} has been active for a long time')

monitor = gpiodmonitor.GPIODMonitor(chip=0)

for gpio_pin in [12,13]:
    # register some functions to be called on activity on pins 12 and 13
    monitor.register(int(gpio_pin),
                     on_active=dummy_active,
                     on_inactive=dummy_inactive)
    # register function that will be called every 300 ms as long as the
    # pin is active
    monitor.register_pulsed_active(int(gpio_pin),
                                 callback=dummy_pulsed_active,
                                 seconds=0.3)
    # register a function to be called when the button is pressed for 3
    # seconds
    monitor.register_long_active(int(gpio_pin),
                                 callback=dummy_long_active,
                                 seconds=3)

with monitor.open_chip():
    try:
        while True:
            # check according to interval
            time.sleep(monitor.check_interval / 1000)
            monitor.tick()
    except KeyboardInterrupt:
        sys.exit(130)
    # or use (equivalent but you don't have controll over the loop):
    # chip.monitor()

Metadata

Release files for gpiodmonitor 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpiodmonitor 1.4.0
File Size Uploaded Provenance Actions
gpiodmonitor-1.4.0.tar.gz 8.8 kB Without provenance Details for gpiodmonitor-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gpiodmonitor 1.4.0
File Interpreter ABI Platform Actions
gpiodmonitor-1.4.0-py3-none-any.whl Python 3 none any Details for gpiodmonitor-1.4.0-py3-none-any.whl

Total release size: 17.3 kB

Release files / gpiodmonitor-1.4.0.tar.gz

Download URL gpiodmonitor-1.4.0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
61c6026ea8debebf68438de4f7568df918dd8840b4653056fa3d347b50d27ea0
BLAKE2b-256 checksum
How to use checksums
12a534f6a14a3e29769c1a38d619f0e1d842a4c2b90117fd46314ca16d06eaa6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.8

Release files / gpiodmonitor-1.4.0-py3-none-any.whl

Download URL gpiodmonitor-1.4.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
009f204352619ae4b0b1c80266c5937bbd972476eea57fa17a9cb176685b498f
BLAKE2b-256 checksum
How to use checksums
eb762629f65d461294f90234119d6c499a7b43163815f8062909b0b5083b72e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.8

Security for gpiodmonitor 1.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page