pcf8574-library


Namepcf8574-library JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://github.com/xreef/PCF8574_micropython_library
SummaryMost starred 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
upload_time2023-04-18 20:37:35
maintainerRenzo Mischianti
docs_urlNone
authorRenzo Mischianti
requires_python>=3.7
licenseThe MIT License (MIT) Copyright (c) 2017 Renzo Mischianti www.mischianti.org All right reserved. You may copy, alter and reuse this code in any way you like, but please leave reference to www.mischianti.org in your comments if you redistribute this code. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords micropython digital i2c encoder expander pcf8574 pcf8574a esp32 esp8266 stm32 samd arduino wire rp2040 raspberry
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div>
<a href="https://www.mischianti.org/forums/forum/mischiantis-libraries/pcf8574-i2c-digital-i-o-expander/"><img
  src="https://github.com/xreef/LoRa_E32_Series_Library/raw/master/resources/buttonSupportForumEnglish.png" alt="Support forum pcf8574 English"
   align="right"></a>
</div>
<div>
<a href="https://www.mischianti.org/it/forums/forum/le-librerie-di-mischianti/pcf8574-expander-digitale-i-o-i2c/"><img
  src="https://github.com/xreef/LoRa_E32_Series_Library/raw/master/resources/buttonSupportForumItaliano.png" alt="Forum supporto pcf8574 italiano"
  align="right"></a>
</div>

#
#### www.mischianti.org

# PCF8574 PCF8574AP digital input and output expander with i2c bus.

## Changelog
 - 18/04/2023: v0.0.2 Add static declaration for Px constants inside class.
 - 14/04/2023: v0.0.1 Initial commit of stable version.

I try to simplify the use of this IC, with a minimal set of operations.

Tested with esp8266, esp32, Arduino, Arduino SAMD (Nano 33 IoT, MKR etc.), STM32 and rp2040 (Raspberry Pi Pico and similar)

PCF8574P address map 0x20-0x27 
PCF8574AP address map 0x38-0x3f 

### Installation
To install the library execute the following command:

```bash
pip install pcf8574-library
```

**Constructor:**
Pass the address of I2C 
```python
    from PCF8574 import PCF8574
    
    pcf = PCF8574(0x38, sda=21, scl=22)
```
To use interrupt you must pass the interrupt pin and the function to call when interrupt raised from PCF8574
```python
    from PCF8574 import PCF8574
    
    def keyPressedOnPCF8574(pin):
        # Interrupt called (No Serial no read no wire in this function, and DEBUG disabled on PCF library)
        keyPressed = True
    
    pcf = PCF8574(0x38, sda=21, scl=22, interrupt_callback=keyPressedOnPCF8574, interrupt_pin=18)
```

You must set input/output mode:
```python
    from machine import Pin
    from PCF8574 import PCF8574

    pcf.Pin(PCF8574.P0, Pin.IN)
    pcf.Pin(PCF8574.P1, Pin.IN, Pin.PULL_UP)
    pcf.Pin(PCF8574.P2, Pin.IN)
    pcf.Pin(PCF8574.P3, Pin.IN)
    
    pcf.Pin(PCF8574.P7, Pin.OUT)
    pcf.Pin(PCF8574.P6, Pin.OUT, 1)
    pcf.Pin(PCF8574.P5, Pin.OUT, 0)
    pcf.Pin(PCF8574.P4, Pin.OUT, 0)
```

then IC as you can see in the image has 8 digital input/output ports:

![PCF8574 schema](https://github.com/xreef/PCF8574_library/raw/master/resources/PCF8574-pins.gif)

To 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):
```python
    digital_input = pcf.digital_read_all()
    
    print(digital_input.p0)
    print(digital_input.p1)
    print(digital_input.p2)
    print(digital_input.p3)
    print(digital_input.p4)
    print(digital_input.p5)
    print(digital_input.p6)
    print(digital_input.p7)
    
    array_input = pcf.digital_read_all_array()
    print(array_input)
    
    byte_input = pcf.digital_read_all_byte()
    print(bin(byte_input))
```

If you want to read a single input:
```python
    digital_input = pcf.digital_read(PCF8574.P1)
    print(digital_input)
```

If you want to write a digital value:
```python
    pcf.digital_write(PCF8574.P1, 1)
```

You can also use an interrupt pin:
You must initialize the pin and the function to call when interrupt raised from PCF8574
```python
    def callback(pin):
        now = utime.ticks_ms()
        global count
        count += 1
        print("Time: {} {}".format(now, count))
    
    
    pcf.attach_interrupt(18, callback)
```

