One Input Keypad

Last Update: 8.3.2007

 

As you know, a normal 4x3 keypad would use up four outputs and three inputs of a microcontroller. There are four rows and three columns, each row connected to an output and each column connected to an input. As each output is set high, the three input  pins are scanned for a high indicating a button push. By identifying which output and which input was set high, the microcontroller can determine which key was pressed.

This technique works perfectly well. The only drawback is that it requires seven dedicated I/O pins to function. Even using the bigger Picaxes(40x1), this cuts down on your usable I/O which never makes anyone happy. I came across a post one day on the PicAxe forums talking about possibly using one input and a readadc command to read a keypad. The posters explanation in theory was sound. Now of course when I came across that post, I wasnt looking for it. I haven't been able to find it again to see if hes tried to prove it. So, I will.

Now codewise, it doesn't seem like it would be very hard to do. It wasn't. Now I am a novice programmer, but this code is just as sound in the simulator as the keypad  code rev-ed uses for their lock. Its actually based off of it.

This was my first concept:

 

 

 

While it was sound, it lacked in speed. It read the input then had to go through twelve instructions to determine which, if any, key was pressed. While still speedy, it had room for improvement.

 

 

 

 

With a normal keypad, the four outputs were set high in order.  An output was set high, then the three input pins were scanned. If all were low, the next rows output pin was set and the three inputs scanned and so forth.

Lets take the middle number:   5

The five key would be set by setting out1 and pin1 high:

                             1-------2-------3       Output 0

                             4-------5-------6       Output 1

                             7-------8-------9       Output 2

                             *-------0-------#       Output 3

                           pin0      pin1      pin2

Using the code for a normal keypad, it would take eleven instructions to decide what the key value is.

