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

Needs libgpiod2 installed. Under Ubuntu / Debian you can install it using:

sudo apt install libgpiod2 python3-gpiod

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()

Download files

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

Source Distribution

gpiodmonitor-1.3.1.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

gpiodmonitor-1.3.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file gpiodmonitor-1.3.1.tar.gz.

File metadata

  • Download URL: gpiodmonitor-1.3.1.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for gpiodmonitor-1.3.1.tar.gz
Algorithm Hash digest
SHA256 ea34f030be177c4c155a4a059ed8c1df75a3686d4ed469778b0696d3ebaba7d7
MD5 c7e97300cf7fa16a42567cc4404d2a07
BLAKE2b-256 332cb95c6f25b7ef668480fd7f6510fde818ed35add1ec3aa4c3039ea74ca81f

See more details on using hashes here.

File details

Details for the file gpiodmonitor-1.3.1-py3-none-any.whl.

File metadata

  • Download URL: gpiodmonitor-1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.0

File hashes

Hashes for gpiodmonitor-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8b3fa3e3d87f068d7904d57d3b15fcd66b20e9607221c0340ac71feda14b5785
MD5 5a82d1fd11feb40ab384e175443468e9
BLAKE2b-256 13235ed4d586b9585ca4f8a39fee9197215d4aa44f64121302ca18601e775b68

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.3.1 This release

2 files

1.3.0

2 files

1.2.0

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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