Robert Rau's 1-Wire Keyboard Calculator Takes the Hard Work Out of Analog Keypad Design
Just fill in the blanks and see exactly what resistors you need for a given analog keyboard — and even receive C code to make it work.
Electronic designer and engineer Robert Rau has put together a handy tool for when you need to design a keyboard but only have one pin remaining on your microcontroller — by calculating what resistors you'd need to have uniquely-identifiable keypresses on an analog input, and even generating the code you'll need for it.
"1-Wire Keyboard (or analog keyboard) Calculator is a tool for embedded system designers to implement a keyboard or keypad using a single analog-to-digital converter (A/D) input," Rau explains of his creation, brought to our attention by Adafruit. "For larger keyboards, or keypads that require chording (more than one key pressed at a time) multiple A/D inputs can be used, each with a portion of your complete keypad."
While a naive keypad implementation would use a digital pin for every key and a more sensible implementation would use a matrix to reduce the number of pins required, an analogue keypad reduces things to a single wire — using a matrix of resistors to ensure a unique voltage output depending on which key on the pad is pressed. The only trouble: figuring out what values of resistors you need in order to ensure that a given input is indeed unique, to a level recognizable by your microcontroller's analog input.
That's where Rau's tool comes in. Fill in a few blanks — like how many columns and rows your keypad will have, the accuracy and resolution of your microcontroller's analog to digital converter, and even the contact resistance of the switches used — and the calculator will tell you exactly what values of resistor you need to put where. For larger keyboards, or where simultaneous keypresses are desired, the tool can even accommodate multiple analog inputs — splitting the keys between them.
"1-Wire Keyboard supports from two to 64 key keyboards; however, keyboards beyond 26 keys may be hard to realize with a single A/D input and low cost resistors," Rau notes. "For keyboards with many keys you may see some pink highlighted keys. When A/D inaccuracy and resistors conspire against you, and some keys’ A/D ranges of a key overlap the A/D range of another key, those keys are highlighted in pink."
In its most recent release, Rau's calculator has gained another useful tool: the ability to generate C code to go with the hardware design. "After you have named your keys and optimized your key placement and resistors, you can generate a C function to decode your keyboard," Rau writes. "Testing is still on-going. Please give me feedback if you have used this feature and if it worked for you."
The tool, and a detailed explanation of its operation, is available on Rau's website.