pca9536-driver
Easy-to-use python driver for the PCA9536 GPIO expander.
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.
Metadata
Release files for pca9536-driver 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pca9536_driver-0.1.3.tar.gz | 13.0 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pca9536_driver-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.7 kB
Release files / pca9536_driver-0.1.3.tar.gz
| Download URL | pca9536_driver-0.1.3.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b11b636eea83da4e43b126829c76f097fa396cf3b547719c73cbe9eb0142874
|
|
BLAKE2b-256 checksum How to use checksums |
6929b12e7a29fd8a525296aade04d071643ae0bc2218b828dc8d5b04ed178816
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 28, 2025.
Transparency logRelease files / pca9536_driver-0.1.3-py3-none-any.whl
| Download URL | pca9536_driver-0.1.3-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
00ff2e936c9c46e7daaef4a73f86c71ef18db6f3c54e1f6df5efb463e66c521a
|
|
BLAKE2b-256 checksum How to use checksums |
7fac3d70e05500983e77142a578d1dc1e250a127da79b04c84b0786aa0715ee3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 28, 2025.
Transparency logSecurity for pca9536-driver 0.1.3
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pca9536_driver-0.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 28, 2025.
Transparency logA 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.