{"id":13802286,"url":"https://github.com/xreef/PCF8591_micropython_library","last_synced_at":"2025-05-13T13:30:34.703Z","repository":{"id":183948962,"uuid":"629698998","full_name":"xreef/PCF8591_micropython_library","owner":"xreef","description":"MicroPython Library to use pcf8591 i2c analog IC with Arduino, Raspberry Pi Pico and rp2040 boards, esp32, SMT32 and ESP8266. Can read analog value and write analog value with only 2 wire.","archived":false,"fork":false,"pushed_at":"2023-11-07T16:37:26.000Z","size":11,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-19T11:11:42.802Z","etag":null,"topics":["analog","arduino","esp32","esp8266","expander","i2c","micropython","pcf8591","raspberry","rp2040","samd","stm32","wire"],"latest_commit_sha":null,"homepage":"https://www.mischianti.org/2019/01/03/pcf8591-i2c-analog-i-o-expander/","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-18T21:08:12.000Z","updated_at":"2024-06-04T08:47:24.000Z","dependencies_parsed_at":"2024-11-14T12:38:55.307Z","dependency_job_id":"515ad079-7540-4be2-b46c-cf69354fc48c","html_url":"https://github.com/xreef/PCF8591_micropython_library","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"5f481b7496f9a817a9d8af7dd13e85471849af26"},"previous_names":["xreef/pcf8591_micropython_library"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FPCF8591_micropython_library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FPCF8591_micropython_library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FPCF8591_micropython_library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xreef%2FPCF8591_micropython_library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xreef","download_url":"https://codeload.github.com/xreef/PCF8591_micropython_library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225218006,"owners_count":17439712,"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":["analog","arduino","esp32","esp8266","expander","i2c","micropython","pcf8591","raspberry","rp2040","samd","stm32","wire"],"created_at":"2024-08-04T00:01:41.115Z","updated_at":"2024-11-18T17:31:13.921Z","avatar_url":"https://github.com/xreef.png","language":"Python","readme":"\u003cdiv\u003e\n\u003ca href=\"https://www.mischianti.org/forums/forum/mischiantis-libraries/pcf8591-i2c-analog-expander/\"\u003e\u003cimg\n  src=\"https://github.com/xreef/LoRa_E32_Series_Library/raw/master/resources/buttonSupportForumEnglish.png\" alt=\"Support forum pcf8591 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/pcf8591-expander-analogico-i2c/\"\u003e\u003cimg\n  src=\"https://github.com/xreef/LoRa_E32_Series_Library/raw/master/resources/buttonSupportForumItaliano.png\" alt=\"Forum supporto pcf8591 italiano\"\n  align=\"right\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n#\n#### www.mischianti.org\n\n### MicroPython Library to use i2c analog IC with arduino and esp8266. Can read analog value and write analog value with only 2 wire (perfect for ESP-01).\n\n#### Changelog\n - 07/11/2023: v0.0.3 Fix on read when write is active and running [#Forum](https://mischianti.org/forums/topic/micropython-i2c-pcf8591-round-value-problem-raspberry-pi-pico/#post-28043)\n - 16/05/2023: v0.0.2 Minor fix on read and write [#Forum](https://www.mischianti.org/forums/topic/micropython-i2c-pcf8591-round-value-problem-raspberry-pi-pico/)\n - 18/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 operation.\n\n#### Installation\nTo install the library execute the following command:\n\n```bash\npip install pcf8591-library\n```\n\n**Constructor:**\nPass the address of I2C \n```python\nfrom PCF8591 import PCF8591\nfrom machine import I2C, Pin\n    \n# Initialize the I2C bus\ni2c = I2C(0, scl=Pin(22), sda=Pin(21))  \n\n# Initialize the PCF8591\npcf8591 = PCF8591(0x48, i2c)\nif pcf8591.begin():\n    print(\"PCF8591 found\")\n\n```\nor\n```python\nfrom PCF8591 import PCF8591\n\npcf8591 = PCF8591(0x48, sda=21, scl=22)\nif pcf8591.begin():\n    print(\"PCF8591 found\")\n\n```\n\nTo read all analog input in one \n```python\n# Main loop\nwhile True:\n    # Read all analog input channels\n    ain0, ain1, ain2, ain3 = pcf8591.analog_read_all()\n\n    # Print the results\n    print(\"AIN0:\", ain0, \"AIN1:\", ain1, \"AIN2:\", ain2, \"AIN3:\", ain3)\n\n    # Wait for 1 second\n    utime.sleep(1)\n```\n\nIf you want to read a single input:\n```python\nprint(\"AIN0 \", pcf8591.analog_read(PCF8591.AIN0))\nprint(\"AIN1 \", pcf8591.analog_read(PCF8591.AIN1))\nprint(\"AIN2 \", pcf8591.analog_read(PCF8591.AIN2))\nprint(\"AIN3 \", pcf8591.analog_read(PCF8591.AIN3))\n```\n\nIf you want to write a value:\n```python\npcf8591.analog_write(255)\nutime.sleep(1)\npcf8591.analog_write(128)\nutime.sleep(1)\npcf8591.analog_write(0)\n```\n\nYou can also read and write voltage\n\n```python\npcf8591.voltage_write(3.3)\nutime.sleep(1)\npcf8591.voltage_write(1.65)\nutime.sleep(1)\npcf8591.voltage_write(0)\n```\nor\n```python\nprint(\"AIN0 \", pcf8591.voltage_read(PCF8591.AIN0))\nprint(\"AIN1 \", pcf8591.voltage_read(PCF8591.AIN1))\nprint(\"AIN2 \", pcf8591.voltage_read(PCF8591.AIN2))\nprint(\"AIN3 \", pcf8591.voltage_read(PCF8591.AIN3))\n```\n\n\nFor the examples I use this wire schema on breadboard:\n![esp32 and pcf8591 wiring](https://www.mischianti.org/wp-content/uploads/2023/04/esp32-pcf8591-wiring_bb.jpg)","funding_links":[],"categories":["Libraries"],"sub_categories":["IO"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxreef%2FPCF8591_micropython_library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxreef%2FPCF8591_micropython_library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxreef%2FPCF8591_micropython_library/lists"}