{"id":13894211,"url":"https://github.com/RobTillaart/I2CKeyPad","last_synced_at":"2025-07-17T09:31:16.429Z","repository":{"id":37590245,"uuid":"275163251","full_name":"RobTillaart/I2CKeyPad","owner":"RobTillaart","description":"Arduino library for 4x4 (or smaller) keypad connected to an I2C PCF8574.","archived":false,"fork":false,"pushed_at":"2024-08-19T10:37:34.000Z","size":53,"stargazers_count":57,"open_issues_count":0,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-19T06:33:06.759Z","etag":null,"topics":["arduino","i2c","keypad","pcf8574"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobTillaart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"RobTillaart","custom":"https://www.paypal.me/robtillaart"}},"created_at":"2020-06-26T13:31:27.000Z","updated_at":"2024-11-11T12:52:24.000Z","dependencies_parsed_at":"2024-04-13T10:22:56.759Z","dependency_job_id":"0178eccc-4550-4ff4-a0a8-6b9e9a2a19fd","html_url":"https://github.com/RobTillaart/I2CKeyPad","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FI2CKeyPad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FI2CKeyPad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FI2CKeyPad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FI2CKeyPad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobTillaart","download_url":"https://codeload.github.com/RobTillaart/I2CKeyPad/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226248201,"owners_count":17595158,"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","i2c","keypad","pcf8574"],"created_at":"2024-08-06T18:01:26.567Z","updated_at":"2024-11-24T23:30:17.580Z","avatar_url":"https://github.com/RobTillaart.png","language":"C++","funding_links":["https://github.com/sponsors/RobTillaart","https://www.paypal.me/robtillaart"],"categories":["C++"],"sub_categories":[],"readme":"\n[![Arduino CI](https://github.com/RobTillaart/I2CKeyPad/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)\n[![Arduino-lint](https://github.com/RobTillaart/I2CKeyPad/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/I2CKeyPad/actions/workflows/arduino-lint.yml)\n[![JSON check](https://github.com/RobTillaart/I2CKeyPad/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/I2CKeyPad/actions/workflows/jsoncheck.yml)\n[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/I2CKeyPad.svg)](https://github.com/RobTillaart/I2CKeyPad/issues)\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/I2CKeyPad/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/RobTillaart/I2CKeyPad.svg?maxAge=3600)](https://github.com/RobTillaart/I2CKeyPad/releases)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/I2CKeyPad.svg)](https://registry.platformio.org/libraries/robtillaart/I2CKeyPad)\n\n\n# I2CKeyPad\n\nArduino library for 4x4 (or smaller) keypad connected to an I2C PCF8574.\n\n\n## Description\n\nThe I2CKeyPad library implements the reading of a 4x4 keypad by means of a PCF8574.\nSmaller keypads, meaning less columns or rows (4x3) can be read with it too.\n\nSince 0.3.2 the library allows a 5x3, 6x2 or 8x1 or smaller keypad to be connected too.\n\n### Breaking change\n\nSince 0.5.0 the library can set a debounce threshold. \nIf this is set (\u003e 0) the **getKey()** and **getChar()** functions \ncan return **I2C_KEYPAD_THRESHOLD** (255).\n\n\n### Related\n\nRelates strongly to https://github.com/RobTillaart/I2CKeyPad8x8. which is an 8x8 version using **PCF8575**.\n\n- https://github.com/RobTillaart/PCF8574\n- https://github.com/RobTillaart/AnalogKeypad\n- https://github.com/RobTillaart/I2CKeyPad4x4\n- https://github.com/RobTillaart/I2CKeyPad8x8\n- https://github.com/WK-Software56/AdvKeyPad (derived work with keyboard alike interface)\n\n\n## Connection\n\nThe PCF8574 is connected between the processor and the (default) 4x4 keypad.\nSee the conceptual schema below. \nIt might take some trying to get the correct pins connected.\n\n```\n          PROC             PCF8574               KEYPAD\n        +--------+        +---------+          +---------+\n        |        |        |       0 |\u003c--------\u003e| R       |\n        |    SDA |\u003c------\u003e|       1 |\u003c--------\u003e| O       |\n        |    SCL |-------\u003e|       2 |\u003c--------\u003e| W       |\n        |        |        |       3 |\u003c--------\u003e| S       |\n        |        |        |         |          |         |\n        |        |        |       4 |\u003c--------\u003e| C       |\n        |        |        |       5 |\u003c--------\u003e| O       |\n        |        |        |       6 |\u003c--------\u003e| L       |\n        |        |        |       7 |\u003c--------\u003e| S       |\n        +--------+        +---------+          +---------+ \n```\n\n\n## I2C\n\n### I2C addresses\n\nThis library uses a PCF8574 or a PCF8574A chip.\nThese devices are identical in behaviour although there are two distinct address ranges.\n\n|  Type      |  Address-range  |  Notes                    |\n|:-----------|:---------------:|:-------------------------:|\n|  PCF8574   |  0x20 to 0x27   |  same range as PCF8575 !  |\n|  PCF8574A  |  0x38 to 0x3F   |\n\nBe careful to select an unique I2C address for every device on the bus.\n\n\n### I2C multiplexing\n\nSometimes you need to control more devices than possible with the default\naddress range the device provides.\nThis is possible with an I2C multiplexer e.g. TCA9548 which creates up\nto eight channels (think of it as I2C subnets) which can use the complete\naddress range of the device.\n\nDrawback of using a multiplexer is that it takes more administration in\nyour code e.g. which device is on which channel.\nThis will slow down the access, which must be taken into account when\ndeciding which devices are on which channel.\nAlso note that switching between channels will slow down other devices\ntoo if they are behind the multiplexer.\n\n- https://github.com/RobTillaart/TCA9548\n\n\n## Interface\n\n```cpp\n#include \"I2CKeyPad.h\"\n```\n\n### Base\n\n- **I2CKeyPad(const uint8_t deviceAddress, TwoWire \\*wire = \u0026Wire)** \nThe constructor sets the device address and optionally \nallows to selects the I2C bus to use.\n- **bool begin()** The return value shows if the PCF8574 with the given address is connected properly.\nCall wire.begin() first!\n- **bool isConnected()** returns false if the PCF8574 cannot be connected to.\n- **uint8_t getKey()** Returns default 0..15 for regular keys, \nReturns **I2C_KEYPAD_NOKEY** (16) if no key is pressed and **I2C_KEYPAD_FAIL**\n(17) in case of an error, e.g. multiple keys pressed.\nIf a debounce delay is set, it might return **I2C_KEYPAD_THRESHOLD** if called too fast.\n- **uint8_t getLastKey()** Returns the last **valid** key pressed 0..15, \nor **I2C_KEYPAD_NOKEY** (16) which is also the initial value.\n- **bool isPressed()** Returns true if one or more keys of the keyPad are pressed, \nhowever there is no check if multiple keys are pressed.\n\n\n### Mode functions\n\n**Experimental**\n\n- **void setKeyPadMode(uint8_t mode = I2C_KEYPAD_4x4)** sets the mode, default 4x4.\nThis mode can also be used for 4x3 or 4x2 or 3x3 etc. \nInvalid values for mode are mapped to 4x4.\n- **uint8_t getKeyPadMode()** returns the current mode.\n\n**Supported modi**\n\nThere are 4 modi supported, and every mode will also support smaller keypads.\nE.g. a 4x3 keypad can be read in mode 4x4 or in mode 5x3.\n\n|  modi  |  value  |  definition      |  notes    |\n|:------:|:-------:|:-----------------|:----------|\n|  4x4   |    44   |  I2C_KEYPAD_4x4  |  default, also for 4x3 4x2 4x1 3x3 3x2 3x1 etc.\n|  5x3   |    53   |  I2C_KEYPAD_5x3  |  also for 5x2 or 5x1 etc.\n|  6x2   |    62   |  I2C_KEYPAD_6x2  |  also for 6x1 etc.\n|  8x1   |    81   |  I2C_KEYPAD_8x1  |  not real matrix, connect pins to switch to GND.\n\n\n### KeyMap functions\n\nNote: **loadKeyMap()** must be called before **getChar()** and **getLastChar()**!\n\n- **char getChar()** returns the char corresponding to mapped key pressed.\nIt returns **I2C_KEYPAD_THRESHOLD** if called too fast.\n- **char getLastChar()** returns the last char pressed.\nThis function is not affected by the debounce threshold.\n- **bool loadKeyMap(char \\* keyMap)** keyMap should point to a (global) char array of length 19.\nThis array maps index 0..15 on a char and index \\[16\\] maps to **I2CKEYPAD_NOKEY** (typical 'N') \nand index \\[17\\] maps **I2CKEYPAD_FAIL** (typical 'F'). index 18 is the null char.\n\n**WARNING**\n\nIf there is no key map loaded the user should **NOT** call **getChar()** or \n**getLastChar()** as these would return meaningless bytes.\n\n\n```cpp\nchar normal_keymap[19]  = \"123A456B789C*0#DNF\";   // typical normal key map (phone layout)\nchar repeat_keymap[19]  = \"1234123412341234NF\";   // effectively 4 identical columns\nchar partial_keymap[19] = \"1234            NF\";   // top row\nchar diag_keymap[19]    = \"1    2    3    4NF\";   // diagonal keys only\n```\n\nIn the examples above a 'space' key might be just meant to ignore.\nHowever functionality there is no limit how one wants to use the key mapping.\nIt is even possible to change the mapping runtime after each key.\n\nNote: a keyMap char array may be longer than 18 characters, but only the first 18 are used.\nThe length is **NOT** checked upon loading.\n\nNote: The 5x3, 6x2 and the 8x1 modi also uses a key map of length 18.\n\n\n### Debouncing threshold\n\n**Experimental**\n\nSince version 0.5.0, the library implements an experimental debounce threshold\nwhich is non-blocking.\n\nIf a key bounces, it can trigger multiple interrupts, while the purpose is to\nact like only one keypress. The debounce threshold results in a fast return \nof **getKey()** (with **I2C_KEYPAD_THRESHOLD**) if called too fast.\n\nThe default value of the debounce threshold is zero to be backwards compatible.\nThe value is set in milliseconds, with a maximum of 65535 ==\u003e about 65 seconds or 1 minute.\nA value of 1 still allows ~1000 **getKey()** calls per second (in theory).\nA value of 65535 can be used e.g. for a delay after entering a wrong key code / password.\nSetting a high value might result in missed keypresses so use with care.\n\nThe default value of the debounce threshold is zero to be backwards compatible.\n\n- **void setDebounceThreshold(uint16_t value = 0)** set the debounce threshold,\nvalue in milliseconds, max 65535.\nThe default value is zero, to reset its value.\n- **uint16_t getDebounceThreshold()** returns the set debounce threshold.\n- **uint32_t getLastTimeRead()** returns the time stamp of the last valid read key\n(or NOKEY). This variable is used for the debounce, and may be used for other\npurposes too. E.g. track time between keypresses.\n\nIf a debounce threshold is set, and **getKey()** or **getChar()** is called too fast,\nthese functions will return **I2C_KEYPAD_THRESHOLD** (255).\n\nFeedback welcome!\n\n\n### Basic working\n\nAfter the **keypad.begin()** the sketch calls the **keyPad.getKey()** to read values from the keypad. \n- If no key is pressed **I2C_KEYPAD_NOKEY** code (16) is returned.\n- If the read value is not valid, e.g. two keys pressed, **I2C_KEYPAD_FAIL** code (17) is returned.\n- If a debounce threshold is set, **I2C_KEYPAD_THRESHOLD** might be returned.\nSee section above.\n- Otherwise a number 0..15 is returned.\n\nNote NOKEY and FAIL both have bit 4 set, all valid keys don't.\nThis allows fast checking for valid keys.\n\nOnly if a key map is loaded, the user can call **getChar()** and **getLastChar()** to get mapped keys.\n\n\n## Interrupts\n\nThe library enables the PCF8574 to generate interrupts on the PCF8574 when a key is pressed. \nThis makes checking the keypad far more efficient as one does not need to poll the device over I2C.\nSee examples.\n\n\n## Future\n\n#### Must\n\n- update documentation\n\n#### Should\n\n- test extensively\n  - basic working (OK)\n  - interrupts\n  - keymapping\n  - performance\n- improve error handling?\n  - **I2C_KEYPAD_ERR_MODE**\n\n#### Could\n\n#### Wont\n\n\n## Support\n\nIf you appreciate my libraries, you can support the development and maintenance.\nImprove the quality of the libraries by providing issues and Pull Requests, or\ndonate through PayPal or GitHub sponsors.\n\nThank you,\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobTillaart%2FI2CKeyPad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRobTillaart%2FI2CKeyPad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRobTillaart%2FI2CKeyPad/lists"}