{"id":18837031,"url":"https://github.com/xreef/pcf8574_library","last_synced_at":"2025-04-12T15:39:12.783Z","repository":{"id":43946287,"uuid":"110599789","full_name":"xreef/PCF8574_library","owner":"xreef","description":"PCF8574 library. i2c digital expander for Arduino, Raspberry Pi Pico and rp2040 boards, esp32, SMT32 and ESP8266. Can read write digital values with only 2 wire. Very simple to use and encoder support.","archived":false,"fork":false,"pushed_at":"2025-01-11T07:35:04.000Z","size":40489,"stargazers_count":229,"open_issues_count":4,"forks_count":63,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-03T16:11:32.311Z","etag":null,"topics":["arduino","arduino-library","digital","encoder","esp-01","esp32","esp8266","expander","i2c","library","pcf8574","rp2040","stm32"],"latest_commit_sha":null,"homepage":"","language":"C++","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","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":"2017-11-13T20:43:31.000Z","updated_at":"2025-03-05T12:09:44.000Z","dependencies_parsed_at":"2024-02-01T19:08:07.287Z","dependency_job_id":"5245503d-c7da-4527-8921-bffb2844bf56","html_url":"https://github.com/xreef/PCF8574_library","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FPCF8574_library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FPCF8574_library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FPCF8574_library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FPCF8574_library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xreef","download_url":"https://codeload.github.com/xreef/PCF8574_library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248590655,"owners_count":21129868,"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","arduino-library","digital","encoder","esp-01","esp32","esp8266","expander","i2c","library","pcf8574","rp2040","stm32"],"created_at":"2024-11-08T02:33:22.603Z","updated_at":"2025-04-12T15:39:12.764Z","avatar_url":"https://github.com/xreef.png","language":"C++","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\n\n# PCF8574 PCF8574AP digital input and output expander with i2c bus.\n#### Complete documentation on my site: [pcf8574 Article](https://www.mischianti.org/2019/01/02/pcf8574-i2c-digital-i-o-expander-fast-easy-usage/).\n\n#### If you need more pins [here](https://www.mischianti.org/2019/07/22/pcf8575-i2c-16-bit-digital-i-o-expander/) you can find the pcf8575 16bit version of the IC.\n\n## Changelog\n - 01/02/2024: v2.3.7 Add the possibility to insert address at begin()\n - 10/07/2023: v2.3.6 Support for Arduino UNO R4\n - 08/02/2023: v2.3.5 Fix STM32 support and add support for Raspberry Pi Pico and other rp2040 boards\n - 10/08/2022: v2.3.4 Add support for custom SERCOM interface of Arduino SAMD devices. Force SDA SCL to use GPIO numeration for STM32 bug (https://www.mischianti.org/forums/topic/compatible-with-stm32duino/). \n - 28/07/2022: v2.3.3 Force SDA SCL to use GPIO numeration (https://www.mischianti.org/forums/topic/cannot-set-sda-clk-on-esp8266/).\n - 28/07/2022: v2.3.2 Fix the SDA SCL type #58 and add basic support for SAMD device.\n - 26/04/2022: v2.3.1 Fix example for esp32 and double begin issue #56.\n - 06/04/2022: v2.3.0 Fix package size\n - 30/12/2021: v2.2.4 Minor fix and remove deprecated declaration\n - 23/11/2020: v2.2.2 Add multiple implementation for encoder management (you can enable by uncomment relative define)\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**Constructor:**\nPass the address of I2C (to check the address use this guide [I2cScanner](https://playground.arduino.cc/Main/I2cScanner)) \n```cpp\n\tPCF8574(uint8_t address);\n```\nFor ESP8266 if you want to specify SDA and SCL pins use this:\n\n```cpp\n\tPCF8574(uint8_t address, uint8_t sda, uint8_t scl);\n```\nYou must set input/output mode:\n```cpp\n\tpcf8574.pinMode(P0, OUTPUT);\n\tpcf8574.pinMode(P1, INPUT);\n\tpcf8574.pinMode(P2, INPUT);\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/blob/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```cpp\n\tPCF8574::DigitalInput di = PCF8574.digitalReadAll();\n\tSerial.print(di.p0);\n\tSerial.print(\" - \");\n\tSerial.print(di.p1);\n\tSerial.print(\" - \");\n\tSerial.print(di.p2);\n\tSerial.print(\" - \");\n\tSerial.println(di.p3);\n```\n\nTo follow a request (you can see It on [issue #5](https://github.com/xreef/PCF8574_library/issues/5)) I create a define variable to work with low memory devices, if you uncomment this line in the .h file of the library:\n\n```cpp\n// #define PCF8574_LOW_MEMORY\n```\n\nEnable low memory props and gain about 7 bytes of memory, and you must use the method to read all like so:\n\n ```cpp\n\tbyte di = pcf8574.digitalReadAll();\n\tSerial.print(\"READ VALUE FROM PCF: \");\n\tSerial.println(di, BIN);\n```\n\nwhere `di` is a byte like 1110001, so you must do a bitwise operation to get the data, operation that I already do in the \"normal\" mode. For example:\n\n ```cpp\n\tp0 = ((di \u0026 bit(0))\u003e0)?HIGH:LOW;\n\tp1 = ((di \u0026 bit(1))\u003e0)?HIGH:LOW;\n\tp2 = ((di \u0026 bit(2))\u003e0)?HIGH:LOW;\n\tp3 = ((di \u0026 bit(3))\u003e0)?HIGH:LOW;\n\tp4 = ((di \u0026 bit(4))\u003e0)?HIGH:LOW;\n\tp5 = ((di \u0026 bit(5))\u003e0)?HIGH:LOW;\n\tp6 = ((di \u0026 bit(6))\u003e0)?HIGH:LOW;\n\tp7 = ((di \u0026 bit(7))\u003e0)?HIGH:LOW;\n ```\n \n\nif you want to read a single input:\n\n```cpp\n\tint p1Digital = PCF8574.digitalRead(P1); // read P1\n```\n\nIf you want to write a digital value:\n```cpp\n\tPCF8574.digitalWrite(P1, HIGH);\n```\nor:\n```cpp\n\tPCF8574.digitalWrite(P1, LOW);\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```cpp\n// Function interrupt\nvoid keyPressedOnPCF8574();\n\n// Set i2c address\nPCF8574 pcf8574(0x39, ARDUINO_UNO_INTERRUPT_PIN, keyPressedOnPCF8574);\n```\nRemember you can't use Serial or Wire on an interrupt function.\n\nIt's better to only set a variable to read on loop:\n```cpp\nvoid keyPressedOnPCF8574(){\n\t// Interrupt called (No Serial no read no wire in this function, and DEBUG disabled on PCF library)\n\t keyPressed = true;\n}\n```\n\nFor the examples I use this wire schema on breadboard:\n![Breadboard](https://github.com/xreef/PCF8574_library/raw/master/resources/testReadWriteLedButton_bb.png)\n\nhttps://downloads.arduino.cc/libraries/logs/github.com/xreef/PCF8574_library/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxreef%2Fpcf8574_library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxreef%2Fpcf8574_library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxreef%2Fpcf8574_library/lists"}