https://github.com/flyte/pcf8574
A library for the pcf8574 I2C IO expander chip
https://github.com/flyte/pcf8574
Last synced: 11 months ago
JSON representation
A library for the pcf8574 I2C IO expander chip
- Host: GitHub
- URL: https://github.com/flyte/pcf8574
- Owner: flyte
- License: mit
- Created: 2016-11-02T17:27:49.000Z (over 9 years ago)
- Default Branch: develop
- Last Pushed: 2023-10-26T15:38:16.000Z (over 2 years ago)
- Last Synced: 2025-06-23T16:49:27.444Z (about 1 year ago)
- Language: Python
- Size: 12.7 KB
- Stars: 34
- Watchers: 2
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PCF8574
=======
This is a Python library for use with the [PCF8574](http://www.nxp.com/documents/data_sheet/PCF8574.pdf) I2C IO expander chip. It abstracts the 8 bit IO port as a Python list, and allows the read/writing of individual pins or the whole port at once.
## Installation
The library depends on the `smbus-cffi` package. You may need to `apt-get install libffi-dev` if you're on a debian based system. Otherwise, simply:
```
pip install pcf8574
```
## Usage
```python
In [1]: from pcf8574 import PCF8574
In [2]: i2c_port_num = 1
In [3]: pcf_address = 0x20
In [4]: pcf = PCF8574(i2c_port_num, pcf_address)
In [5]: pcf.port
Out[5]: [True, True, True, True, True, True, True, True]
In [6]: pcf.port[0] = False
In [7]: pcf.port
Out[7]: [False, True, True, True, True, True, True, True]
In [8]: pcf.port = [True, False, True, False, True, False, True, False]
In [9]: pcf.port
Out[9]: [True, False, True, False, True, False, True, False]
In [10]: pcf.port[7]
Out[10]: False
In [11]: pcf.port[6]
Out[11]: True
```