{"id":13613462,"url":"https://github.com/whyisitworking/MCP23017-ESP8266-Miniature-Driver","last_synced_at":"2025-04-13T15:33:12.384Z","repository":{"id":89402313,"uuid":"82542965","full_name":"whyisitworking/MCP23017-ESP8266-Miniature-Driver","owner":"whyisitworking","description":"A simple driver for ESP8266 enthusiasts out there to drive MCP23017 16-bit IO Expander","archived":false,"fork":false,"pushed_at":"2017-02-21T08:40:05.000Z","size":47,"stargazers_count":12,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T03:32:34.477Z","etag":null,"topics":["api","driver","embedded","embedded-c","esp","esp-open-sdk","esp8266","esp8266-arduino","espressif","expander","i2c","i2c-bus","i2c-interface","i2c-sensors","mcp23017","mcp23017-esp8266","pin","switch","xtensa"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/whyisitworking.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-02-20T09:58:09.000Z","updated_at":"2023-04-24T05:09:31.000Z","dependencies_parsed_at":"2024-01-14T04:45:53.577Z","dependency_job_id":"ab5f4f32-67ff-4d8e-b3e5-8030de68edf4","html_url":"https://github.com/whyisitworking/MCP23017-ESP8266-Miniature-Driver","commit_stats":null,"previous_names":["whyisitworking/mcp23017-esp8266-miniature-driver"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whyisitworking%2FMCP23017-ESP8266-Miniature-Driver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whyisitworking%2FMCP23017-ESP8266-Miniature-Driver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whyisitworking%2FMCP23017-ESP8266-Miniature-Driver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whyisitworking%2FMCP23017-ESP8266-Miniature-Driver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whyisitworking","download_url":"https://codeload.github.com/whyisitworking/MCP23017-ESP8266-Miniature-Driver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248736197,"owners_count":21153549,"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":["api","driver","embedded","embedded-c","esp","esp-open-sdk","esp8266","esp8266-arduino","espressif","expander","i2c","i2c-bus","i2c-interface","i2c-sensors","mcp23017","mcp23017-esp8266","pin","switch","xtensa"],"created_at":"2024-08-01T20:00:47.719Z","updated_at":"2025-04-13T15:33:12.100Z","avatar_url":"https://github.com/whyisitworking.png","language":"C","funding_links":[],"categories":["精选驱动库"],"sub_categories":["功能类"],"readme":"# MCP23017 ESP8266 Miniature Driver\n\nThis is a simple MCP23017 driver for ESP8266. MCP23017 is an I/O Expander, which means it provides 16 fully customizable Input/Output pins for any microcontroller supporting I2C protocol. ESP8266 is a powerful chip, except that it lacks the I2C hardware. This library is a fully functional controller for the same. Kudos to developing in C.\n\nThe work is heavily based on [this](https://github.com/eadf/esp8266_mcp23017) library. The I2C driver is a modified port of the `i2c_master` library from the `esp-open-sdk`.\n\nUsage is pretty straightforward. No I2C library required. Easy to understand API.\n\n## Schematic\n![Schematic](https://github.com/forkachild/MCP23017-ESP8266-Driver/raw/master/schematic.png)\n\n## Customize SDA \u0026 SCL GPIO, Logging and addressing\n\n```c\n// user_config.h\n\n// Choose GPIO\n\n#define MCP_SDA_GPIO\t\t14\n#define MCP_SCL_GPIO\t\t12\n    \n// Debugging mode\n    \n#define MCP_LOG_EN\n    \n// Custom MCP23017 address\n    \n#define MCP_A0\t\t\t\t0\n#define MCP_A1\t\t\t\t0\n#define MCP_A3\t\t\t\t0\n```\n\n\n## Configuration uses a few function calls\n\n```c\n#include \"mcp.h\"\n\nmcpInit();\n\n// Set pin mode to input or output, individual bits can be ORed\n\nmcpSetPinmode(MCP_PORTA, MCP_OUTPUT);\nmcpSetPinmode(MCP_PORTB, 0x0E);\n\n// Configure internal pullups (for input modes only), individual bits can be ORed\n\nmcpSetPullups(MCP_PORTB, MCP_PULL_HIGH);\n\n// Input polarity can be changed, and yet again individual bits can be ORed\n\nmcpSetInputPolarity(MCP_PORTA, MCP_IPOL_INVERTED);\n```\n\n\n## Effortlessly control GPIO\n\n```c\nuint8 input;\n\nmcpSetGpio(MCP_PORTA, 0xF0);\nmcpGetGpio(MCP_PORTB, \u0026input);\n``` \n\n## Examples\n\n### Blinky\n\nWe all know this one\n\n```c\n// user_main.c\n\n#include \"os_type.h\"\n#include \"mcp.h\"\n\n#define LED_PIN         (1 \u003c\u003c 0)\n\nos_timer_t timer;\nbool toggle = false;\n\nLOCAL void ICACHE_FLASH_ATTR timerPoll(void *arg) {\n    if(toggle) {\n        mcpSetGpio(MCP_PORTA, LED_PIN);     // Switch on LED\n        toggle = false;\n    } else {\n        mcpSetGpio(MCP_PORTA, 0);           // Switch off LED\n        toggle = true;\n    }\n}\n\nLOCAL void ICACHE_FLASH_ATTR initDoneCb() {\n    os_timer_disarm(\u0026timer);\n    os_timer_setfn(\u0026timer, (os_timer_func_t *) timerPoll);\n    os_timer_arm(\u0026timer, 1000, true);       // Create timer\n}\n\nvoid user_init() {\n    mcpInit();                              // Init the library\n    mcpSetPinmode(MCP_PORTA, MCP_OUTPUT);   // Set full Port A as output\n    system_init_done_cb(initDoneCb);\n}\n```\n\n### Read switch to control an LED\n\nThe switch is push-to-close and connects PORTB pin 0 to ground.\n\n```c\n// user_main.c\n\n#include \"os_type.h\"\n#include \"mcp.h\"\n\n#define LED_PIN         (1 \u003c\u003c 0)\n#define SWITCH_PIN      (1 \u003c\u003c 0)\n\nos_timer_t timer;\nuint8 data;\n\nLOCAL void ICACHE_FLASH_ATTR timerPoll(void *arg) {\n    mcpGetGpio(PORTB, \u0026data);                       // Read Port B where switch is connected\n    if(data \u0026 SWITCH_PIN) {                         // Check whether switch is on\n        mcpSetGpio(MCP_PORTA, LED_PIN);             // Switch on LED\n    } else {\n        mcpSetGpio(MCP_PORTA, 0);                   // Switch off LED\n    }\n}\n\nLOCAL void ICACHE_FLASH_ATTR initDoneCb() {\n    os_timer_disarm(\u0026timer);\n    os_timer_setfn(\u0026timer, (os_timer_func_t *) timerPoll);\n    os_timer_arm(\u0026timer, 100, true);                // Create timer to poll switch\n}\n\nvoid user_init() {\n    mcpInit();                                      // Init the library\n    mcpSetPinmode(MCP_PORTA, MCP_OUTPUT);           // Set full Port A as output\n    mcpSetPinmode(MCP_PORTB, MCP_INPUT);            // Set full Port B as input\n    mcpSetPullups(MCP_PORTB, MCP_PULL_HIGH);        // Pullup Port B pins for switch to pull it down on press\n    mcpSetInputPolarity(MCP_PORTB, MCP_INVERTED);   // Polrity has to be reversed since pullup has to mean 1\n    system_init_done_cb(initDoneCb);\n}\n```\n\n### Enjoy\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhyisitworking%2FMCP23017-ESP8266-Miniature-Driver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhyisitworking%2FMCP23017-ESP8266-Miniature-Driver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhyisitworking%2FMCP23017-ESP8266-Miniature-Driver/lists"}