{"id":13802298,"url":"https://github.com/mcauser/micropython-pcf8574","last_synced_at":"2025-04-12T00:32:07.092Z","repository":{"id":150620694,"uuid":"224572496","full_name":"mcauser/micropython-pcf8574","owner":"mcauser","description":"MicroPython driver for PCF8574 8-Bit I2C I/O Expander with Interrupt","archived":false,"fork":false,"pushed_at":"2024-02-11T04:11:05.000Z","size":2772,"stargazers_count":32,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-22T12:34:43.790Z","etag":null,"topics":["io-expander","micropython","pcf8574"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcauser.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-28T04:53:50.000Z","updated_at":"2024-08-04T00:07:07.639Z","dependencies_parsed_at":"2024-08-04T00:17:53.284Z","dependency_job_id":null,"html_url":"https://github.com/mcauser/micropython-pcf8574","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-pcf8574","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-pcf8574/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-pcf8574/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcauser%2Fmicropython-pcf8574/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcauser","download_url":"https://codeload.github.com/mcauser/micropython-pcf8574/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501410,"owners_count":21114674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["io-expander","micropython","pcf8574"],"created_at":"2024-08-04T00:01:41.472Z","updated_at":"2025-04-12T00:32:06.069Z","avatar_url":"https://github.com/mcauser.png","language":"Python","readme":"# MicroPython PCF8574\n\nA MicroPython library for PCF8574 8-Bit I2C I/O Expander with Interrupt.\n\n![demo](docs/demo.jpg)\n\nThe PCF8574 consists of a 8-bit quasi-bidirectional port and an I2C-bus interface.\n\nThe device includes latched outputs with high current drive capability for directly driving LEDs.\n\nThe interrupt has an open-drain output, which means you need a pull-up on your microcontroller\nto detect when the PCF8574 drives it LOW.\n\nWhen setting a pin HIGH, it acts as both output AND input. The pin internally uses a weak\ncurrent-source pull-up to latch output HIGH.\nWhen driven LOW, for example, with a push button, the pin will read as LOW.\n\nAn interrupt fires on any rising or falling edge of the pins in input mode (HIGH).\nInterrupt is cleared when the pins are changed or the port is read.\n\nAt power on, all pins are driven HIGH and can be immediately used as inputs.\n\nOperating voltage: 2.5V - 5.5V\n\n\n## Installation\n\nUsing mip via mpremote:\n\n```bash\n$ mpremote mip install github:mcauser/micropython-pcf8574\n$ mpremote mip install github:mcauser/micropython-pcf8574/examples\n```\n\nUsing mip directly on a WiFi capable board:\n\n```python\n\u003e\u003e\u003e import mip\n\u003e\u003e\u003e mip.install(\"github:mcauser/micropython-pcf8574\")\n\u003e\u003e\u003e mip.install(\"github:mcauser/micropython-pcf8574/examples\")\n```\n\nManual installation:\n\nCopy `src/pcf8574.py` to the root directory of your device.\n\n\n## Examples\n\n**Basic Usage**\n\n```python\nimport pcf8574\nfrom machine import I2C, Pin\n\n# TinyPICO (ESP32)\ni2c = I2C(0)\npcf = pcf8574.PCF8574(i2c, 0x20)\n\n# read pin 2\npcf.pin(2)\n\n# set pin 3 HIGH\npcf.pin(3, 1)\n\n# set pin 4 LOW\npcf.pin(4, 0)\n\n# toggle pin 5\npcf.toggle(5)\n\n# set all pins at once with 8-bit int\npcf.port = 0xFF\n\n# read all pins at once as 8-bit int\npcf.port\n# returns 255 (0xFF)\n```\n\nFor more detailed examples, see [examples](/examples).\n\nIf you mip installed them above, you can run them like so:\n\n```python\nimport pcf8574.examples.basic\n```\n\n\n#### Pins\n\nPin  | Type | Description\n:---:|:----:|:----------------------------------------\nA0   | I    | Address select 1, connect to VCC or GND\nA1   | I    | Address select 2, connect to VCC or GND\nA2   | I    | Address select 3, connect to VCC or GND\nINT  | O    | Interrupt output, open drain, active LOW\nP00  | I/O  | Port A, Pin 0\nP01  | I/O  | Port A, Pin 1\nP02  | I/O  | Port A, Pin 2\nP03  | I/O  | Port A, Pin 3\nP04  | I/O  | Port A, Pin 4\nP05  | I/O  | Port A, Pin 5\nP06  | I/O  | Port A, Pin 6\nP07  | I/O  | Port A, Pin 7\nSDA  | I/O  | I2C Serial Data, needs pull-up\nSCL  | I    | I2C Serial Clock, needs pull-up\nGND  | PWR  | Ground\nVCC  | PWR  | Supply voltage 3.3-5V\n\n\n## Methods\n\nConstruct with a reference to I2C and set the device address.\nValid address range 0x20-0x27.\nIf are you not sure what it is, run an `i2c.scan()`.\nSee below for address selection.\n```python\n__init__(i2c, address=0x20)\n```\n\nScans the I2C bus for the provided address and returns True if a device is present\notherwise raises an OSError.\n```python\ncheck()\n```\n\nMethod for getting or setting a single pin.\nIf no value is provided, the port will be read and value of specified pin returned.\nIf a value is provided, the port will be updated and device written to.\nThe port is written to after each call. If you intend to toggle many pins at once, use the\nport property instead. See below.\nValid pin range 0-7.\n```python\npin(pin, value=None)\n```\n\nMethod for flipping the value of a single pin.\nValid pin range 0-7.\n```python\ntoggle(pin)\n```\n\nPrivate method for checking the supplied pin number is within the valid range.\n```python\n_validate_pin()\n```\n\nPrivate method for loading _port from the device.\n```python\n_read()\n```\n\nPrivate method for sending _port to the device.\n```python\n_write()\n```\n\n\n## Properties\n\nGetter reads the port from the device and returns a 8-bit integer.\n```python\nport\n```\n\nSetter writes an 8-bit integer representing the port to the device.\nIf you are setting multiple pins at once, use this instead of the pin() method as\nthis writes the entire 8-bit port to the device once, rather than 8 separate writes.\n```python\nport = 0xFF\n```\n\n\n## Ports\n\n* P00-P07 - Port A\n\nThis chip only has one port (8 pins). If you need more pins, the\n[PCF8575](https://github.com/mcauser/micropython-pcf8575) has two ports (16 pins).\n\n\n## Interrupts\n\n* INT - Active LOW\n\n\n## I2C Interface\n\nIf you are using a module, most contain 10k pull-ups on the SCL and SDA lines.\n\nIf you are using the PCF8574 chip directly, you'll need to add your own.\n\n\n### I2C Address\n\nThe chip supports I2C addresses 0x20-0x27 and is customisable using address pins A0, A1, A2\n\nA0  | A1  | A2  | I2C Address\n----|-----|-----|------------\nGND | GND | GND | 0x20 (default)\n3V3 | GND | GND | 0x21\nGND | 3V3 | GND | 0x22\n3V3 | 3V3 | GND | 0x23\nGND | GND | 3V3 | 0x24\n3V3 | GND | 3V3 | 0x25\nGND | 3V3 | 3V3 | 0x26\n3V3 | 3V3 | 3V3 | 0x27\n\n\n## Parts\n\n* [PCF8574 blue chainable board](https://s.click.aliexpress.com/e/_DdzV1ZR)\n* [PCF8574 blue chainable board](https://s.click.aliexpress.com/e/_DlQkWZj)\n* [PCF8574 red board DIP switch](https://s.click.aliexpress.com/e/_DevQFrx)\n* [PCF8574 red board DIP switch](https://s.click.aliexpress.com/e/_Dmeylnb)\n* [PCF8574 purple board](https://s.click.aliexpress.com/e/_DlcJB2t)\n* [PCF8574 as 1602 LCD backpack](https://s.click.aliexpress.com/e/_DlcJB2t)\n* [PCF8574 10x DIP-16](https://s.click.aliexpress.com/e/_Dn3xoYh)\n* [PCF8574 5x SOP-16](https://s.click.aliexpress.com/e/_DC1lqxn)\n* [TinyPICO](https://www.tinypico.com/)\n\n\n## Connections\n\n### TinyPICO ESP32\n\n```python\nfrom machine import SoftI2C, Pin\ni2c = SoftI2C(scl=Pin(22), sda=Pin(21))\n\nfrom machine import I2C, Pin\ni2c = I2C(0)\n```\n\nPCF8574 Module | TinyPICO (ESP32)\n-------------- | ----------------\nSDA            | 21 (SDA)\nSCL            | 22 (SCL)\nVCC            | 3V3\nGND            | GND\nINT (optional) | 4\n\n\n## Links\n\n* [micropython.org](http://micropython.org)\n* [PCF8574 datasheet](docs/pcf8574.pdf)\n* [TinyPICO Getting Started](https://www.tinypico.com/gettingstarted)\n\n\n## License\n\nLicensed under the [MIT License](http://opensource.org/licenses/MIT).\n\nCopyright (c) 2019 Mike Causer\n","funding_links":[],"categories":["Libraries"],"sub_categories":["IO"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcauser%2Fmicropython-pcf8574","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcauser%2Fmicropython-pcf8574","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcauser%2Fmicropython-pcf8574/lists"}