|
@@ -1,13 +1,8 @@
|
|
|
----
|
|
|
-title: Keyboard Scanning
|
|
|
-author: Pat Beirne <patb@pbeirne.com>
|
|
|
-date: Dec, 2024
|
|
|
-version: 1.0
|
|
|
----
|
|
|
+# Keypad Scanning
|
|
|
|
|
|
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](#ext_ref)],
|
|
|
-but this paper introduces some new techniques: [row-grounded](#3x4gnd),
|
|
|
+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)
|
|
|
|
|
@@ -27,7 +22,8 @@ Sometimes, this is appropriate if the keypad is small or in an awkward location,
|
|
|
In this document, *n* refers to the number of keys that are in the keyboard. The letter *k* refers to a specific key
|
|
|
that is being pressed during an explanation.
|
|
|
|
|
|
-## One per Pin <a name="one_per_pin" />
|
|
|
+<a name="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.
|
|
@@ -60,7 +56,8 @@ 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 <a name="3x4chain" />
|
|
|
+ <a name="3x4chain" />
|
|
|
+### 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
|
|
|
the resistor ladder to determine the key-press.
|
|
@@ -164,7 +161,8 @@ 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] <a name="3x4diodes" />
|
|
|
+<a name="3x4diodes" />
|
|
|
+### 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.
|
|
|
|
|
@@ -217,7 +215,8 @@ 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] <a name="3x4double_diodes" />
|
|
|
+<a name="3x4double_diodes" />
|
|
|
+### 3x4 plus Ground and 4 Diodes [new design]
|
|
|
|
|
|
As an extreme, you can decode a 3x4 keypad with only 4 GPIO pins,
|
|
|
using 4 external diodes.
|