Skip to main content

Python driver for the PCA9536 GPIO expander.

Project description

pca9536-driver

Easy-to-use python driver for the PCA9536 GPIO expander.

GitHub Workflow Status PyPI PyPI - License PyPI - Downloads

Installation

The package is available on PyPI. Installation is can be done with your favourite package manager. For example:

pip install pca9536-driver

Usage

In order to initialise the device we need an open SMBus object. Depending on the machine that you are running on you may need to provide another bus number or path:

from pca9536 import PCA9536
from smbus2 import SMBus


with SMBus(1) as bus:
    device = PCA9536(bus=bus)

The address of the PCA9536 defaults to 0x41. This is the (fixed) address of the PCA9536 devices, so you should never have to change it. If you do want to change it, you can provide it like PCA9536(bus=bus, address=0x42).

Controlling a pin

The PCA9536 has four GPIO pins, which are represented by PCA9536Pin objects that can be accessed by using index brackets:

pin = device[0]

If desired, you can loop over all pins:

for pin in device:
    ...

Reading the logic level of the pin is done with the read() method, which returns a boolean:

logic_level = pin.read()

To switch the pin to output mode and write the logic level:

from pca9536 import PinMode

pin.mode = PinMode.output  # or use "output"
pin.write(True)

Note that writing only sets the output flip-flops of the GPIO expander, and has therefore no effect when the pin is in input mode.

Simultaneous operations

If you have the need to read from, write to or set the mode of multiple pins simultaneously, then you can use the respective methods and properties of the PCA9536 object.

Reading returns a tuple of four booleans:

pin_0, pin_1, pin_2, pin_3 = device.read()

Writing can be done to one or more pins at the same time:

device.write(pin_0=True, pin_2=False)

Setting the same mode of all pins to the same value:

device.mode = PinMode.input

or specify a value per pin by providing a tuple of four values:

device.mode = PinMode.input, Pinmode.output, "input", None

Note that also here the values PinMode.input and PinMode.output may be used interchangeably with the strings "input" and "output". Providing None for any of the values will leave the mode of the respective pin unchanged.

Polarity inversion

The PCA9536 offers functionality to invert the polarity of the input bits. Note that the outputs are not affected by this setting.

Polarity inversion of a single pin can be enabled by:

pin.polarity_inversion = True

Polarity inversion of all pins can be set at the same time in a similar manner to that of the pin mode:

device.polarity_inversion = False
# or
device.polarity_inversion = False, True, True, None

where None will leave the current polarity inversion of a pin untouched.

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

pca9536_driver-0.1.3.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

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

pca9536_driver-0.1.3-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file pca9536_driver-0.1.3.tar.gz.

File metadata

  • Download URL: pca9536_driver-0.1.3.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pca9536_driver-0.1.3.tar.gz
Algorithm Hash digest
SHA256 9b11b636eea83da4e43b126829c76f097fa396cf3b547719c73cbe9eb0142874
MD5 4abe0f9ff10c796ff6d899706f42c16f
BLAKE2b-256 6929b12e7a29fd8a525296aade04d071643ae0bc2218b828dc8d5b04ed178816

See more details on using hashes here.

Provenance

The following attestation bundles were made for pca9536_driver-0.1.3.tar.gz:

Publisher: publish.yaml on rogiervandergeer/pca9536-driver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pca9536_driver-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pca9536_driver-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pca9536_driver-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 00ff2e936c9c46e7daaef4a73f86c71ef18db6f3c54e1f6df5efb463e66c521a
MD5 b95f73d73d07b645ead17c4e7b176e79
BLAKE2b-256 7fac3d70e05500983e77142a578d1dc1e250a127da79b04c84b0786aa0715ee3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pca9536_driver-0.1.3-py3-none-any.whl:

Publisher: publish.yaml on rogiervandergeer/pca9536-driver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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