I am currently trying to use my Diecimila to read a 16-key matrix keypad. The keypad is a DIY piece, right now built on perfboard with 6mm Omron tactile switches. I threw together a simple sketch just to see if I had the basic wiring right. The idea is to output to the serial interface a row and column number corresponding to the switch currently pressed.
What is actually happening is that when I press a switch, I will get one or more results, many of which are not the switch I pressed. I can also get results by holding the board, touching traces, etc., which leads me to think I am getting noise. Right now I am feeding the outputs of pins 4-7 into the columns of the matrix, and then looping through the inputs on pins 8-11 to read each row to see if any switch is pressed.
Assuming I am not missing a really silly mistake in my sketch, do I need to add some caps or pull-up(down) resistors to my switch matrix to smooth things out? Or maybe I am missing a fundamental design thing here? I know my way around code and can follow a schematic OK but design from scratch I am a relative newbie... any help appreciated!
Oh, and yes, I did beep the board to make sure the wiring is basically sound... :
Yes, sounds like you might be fighting 'floating inputs' due to lack of proper pull-down resistors. You could change your logic around and use active low outputs to scan the keypad and then just enable the internal pull-up resistors for the digital input pins.
No, no diodes. I don't have an easy way to attach an image of my schematic right now, but it's simply an LED matrix with switches instead of LEDs. Instead of driving a row high and a column low, I'm driving a row high and then looping through the columns to find if I see a high on any of them. Too naive, perhaps.
In reading the replies, I am seeing that in addition to noise, I am probably suffering from a fundamental design flaw. Does anyone have a link to a good example schematic I could borrow from? Everything I found was dealing with how to read a matrix keypad that was already built. I need a custom keypad configuration so I can't use an off-the-shelf unit.
yes you will never cope with more than one switch being pressed at a time. If you have two pressed you will see four being pressed, this is known as ghosting.