From b46a4a7c7e3a697fb1240260b098ec5aab1c6ad2 Mon Sep 17 00:00:00 2001 From: Pat Beirne Date: Mon, 9 Dec 2024 13:02:32 -0500 Subject: [PATCH] changed all the internal links/anchors --- keypad_to_microcontroller.md | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/keypad_to_microcontroller.md b/keypad_to_microcontroller.md index 96dbb0f..b030b65 100644 --- a/keypad_to_microcontroller.md +++ b/keypad_to_microcontroller.md @@ -1,10 +1,10 @@ # Keypad Scanning -There's a dozen ways to connect a keyboard to a microcontroller, and this paper attempts to enumerate many of them. [test link](#one-per-pin) -There are similar articles on the internet [[see below](#ext_ref)], -but this paper introduces some new techniques: [row-grounded](#3x4-plus-ground-[new-design]), -[row-grounded-with-diodes](#3x4diodes), -[row-grounded-with-4-diodes](#3x4double_diodes) +There's a dozen ways to connect a keyboard to a microcontroller, and this paper attempts to enumerate many of them. +There are similar articles on the internet [[see below](#external-references)], +but this paper introduces some new techniques: [row-grounded](#3x4-plus-ground-new-design), +[row-grounded-with-diodes](#3x4-plus-ground-and-2-diodes-new-design), +[row-grounded-with-4-diodes](#3x4-plus-ground-and-4-diodes-new-design) Some articles focus on a full-function, unambiguous keyboard, where multiple key-presses can be detected. Something @@ -23,7 +23,7 @@ In this document, *n* refers to the number of keys that are in the keyboard. The that is being pressed during an explanation. -## One per Pin +## One per Pin The simplest way to connect keys to a microcontroller is one key to one pin. Connect the other side of the key to ground. @@ -40,7 +40,7 @@ This configuration has a few advantages: - there is no keyboard scan....which helps keep scan-noise out of the power supply; helpful in an audio environment - can easily be set to wake-on-interrupt, which means that you can power down between keystrokes -See [KeyBounce](#bounce) below. +See [KeyBounce](#keyboard-bounce) below. Of course, this solution does not apply to a keyboard which has *rows* and *columns*. @@ -56,7 +56,6 @@ microcontrollers have an A/D converter, and that can be used to determine which A naive approach would be to simply use equal-valued resistors, and then each tap would be *k*/(*n*+1) of the supply voltage. - ### 3x4 Chain Sometimes a keyboard will be pre-wired as a grid, so you don't have access to the individual keys. You can still use @@ -109,7 +108,7 @@ See also [this article](https://github.com/sgmne/AnalogKeypad) ## Scanning -### 3x4 Scanning +### 3x4 Scanning The simplest connection of a 3x4 keyboard is to simply use 7 GPIO pins, 4 for the rows, and 3 for the columns. Enable input & pullups on the columns and rows. At scan time, assert each row pin, one at a time, as a low, and measure @@ -136,10 +135,10 @@ This scheme can be configured for interrupt triggering columns are set to input+pullup+interrupt. Any keypress will then pull at least one column line low. Once the interrupt is triggered, change to the logic described above, scan the keyboard -[over the [debounce period](#bounce) and then restore they keyboard +[over the [debounce period](#keyboard-bounce) and then restore they keyboard to the "ready-for-interrupt" configuration. -### 3x4 plus Ground [new design] +### 3x4 plus Ground [new design] If you are really tight on pins, you can ground one of the rows and still get a functioning keyboard. @@ -161,7 +160,6 @@ The resulting 4 groups of 3 bits indicate the state of the keyboard; 1=open, 0=k Again, the same logic will allow you to manage a 4x4 keyboard with 7 GPIO pins. - ### 3x4 plus Ground and 2 Diodes [new design] Again, we can scrape off one more GPIO if we can add a pair of diodes to the row pins. @@ -215,7 +213,6 @@ look for the symbol **FIVE_PIN**. This configuration is also interrupt-capable, by setting the row drivers to output-low, and the columns as input+pullup+interrupt. - ### 3x4 plus Ground and 4 Diodes [new design] As an extreme, you can decode a 3x4 keypad with only 4 GPIO pins, @@ -268,7 +265,7 @@ can happen. look for the symbol **FOUR_PIN**. Here is a working prototype. ![working](keypad.jpg) -### Keyboard Debounce +### Keyboard Debounce When a key is pressed, there is a short time during closure when the physical elements almost-touch, and the @@ -301,8 +298,12 @@ One involves using an SPI output and a shift register This design requires an external chip ($0.10), 8 diodes and 4 resistors. +### Interrupts -### Reading DIP switches + + + +### Reading DIP switches In some situations, it's helpful to read an array of DIP switches, perhaps to read a configuration at power-on. In this case, @@ -325,7 +326,7 @@ and it's impossible to determine if the "5" key is pressed or not. Diodes are required at each junction to disambiguate. -### External keyboard processor +### External keyboard processor With the current cost of processors, consider adding an external coprocessor to your project. @@ -364,7 +365,7 @@ It's U$0.11, 16k flash, 2k ram, 6gpio, sop8. | scan with diodes | 6 for 4x4, 5 for 3x4 | 1 | 2 diodes | | scan with 4 diodes | 5 for 4x4, 4 for 3x4 | 1 | 4 diodes | -### External References +### External References An excellent overview of keyboard scanning directly from a microcontroller.