For the examples I use this wire schema on breadboard:
![Breadboard](https://www.mischianti.org/wp-content/uploads/2021/04/WeMos-D1-esp8266-pcf8574-IC-wiring-schema-8-leds.jpg)
![Breadboard](https://www.mischianti.org/wp-content/uploads/2021/04/esp32-pcf8574-IC-wiring-schema-8-leds.jpg)
![Breadboard](https://www.mischianti.org/wp-content/uploads/2022/08/stm32_pcf8574_wiring_4_Led_4_Buttons_bb.jpg)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/xreef/PCF8574_micropython_library",
    "name": "pcf8574-library",
    "maintainer": "Renzo Mischianti",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "Renzo Mischianti <renzo@mischianti.org>",
    "keywords": "micropython,digital,i2c,encoder,expander,pcf8574,pcf8574a,esp32,esp8266,stm32,SAMD,Arduino,wire,rp2040,Raspberry",
    "author": "Renzo Mischianti",
    "author_email": "Renzo Mischianti <renzo@mischianti.org>",
    "download_url": "https://files.pythonhosted.org/packages/81/66/a3a38c84a032d722406d7b4a7e23ac88214e63a56399291804e7be00f674/pcf8574-library-0.0.2.tar.gz",
    "platform": null,
    "description": "<div>\r\n<a href=\"https://www.mischianti.org/forums/forum/mischiantis-libraries/pcf8574-i2c-digital-i-o-expander/\"><img\r\n  src=\"https://github.com/xreef/LoRa_E32_Series_Library/raw/master/resources/buttonSupportForumEnglish.png\" alt=\"Support forum pcf8574 English\"\r\n   align=\"right\"></a>\r\n</div>\r\n<div>\r\n<a href=\"https://www.mischianti.org/it/forums/forum/le-librerie-di-mischianti/pcf8574-expander-digitale-i-o-i2c/\"><img\r\n  src=\"https://github.com/xreef/LoRa_E32_Series_Library/raw/master/resources/buttonSupportForumItaliano.png\" alt=\"Forum supporto pcf8574 italiano\"\r\n  align=\"right\"></a>\r\n</div>\r\n\r\n#\r\n#### www.mischianti.org\r\n\r\n# PCF8574 PCF8574AP digital input and output expander with i2c bus.\r\n\r\n## Changelog\r\n - 18/04/2023: v0.0.2 Add static declaration for Px constants inside class.\r\n - 14/04/2023: v0.0.1 Initial commit of stable version.\r\n\r\nI try to simplify the use of this IC, with a minimal set of operations.\r\n\r\nTested with esp8266, esp32, Arduino, Arduino SAMD (Nano 33 IoT, MKR etc.), STM32 and rp2040 (Raspberry Pi Pico and similar)\r\n\r\nPCF8574P address map 0x20-0x27 \r\nPCF8574AP address map 0x38-0x3f \r\n\r\n### Installation\r\nTo install the library execute the following command:\r\n\r\n```bash\r\npip install pcf8574-library\r\n```\r\n\r\n**Constructor:**\r\nPass the address of I2C \r\n```python\r\n    from PCF8574 import PCF8574\r\n    \r\n    pcf = PCF8574(0x38, sda=21, scl=22)\r\n```\r\nTo use interrupt you must pass the interrupt pin and the function to call when interrupt raised from PCF8574\r\n```python\r\n    from PCF8574 import PCF8574\r\n    \r\n    def keyPressedOnPCF8574(pin):\r\n        # Interrupt called (No Serial no read no wire in this function, and DEBUG disabled on PCF library)\r\n        keyPressed = True\r\n    \r\n    pcf = PCF8574(0x38, sda=21, scl=22, interrupt_callback=keyPressedOnPCF8574, interrupt_pin=18)\r\n```\r\n\r\nYou must set input/output mode:\r\n```python\r\n    from machine import Pin\r\n    from PCF8574 import PCF8574\r\n\r\n    pcf.Pin(PCF8574.P0, Pin.IN)\r\n    pcf.Pin(PCF8574.P1, Pin.IN, Pin.PULL_UP)\r\n    pcf.Pin(PCF8574.P2, Pin.IN)\r\n    pcf.Pin(PCF8574.P3, Pin.IN)\r\n    \r\n    pcf.Pin(PCF8574.P7, Pin.OUT)\r\n    pcf.Pin(PCF8574.P6, Pin.OUT, 1)\r\n    pcf.Pin(PCF8574.P5, Pin.OUT, 0)\r\n    pcf.Pin(PCF8574.P4, Pin.OUT, 0)\r\n```\r\n\r\nthen IC as you can see in the image has 8 digital input/output ports:\r\n\r\n![PCF8574 schema](https://github.com/xreef/PCF8574_library/raw/master/resources/PCF8574-pins.gif)\r\n\r\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):\r\n```python\r\n    digital_input = pcf.digital_read_all()\r\n    \r\n    print(digital_input.p0)\r\n    print(digital_input.p1)\r\n    print(digital_input.p2)\r\n    print(digital_input.p3)\r\n    print(digital_input.p4)\r\n    print(digital_input.p5)\r\n    print(digital_input.p6)\r\n    print(digital_input.p7)\r\n    \r\n    array_input = pcf.digital_read_all_array()\r\n    print(array_input)\r\n    \r\n    byte_input = pcf.digital_read_all_byte()\r\n    print(bin(byte_input))\r\n```\r\n\r\nIf you want to read a single input:\r\n```python\r\n    digital_input = pcf.digital_read(PCF8574.P1)\r\n    print(digital_input)\r\n```\r\n\r\nIf you want to write a digital value:\r\n```python\r\n    pcf.digital_write(PCF8574.P1, 1)\r\n```\r\n\r\nYou can also use an interrupt pin:\r\nYou must initialize the pin and the function to call when interrupt raised from PCF8574\r\n```python\r\n    def callback(pin):\r\n        now = utime.ticks_ms()\r\n        global count\r\n        count += 1\r\n        print(\"Time: {} {}\".format(now, count))\r\n    \r\n    \r\n    pcf.attach_interrupt(18, callback)\r\n```\r\n\r\nFor the examples I use this wire schema on breadboard:\r\n![Breadboard](https://www.mischianti.org/wp-content/uploads/2021/04/WeMos-D1-esp8266-pcf8574-IC-wiring-schema-8-leds.jpg)\r\n![Breadboard](https://www.mischianti.org/wp-content/uploads/2021/04/esp32-pcf8574-IC-wiring-schema-8-leds.jpg)\r\n![Breadboard](https://www.mischianti.org/wp-content/uploads/2022/08/stm32_pcf8574_wiring_4_Led_4_Buttons_bb.jpg)\r\n\r\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2017 Renzo Mischianti www.mischianti.org All right reserved.  You may copy, alter and reuse this code in any way you like, but please leave reference to www.mischianti.org in your comments if you redistribute this code.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Most starred 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",
    "version": "0.0.2",
    "split_keywords": [
        "micropython",
        "digital",
        "i2c",
        "encoder",
        "expander",
        "pcf8574",
        "pcf8574a",
        "esp32",
        "esp8266",
        "stm32",
        "samd",
        "arduino",
        "wire",
        "rp2040",
        "raspberry"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a5234d45306a238bbc7dd3cbabd625a1eb7f67b30486910a41153915b8fcf614",
                "md5": "6206a99d5a6a013fc525e07455c14c79",
                "sha256": "d6eb6f1f61b15430b4383daf40c4222f26ff743b73431dd5b9bebf4a3788e23e"
            },
            "downloads": -1,
            "filename": "pcf8574_library-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6206a99d5a6a013fc525e07455c14c79",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8921,
            "upload_time": "2023-04-18T20:37:33",
            "upload_time_iso_8601": "2023-04-18T20:37:33.290911Z",
            "url": "https://files.pythonhosted.org/packages/a5/23/4d45306a238bbc7dd3cbabd625a1eb7f67b30486910a41153915b8fcf614/pcf8574_library-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8166a3a38c84a032d722406d7b4a7e23ac88214e63a56399291804e7be00f674",
                "md5": "b1b3533be6075e3c887140316882078b",
                "sha256": "e2604a1f01de37bfdb7f3d16c9a23901acb1fea4a91e712e7ea8010104eab8df"
            },
            "downloads": -1,
            "filename": "pcf8574-library-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "b1b3533be6075e3c887140316882078b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9528,
            "upload_time": "2023-04-18T20:37:35",
            "upload_time_iso_8601": "2023-04-18T20:37:35.912899Z",
            "url": "https://files.pythonhosted.org/packages/81/66/a3a38c84a032d722406d7b4a7e23ac88214e63a56399291804e7be00f674/pcf8574-library-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-18 20:37:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "xreef",
    "github_project": "PCF8574_micropython_library",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pcf8574-library"
}
        
Elapsed time: 1.03119s