Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

ANALOG INPUTS TO INTERFACE 3X4 KEYPAD
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ANALOG INPUTS TO INTERFACE 3X4 KEYPAD

by 123Splat on Mon Sep 05, 2011 7:52 pm

This is probablly a really stupid idea, but it looked good on paper.... I thought that I could reduce the number of input pins required to interface a 3X4 key pad by: 1) build a resistor ladder with five 3.9k resistors in series. 2) connect one end of the ladder to +5V and the other end to GND. 3) connect each of the keypad row pins (keypad p2, p7,p6, p4) to a unique node in the ladder. 4) connect the three collumn leads (keypad p3,p1,p5) to analog inputs (UNO pins A1,A2,A3) of the UNO. 5) analog read the input (keypad col) pins to detect a unique row voltage on a col pin to decode that a pin on row x col y had been pushed. I hooked up the ladder and connected the keypad row pins. Then connected a DMM to each col pin. EUREKA! meter on col for pin pushed displays correct row voltage for row of pin pushed. Other col pin meters read zero. all three meters read zero when no pins pushed. Most Excellently Perfect!!

Hooked ladder/keypad up to UNO. did looped analog reads of the col pins. Results NOT good: Floating readings when no pins pushed. push any pin in a certain col. and that col's reading goes to zero..... all other col pin readings continue to float all over the place.

Any ideas where I am going wrong? Logically seems like it should work. offboard meter tests seem to indicate that logic is correct and it does work. software application falls flat on it's face, so I obviously do not grasp something bout reading the analog inputs on the UNO... Help.
Before you ask I don't know exactly how to get a schematic posted, hence the verbose description of the configuration. The code is dirt simple: identify the input keys, start serial com, loop analog reads with delay(10), serial print the value read, loop again.
123Splat
 
Posts: 23
Joined: Fri Jul 22, 2011 4:38 pm

Re: ANALOG INPUTS TO INTERFACE 3X4 KEYPAD

by adafruit_support_bill on Mon Sep 05, 2011 10:17 pm

If you have your schematic image as a file, you can use the "upload attachment" tab just below the text entry box.

There are problems associated with reading from more than one analog pin in close succession. The analog multiplexor in the Atmega needs some time for the signal to settle and the readings from one pin can influence the reading on the next pin. It is usually best to take at least two readings from each channel and throw away the first one.

adafruit_support_bill
 
Posts: 79109
Joined: Sat Feb 07, 2009 10:11 am

Re: ANALOG INPUTS TO INTERFACE 3X4 KEYPAD

by zener on Tue Sep 06, 2011 5:02 pm

You probably cannot decode multiple simultaneous button presses though. At least not on the same divider.

zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: ANALOG INPUTS TO INTERFACE 3X4 KEYPAD

by 123Splat on Fri Sep 09, 2011 2:45 pm

I have made the following changes: 1) rebuilt the resistor ladder (voltage divider) to be five 1.5Kohm resistors in series (reduced from 3.8K to increase current to the ADC); 2) changed code to do dummy analogRead(), analogRead(collpin)/10 to set input value, delay(10), then switch (input value), followed by case input value:, blah, blah,blah.

The code works and seems to give good results on key presses (and, YES, I CAN decode simultaneous key presses,, on different coll.s. at least).

The problem that I have now is doing analogReads on floating inputs and reading spurious values. Seems I need to figure out how to tie a default input to the analog input pins to give a stable reading when no keys are pressed.

Then I'll work on how to make it interrupt driven, so that the MCU isnt constantly reading the keys.

UPDATE: Floating analog inputs fixed- 1) removed the +5V feed to the voltage divider ladder, 2) tapped the three column feeds with a 3.9k R on each then to +5V. works like a charm.
Nice stable 1023 read on the analog inputs when no key is pressed. I use Switch/Case logic checking eace col input read (after a divide by 100, to get a single digit result when key is pressed). Using switch/case, It is easy to rule out Multiple concurrent key presses (needed for my application), but you can easily decode the results and set up case 'x': code for each, if you are looking to capture multiple concurrent key presses.
So, I can now, interface a 4 row by 3 col keypad to my UNO and 328 clones with only three (3) input pins.

This is sooooo much easier than screwing around with PIC 16F628's!!!
123Splat
 
Posts: 23
Joined: Fri Jul 22, 2011 4:38 pm

Please be positive and constructive with your questions and comments.