The (1) key could take Six instructions, the (#) key could take Twenty-One instructions. Think it can get better?

 

 

Here's where I am now. An 'enhanced' version of my first readadc keypad code attempt.

 

Lets look at that five key again:

We see the five key is in the 70-85 range. Working through the code, it takes Eight instructions to get a key value.

The (1) key would take Seven instructions and the (#) key would take Nine instructions.

The (1) key is an instruction slower but its well made up over the rest of the keys.

The scan rate is much higher here also. Whereas the normal code takes Twenty instructions to 'look' at each key for a press, the readadc code takes Five to 'look' at each key for a press.

Of course the adc values used here are for show, if my resistance calcs are correct it will be using 5-250.

 

With the right network of pushbuttons, resistors and a voltage divider, this concept is theoretically very possible. I believe I have the combination of resistances worked out. I'm waiting on the parts to build the circuit and begin testing. Ill update when I'm parts in hand ready to test.

8.3.2007

Here's a schematic of my concept. I've worked out the resistances to give as equal spacing between readings as possible. Of course when the parts get here  monday, these could change. I wired 3 switches and resistors on my breadboard today for some preliminary testing. The key press response seemed to be just as fast if not faster than a conventional keypad. I have not made the program work through itself to give me a key value yet, but from the results so far I definitely see this this being very feasible and possibly better than  the conventional keypad because of the smaller amount of IO needed.

Again, my parts should be here monday. Being school doesnt start up til Aug 20(and I have nothing else to do) I should have some solid results with pictures probably monday night but definitely tuesday. Until then.

8.6.2007

Well, UPS was running late but the parts have arrived.                

After about thirty minutes, here she is.

The build was extremely quick and easy thanks to the protoboard I used from Radio Shack. The trace layout lent itself perfectly to my application. As you can see I only had to use two jumpers for the entire prototype.

The resistors are the same values as spec'd out above with 5% tolerances. The switches are SPST tactile switches from Jameco Electronics. I get all of my components from them, great service and great prices.

So, does it work?.                    

Schematic

The first order of business was to test keys for ADC values. I had calculated what I thought my ADC values for each key would be. Was I close?

  Key 1 Key 2 Key 3 Key 4 Key 5 Key 6 Key 7 Key 8 Key 9 Key 10 Key 11 Key 12 Key 13 Key 14 Key 15 Key 16
Calc ADC Value 10.2 25.245 41.822 59.16 74.97 89.5 102 121.38 133.62 151.98 168.81 183.6 196.35 212.67 229.5 245.31
Act ADC Value 9 24 41 59 74 90 101 120 132 151 168 183 195 212 229 246
Calc Voltage .200 .495 .820 1.16 1.47 1.79 2 2.38 2.62 2.984 3.31 3.60 3.85 4.17 4.5 4.81
Act Voltage .2028 .496 .835 1.185 1.485 1.812 2.022 2.399 2.640 3.014 3.367 3.660 3.896 4.22 4.56 4.88

The calculated values were based off of a 5V source. My actual source was 5.07V.

I used a very simple little loop to get the ADC values. I went through each button and recorded the ADC value for it. For the voltages, I used a voltmeter.

My original code showed a key range of 15. That was only for theoretical representation. My intentions were to use as small a range as possible and still maintain accuracy. My reasoning for this is simultaneous key pressings. My reasoning is as follows. 

When a key is pressed a series circuit is closed. This means that between all the keys, there are only sixteen general resistance values the picaxe will recognize.

When two keys are pressed simultaneously, a series-parallel circuit will be formed. This will produce a resistance unlike any of the sixteen resistances the picaxe recognizes. The thinking is that these values will just appear as nothing to the picaxe because they fall into the ADC ranges not being used.

Now of course some key combinations may produce a resistance in a valid range but to try to calculate all the combos would take forever. The bottom line is that it is to easy an engineering control not to implement.

The code below is part of my alarm code so don't mind the odd stuff. I'm going to start my testing with a key range of 3. I will try to find variables that affect the ADC value of a button. From what I've seen so far, I can see three, maybe four and possibly five. I cant see the range going above five. With a fairly clean voltage source, we should be able to stay at three or four.

So what's the bottom line?      ADC Keypad to Matrix Keypad

Does it work?    YES

Is it faster?        COMPARABLE (Both are plenty fast for my fingers)

Is it more efficient?     Lines of code about equal, ADC KP uses far fewer instructions to reach a Key Value.

The purpose of this project for me is to cut down picaxe size in my alarm control. But I think many folks could find good use for this one. Seven IO down to one, who doesn't love that?

Well, the does it work phase of this project is over. The next phase will be the lets make it work great phase. If anyone would like to build the keypad and play with it themselves, that would be great. Some adc fluctuation data from other setups with the same keypad would be great. If anyone cares to try, you can upload your data to me via my downloads page.

I'm going to concentrate on the range right now. Ill try to vary ,y voltage inputs, length of wires, things like that to see what kind of range I need to catch the keys every time they are pressed.

That's all for now. If all goes well, Ill have a great working version in a week or so. Until then.

8.11.2007

So, I've gotten the chance to play a bit. Ive been testing the feasibility of using an ADC range of three for our one wire kp.

Feeding the KP circuit with different voltages certainly brought about a change. Too much to have one generic set of values that will work. The table below shows ADC values with three different voltage sources. Nothing else I did(change wire length, wiggle wires, apply heat, apply cold) changed the ADC value enough to change it by more than one.

V+ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
4.5 9 22 37 52 66 80 90 107 117 134 150 163 174 189 204 218
5 10 24 41 58 73 89 100 118 130 149 166 181 192 209 226 242
5.5 11 26 45 64 80 98 109 130 143 164 183 199 212 230 248 255

As you can see, different source voltages can bring drastic change in ADC value.  This completely rules out using generic values. The code will stay the same, but the designer will have to 'tune' his/her keypad with the voltage source. This means the designer will build the circuit, write simple code to read the ADC values, make the range +-1 and plug those numbers into the KP code. If the designer is using a good, regulated voltage source, there should never be a problem with ADC fluctuation.

Now, with that said there was some concern raised about contact resistance building up over time. It hadn't hit me at first, but the concern was valid. My current config was only 1039 ohms of resistance at it lowest value. With such a small value, contact resistance builtup over time could cause my ADC value to change. The suggestion from fellow designers was to up the resistor values to a value high enough that buildup resistance would be such a  small portion of the overall resistance that it would not affect the voltage enough to cause change. It was a great idea. I've up my values by a factor of 100. Here it is:

The voltages and ADC values remain the same as the numbers I reached previously. The only difference is the higher resistor values but the picaxe sees no difference from the previous circuit.

Simultaneous Key Pressings

This has been a concern of mine since the beginning. Its the reason I chose this series-parallel circuit setup. As Ive said before, the purpose of this KP for me is to use it with a breach alarm system. I wanted to use as small a picaxe as possible for my keypad panel with a bigger picaxe in the control panel.

When my end-users are typing in their PIN, the only thing they will see on the LCD is an asterisk. Three wrong PIN entries and the alarm sounds. This is why simultaneous pressings was an issue for me.

BCJKiwi has been doing some fantastic work on this issue. He's developed a spreadsheet that helps to determine resistor values depending on how many keys you want and what type of circuit your using. He's also recently added in a section to help determine what results the simultaneous pressing of different keys will yield. His findings show that no circuit of this kind is optimal for this problem. The best solution would be in the design, putting small dividers between keys or recessing them into the board.

Ill continue trying to find a solution to this problem.

BCJKiwi has a project he would like to use this concept on, I hope my work has been as beneficial to him as his has been to mine.

Perhaps a simpler solution?

This caught my interest in a dialog between BCJKiwi and Premelec of the Picaxe forums. Premelec proposed a series chain of sorts for this circuit. Its certainly functional. Its a great circuit for two reasons, building ease and code. All the resistors in the circuit are of the same value. My calcs show using 100K resistors all the way through yields ADC values almost exactly 15 units away from each other. This makes using BeanieBots math solution feasible.

These math solutions work with this circuit. you can of course sub-in what you do with the key values, but reaching the key value this way works well.

The circuit uses a simple series of resistors from V+ to 0V. A switch is tapped off between each resistor and tied to the ADC pin on the Picaxe. I haven't done a schematic yet, but will try to get one posted in a couple days.

I will try to build this circuit and do some testing to prove it.

 

 

Bottom Line

The one-wire ADC keypad works.

The ADC range of three works with a 'tuned' system using a good constant voltage supply.

The KP code will have to be 'tuned' per system (due to source voltage), but multiple reproductions of the same system should use the same values.

I believe I've come to a suitable keypad for my next project. My Breach Alarm Project will use this keypad as a numeric entry pad. Ive already began this project, hopefully Ill be able to post my progress thus far soon

Uses

This concept is definitely worth using as a numeric keypad, but you don't have to stop there. This circuit and code could essentially be used to multiply usable inputs of a picaxe. IE   Dance Floor Project    This guy could have used the 'I don't care about simultaneous key pressing' concept. He could have made two 32 switch strings using only two inputs and still have a range of 8 between each switch.  Instead, it seams he had to use 8 IN's and 8 OUT's. Thinking about it, i wonder if it may have been possible also using an AD converter to drive his 64 outputs with the same concept just reversed. Hmmm We should look into that!

Using it on a project like this is safe. I would not recommend using it as control switches for machinery that could possibly cause harm due to the nature of the simultaneous key pressing issue. Accidentally press two buttons together and you don't know what that machine will do which equals- unsafe.

8.17.2007

I along with BCJKiwi have been able to explore the 'simpler solution' listed above. Its proven itself to be the configuration of choice for this project. Ive posted a new page dedicated to this concept to keep the contents of the earlier concepts from being confused in any way with the new one. This page will stay up as a reference to how we got to the final product from beginning concepts to fruition. I hope both of these pages are helpful to anyone interested in these concepts.

Back    Home