Button Pad Hookup Guide

Pages
Contributors: Byron J.
Favorited Favorite 15

Extra Credit

Through this guide, we've intentionally kept things simple, to demonstrate the matrix scanning concepts. We've only scratched the surface of the permutations of matrix scanning.

There are a lot of other variations on these ideas to consider, but we're leaving them as exercises for the reader.

More Colors

As we discussed in the previous section, we're only lighting the red, green or blue section of each LED individually, to keep current consumption low. When the author was developing exercise #4, the initial implementation allowed for the RGB LEDs to be on in any combination. The end result was that if too many LEDs were lit simultaneously, they got dim, and the processor heated up. Ultimately, the exercise was revised to only use single colors.

If we want to light more than one section at a time, we can mix them to create other colors, but to do that, we'll need to source and sink additional current. One solution is to add current limiting resistors in series with each LED Anode, and buffer the signal with high-current line drivers.

If you're really clever, you can use pulse-width modulation to vary the LED brightness, for an even wider range of colors.

Code Optimizations

The sketches in the exercises were written to be portable. They use the Arduino pin definitions, and digitalRead, and digitalWrite functions, which makes them easy to move to other systems. For instance, you could move this code to a Teensy 3.2 by adjusting the pin numbers in the row and column arrays. But this means handling those individual bits one at a time.

Most microcontrollers define the port pins as adjacent bits in byte or word wide registers. If you're working with those registers, you can arrange the matrix to gang the digital I/O using byte and word reads and writes. It's just not as easy to move to a different microcontroller!

As an even more optimized keypad scan can take advantage of external pin interruts. The scanning is idle until a key is pressed. The key triggers an interrupt, which performs a single scan to determine which key is pressed. When all keys are released, the system idles again.

Bigger and Better

We can combine multiple keypads into a larger matrix by joining the adjacent rows and columns.

Offload The Keypad Scanning

There are peripheral chips that can do the button and LED scanning. The SX1509 I/O expander has a mode that allows it to scan an 8x8 key matrix, and interrupt the host when a key press is detected.

SparkFun 16 Output I/O Expander Breakout - SX1509

SparkFun 16 Output I/O Expander Breakout - SX1509

BOB-13601
$6.95
11

The 2x2 button Pad

The 4x4 button pad has a little brother, the 2X2 button pad, that pairs with a matching PCB. If you're building a 2x2 button pad, you'll need a single top bezel to hold it together.

The circuit of the 2x2 button pad is actually set up like a single row of the 4x4 pad, and could be added to the same scan matrix.