{"id":14971046,"url":"https://github.com/xreef/pcf8574_micropython_library","last_synced_at":"2025-10-26T14:31:00.874Z","repository":{"id":153280212,"uuid":"627974283","full_name":"xreef/PCF8574_micropython_library","owner":"xreef","description":"MicroPython library for pcf8574 an i2c digital expander for Arduino, esp32, SMT32 and ESP8266. Can read write digital values with only 2 wire. ","archived":false,"fork":false,"pushed_at":"2023-04-18T20:36:05.000Z","size":11,"stargazers_count":6,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T20:16:01.737Z","etag":null,"topics":["arduino","digital","esp32","esp8266","expander","i2c","library","micropython","pcf8574","pcf8574a","raspberry","rp2040","samd","stm32","wire"],"latest_commit_sha":null,"homepage":"https://www.mischianti.org/category/my-libraries/pcf8574/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xreef.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-04-14T16:01:15.000Z","updated_at":"2024-10-15T02:35:55.000Z","dependencies_parsed_at":"2023-06-18T15:15:56.065Z","dependency_job_id":null,"html_url":"https://github.com/xreef/PCF8574_micropython_library","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"9d024f0c2ba0188a2681d668b3b4ec3a3f2a6f2b"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FPCF8574_micropython_library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FPCF8574_micropython_library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FPCF8574_micropython_library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FPCF8574_micropython_library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xreef","download_url":"https://codeload.github.com/xreef/PCF8574_micropython_library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238347441,"owners_count":19456935,"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":["arduino","digital","esp32","esp8266","expander","i2c","library","micropython","pcf8574","pcf8574a","raspberry","rp2040","samd","stm32","wire"],"created_at":"2024-09-24T13:44:38.534Z","updated_at":"2025-10-26T14:30:55.554Z","avatar_url":"https://github.com/xreef.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv\u003e\n\u003ca href=\"https://www.mischianti.org/forums/forum/mischiantis-libraries/pcf8574-i2c-digital-i-o-expander/\"\u003e\u003cimg\n  src=\"https://github.com/xreef/LoRa_E32_Series_Library/raw/master/resources/buttonSupportForumEnglish.png\" alt=\"Support forum pcf8574 English\"\n   align=\"right\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv\u003e\n\u003ca href=\"https://www.mischianti.org/it/forums/forum/le-librerie-di-mischianti/pcf8574-expander-digitale-i-o-i2c/\"\u003e\u003cimg\n  src=\"https://github.com/xreef/LoRa_E32_Series_Library/raw/master/resources/buttonSupportForumItaliano.png\" alt=\"Forum supporto pcf8574 italiano\"\n  align=\"right\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n#\n#### www.mischianti.org\n\n# PCF8574 PCF8574AP digital input and output expander with i2c bus.\n\n## Changelog\n - 18/04/2023: v0.0.2 Add static declaration for Px constants inside class.\n - 14/04/2023: v0.0.1 Initial commit of stable version.\n\nI try to simplify the use of this IC, with a minimal set of operations.\n\nTested with esp8266, esp32, Arduino, Arduino SAMD (Nano 33 IoT, MKR etc.), STM32 and rp2040 (Raspberry Pi Pico and similar)\n\nPCF8574P address map 0x20-0x27 \nPCF8574AP address map 0x38-0x3f \n\n### Installation\nTo install the library execute the following command:\n\n```bash\npip install pcf8574-library\n```\n\n**Constructor:**\nPass the address of I2C \n```python\n    from PCF8574 import PCF8574\n    \n    pcf = PCF8574(0x38, sda=21, scl=22)\n```\nTo use interrupt you must pass the interrupt pin and the function to call when interrupt raised from PCF8574\n```python\n    from PCF8574 import PCF8574\n    \n    def keyPressedOnPCF8574(pin):\n        # Interrupt called (No Serial no read no wire in this function, and DEBUG disabled on PCF library)\n        keyPressed = True\n    \n    pcf = PCF8574(0x38, sda=21, scl=22, interrupt_callback=keyPressedOnPCF8574, interrupt_pin=18)\n```\n\nYou must set input/output mode:\n```python\n    from machine import Pin\n    from PCF8574 import PCF8574\n\n    pcf.Pin(PCF8574.P0, Pin.IN)\n    pcf.Pin(PCF8574.P1, Pin.IN, Pin.PULL_UP)\n    pcf.Pin(PCF8574.P2, Pin.IN)\n    pcf.Pin(PCF8574.P3, Pin.IN)\n    \n    pcf.Pin(PCF8574.P7, Pin.OUT)\n    pcf.Pin(PCF8574.P6, Pin.OUT, 1)\n    pcf.Pin(PCF8574.P5, Pin.OUT, 0)\n    pcf.Pin(PCF8574.P4, Pin.OUT, 0)\n```\n\nthen IC as you can see in the image has 8 digital input/output ports:\n\n![PCF8574 schema](https://github.com/xreef/PCF8574_library/raw/master/resources/PCF8574-pins.gif)\n\nTo read all analog input in one trasmission you can do (even if I use a 10millis debounce time to prevent too much read from i2c):\n```python\n    digital_input = pcf.digital_read_all()\n    \n    print(digital_input.p0)\n    print(digital_input.p1)\n    print(digital_input.p2)\n    print(digital_input.p3)\n    print(digital_input.p4)\n    print(digital_input.p5)\n    print(digital_input.p6)\n    print(digital_input.p7)\n    \n    array_input = pcf.digital_read_all_array()\n    print(array_input)\n    \n    byte_input = pcf.digital_read_all_byte()\n    print(bin(byte_input))\n```\n\nIf you want to read a single input:\n```python\n    digital_input = pcf.digital_read(PCF8574.P1)\n    print(digital_input)\n```\n\nIf you want to write a digital value:\n```python\n    pcf.digital_write(PCF8574.P1, 1)\n```\n\nYou can also use an interrupt pin:\nYou must initialize the pin and the function to call when interrupt raised from PCF8574\n```python\n    def callback(pin):\n        now = utime.ticks_ms()\n        global count\n        count += 1\n        print(\"Time: {} {}\".format(now, count))\n    \n    \n    pcf.attach_interrupt(18, callback)\n```\n\nFor the examples I use this wire schema on breadboard:\n![Breadboard](https://www.mischianti.org/wp-content/uploads/2021/04/WeMos-D1-esp8266-pcf8574-IC-wiring-schema-8-leds.jpg)\n![Breadboard](https://www.mischianti.org/wp-content/uploads/2021/04/esp32-pcf8574-IC-wiring-schema-8-leds.jpg)\n![Breadboard](https://www.mischianti.org/wp-content/uploads/2022/08/stm32_pcf8574_wiring_4_Led_4_Buttons_bb.jpg)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxreef%2Fpcf8574_micropython_library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxreef%2Fpcf8574_micropython_library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxreef%2Fpcf8574_micropython_library/lists"}