KeyPad reading and have been useing up batteries
whiteoxe
Posts: 794
hI,
I have two keypads , one was an expensive 4x4 serial keypad using just 1 wire to
send the keypress in decimal. The other which I am concerned with now using for the first
time is 4row X 3 column ,7 pin keypad
which was only a couple of bucks and plugs straight into the bread board.
I seem to have it working. I am checking to see that I have the pins wired up correctly as I do seem to be getting
the same value once in a while on different keypresses. Might have to wire it up 7..0 instead of
0..7
·I have used only a couple of lines of my own code in Main Method and changed the [noparse][[/noparse]0..7] to [noparse][[/noparse]0..6]
in the read row.
The only other thing I did to get this to work was change the unconditional
Repeat in ReadKeyPad method to Repeat Until KeyPad <> 0 which is working fine
except for the keypress being read multiple times. I am fuzzy on
what the Shifting 4 places to the left is for?
Despite having it working and feeling pretty happy to have gotten a keypad working
in a few minutes that I thought I would use a lot further down the track, I really haven't had to write any code,
Well a couple of lines if that counts.
so the fact that no matter how fast I press the keys the terminal screen fills up with
that key press reading it a hell of a lot of times. I guess I will change
the Unconditional Repeat in Main method this time. So im going to try something to
stop that but if you can suggest the way for me it might be· better and best.
Another issue I have is I am going through a lot of 9V batteries. even leaving it
connected while running a program that only lights up LED's if a button is pressed
is doing this. I have been through 4 x 9V batteries in a week and a half(two of them were
expensive Duracell $6.00 each. The batteries seem to drop below 6V very quickly and
will not allow a download cause "No Propellor Chip Found" is what I get. I think Ive
got is wired up as the manual suggests. Would my use of 16V Capacitors and 1 Amp Regulators
have anything to do with this ?· Thanks.
And Lastly I promise is.....
I need to buy an LCD. Futurlec.com.au seems to have the largest range and by far the cheapest starting around $9 for a 16 x 2 display,which is weird as the one above it is only 16 x 1 and about $12, a groovy Blue·& backlit·is under·$12 AU. They·seem to have a very big range and I
don't really mind waiting the two weeks or so that Ive heard is delivery time however if the Parallax LCD is easier to use with the Object library
I would rather spend the money with the local distributor. Anyway ·http://www.futurlec.com.au/LCDDisp.jsp·is their products.
I have two keypads , one was an expensive 4x4 serial keypad using just 1 wire to
send the keypress in decimal. The other which I am concerned with now using for the first
time is 4row X 3 column ,7 pin keypad
which was only a couple of bucks and plugs straight into the bread board.
I seem to have it working. I am checking to see that I have the pins wired up correctly as I do seem to be getting
the same value once in a while on different keypresses. Might have to wire it up 7..0 instead of
0..7
·I have used only a couple of lines of my own code in Main Method and changed the [noparse][[/noparse]0..7] to [noparse][[/noparse]0..6]
in the read row.
The only other thing I did to get this to work was change the unconditional
Repeat in ReadKeyPad method to Repeat Until KeyPad <> 0 which is working fine
except for the keypress being read multiple times. I am fuzzy on
what the Shifting 4 places to the left is for?
Despite having it working and feeling pretty happy to have gotten a keypad working
in a few minutes that I thought I would use a lot further down the track, I really haven't had to write any code,
Well a couple of lines if that counts.
so the fact that no matter how fast I press the keys the terminal screen fills up with
that key press reading it a hell of a lot of times. I guess I will change
the Unconditional Repeat in Main method this time. So im going to try something to
stop that but if you can suggest the way for me it might be· better and best.
Another issue I have is I am going through a lot of 9V batteries. even leaving it
connected while running a program that only lights up LED's if a button is pressed
is doing this. I have been through 4 x 9V batteries in a week and a half(two of them were
expensive Duracell $6.00 each. The batteries seem to drop below 6V very quickly and
will not allow a download cause "No Propellor Chip Found" is what I get. I think Ive
got is wired up as the manual suggests. Would my use of 16V Capacitors and 1 Amp Regulators
have anything to do with this ?· Thanks.
And Lastly I promise is.....
I need to buy an LCD. Futurlec.com.au seems to have the largest range and by far the cheapest starting around $9 for a 16 x 2 display,which is weird as the one above it is only 16 x 1 and about $12, a groovy Blue·& backlit·is under·$12 AU. They·seem to have a very big range and I
don't really mind waiting the two weeks or so that Ive heard is delivery time however if the Parallax LCD is easier to use with the Object library
I would rather spend the money with the local distributor. Anyway ·http://www.futurlec.com.au/LCDDisp.jsp·is their products.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 Var word keypad word value OBJ Debug : "FullDuplexSerialPlus" PUB Main Debug.start(31, 30, 0, 57600) waitcnt(clkfreq*2 + cnt) Debug.tx(Debug#CLS) repeat 'this repeat I guess needs to be conditional to stop multiple reads of one keypress................ value := readkeypad {this will get keypress} Debug.Bin(value,16) 'this will display keypress Debug.str(string("The key pressed ",13)) {{ ***************************************** * 4x4 Keypad Reader v1.0 * * Author: Beau Schwabe * * Copyright (c) 2007 Parallax * * See end of file for terms of use. * ***************************************** }} { Operation: This object uses a capacitive PIN approach to reading the keypad. To do so, ALL pins are made LOW and an OUTPUT to "discharge" the I/O pins. Then, ALL pins are set to an INPUT state. At this point, only one pin is made HIGH and an OUTPUT at a time. If the "switch" is closed, then a HIGH will be read on the input, otherwise a LOW will be returned. The keypad decoding routine only requires two subroutines and returns the entire 4x4 keypad matrix into a single WORD variable indicating which buttons are pressed. Multiple button presses are allowed with the understanding that“BOX entries can be confused. An example of a BOX entry... 1,2,4,5 or 1,4,3,6 or 4,6,*,# etc. where any 3 of the 4 buttons pressed will evaluate the non pressed button as being pressed, even when they are not. There is no danger of any physical or electrical damage, that s just the way this sensing method happens to work. Schematic: No resistors, No capacitors. The connections are directly from the keypad to the I/O's. I literally plugged mine right into the demo board RevC. Looking at the Back of the 4x4 keypad.. ...........................................EXCEPT I'M USING A 3 X 4 KEYPAD SO P6 IS LAST PIN P7 P0 ││││││││ ┌─────── ││││││││ ───────┐ │ oo ││││││││ o │ │ │ │ O O O O O │ │ │ │ O O O O O │ │ {LABEL} │ │ O O O O O │ │ │ │ O O O O O │ │ │ │ O O O O O │ │ o o │ └────────────────────────┘ } { this method ReadKeyPad left alone except I added "UNTIL", assuming it works the same for my 4* row and 3 * column } PUB ReadKeyPad keypad := 0 repeat until keypad <> 0 keypad := 0 'Clear 4x4 'keypad' value ReadRow(3) 'Call routine to read entire ROW 0 keypad <<= 4 'Shift 'keypad' value left by 4 ReadRow(2) 'Call routine to read entire ROW 1 keypad <<= 4 'Shift 'keypad' value left by 4 ReadRow(1) 'Call routine to read entire ROW 2 keypad <<= 4 'Shift 'keypad' value left by 4 ReadRow(0) 'Call routine to read entire ROW 3 Result := keypad {{ReadRow Method Altered so that only pins 0..6 Read as this keypad is 4 rows and 3 Col}} PRI ReadRow(n) outa[noparse][[/noparse]0..6]~ 'preset P0 to P6 as LOWs dira[noparse][[/noparse]0..6]~~ 'make P0 to P6 OUTPUTs ... discharge pins or "capacitors" to VSS dira[noparse][[/noparse]0..6]~ 'make P0 to P6 INPUTSs ... now the pins act like tiny capacitors outa[noparse][[/noparse]n]~~ 'preset Pin 'n' HIGH dira[noparse][[/noparse]n]~~ 'make Pin 'n' an OUTPUT... Make only one pin HIGH ; will charge ' "capacitor" if switch is closed. ' keypad += ina[noparse][[/noparse]4..6] 'read ROW value ... If a switch is open, the pin or "capacitor" dira[noparse][[/noparse]n]~ 'make Pn an INPUT will remain discharged DAT {{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ TERMS OF USE: MIT License │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and assB```ociated documentation │ │files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │ │modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│ │is furnished to do so, subject to the following conditions: │ │ │ │The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│ │ │ │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │ │WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │ │COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ │ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ }}
Comments
AA bateries have between 2000 and 3000mAh. You are far better off to use a couple AA bateries in series then a 9V.
You can improve battery life drastically by using a buck/boost switching regulator like the one on my propmod-us_ps(propmodule.com)
Linear Regulators drop the voltage by converting to heat. Switching regulators convert the voltage by turning the power on and off through a LC filter.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
24 bit LCD Breakout Board coming soon. $21.99 has backlight driver and touch sensitive decoder.
Post Edited (photomankc) : 10/29/2009 2:58:32 PM GMT
best regards
Stefan
for a parallel LCD left over, Ill see thanks.good to hear your writing another object for LCD. The more the merrier.
I just used a counter variable to stop the keypress being reported more than once,maybe not pretty but it works.
The key pad is not right, or my rows and columns need a look.
I am just now looking at the keypad 4 * 3 and re-wired it in case i
had done something weird. 1 , 2, 3 is a ROW right ?
1 & 2 = same value
4 & 5 = same value
7 & 8 = same value
I'm looking at the problem of same values but not a lot of idea, but the patten is probably shouting something
1 = 0000000000000110
2 = 0000000000000110
3 = 0000000000000011
4 = 0000000001100000
5 = 0000000001100000
6 = 0000000000110000
7 = 0000011000000000
8 = 0000011000000000
9 = 0000001100000000
P0 P6
│││││││
┌───── ────┐
│ │
│ │
│ 1 2 3 │
│ │
│ 4 5 6 │
│ │
│ 7 8 9 │
│ │
│ * 0 # │
│ │
│ │
│ │
└─────── ──┘
What about "* 0" ? Are they showing the same values?
There are a couple of things I can suggest:
1)
It sounds at though you could be straddling a ROW and COLUMN, meaning that one of the keypad ROWs is connected to a pin that the software is expecting to be a COLUMN, or vise versa. Double check your wiring.
P0 through P3 should be addressed to a COLUMN
P4 through P7 should be addressed to a ROW <--- In your case P4 through P6
As a sanity check, try the original code with P7 tied to GND with a 1K resistor.
2)
Also, I noticed that you changed some of the original code. i.e. when referencing "0..6" for outa[noparse][[/noparse]0..6], dira[noparse][[/noparse]0..6], and ina[noparse][[/noparse]0..6] ... This could have unwanted effects that don't charge the pin properly.
3)
On a related note to #2, since you are not reading the full NIBBLE (<-- 4-bits) , it could just be a simple matter of changing
the line that reads...
keypad += ina[noparse][[/noparse]4..6]
...So that it reads...
keypad += ina[noparse][[/noparse]4..6]<<1
...or...
keypad := keypad + ina[noparse][[/noparse]4..6]<<1
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 10/30/2009 3:41:08 PM GMT
You Program/Routien are fully usable if it was TGB with every KEY connected to separate IN trace.
BUT in ROW/COLUMN TGB's it is always 2 TGB's connected to 0ne ROW/Column that give You 2 posiblites.
ROW 1 - Col 1
ROW 2 - Col 1
else
ROW 1 - Col 1
ROW 1 - Col 2
It give You need to drive ROW active and in same TIME READ Column to see with on is active.
Regards
ChJ
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nothing is impossible, there are only different degrees of difficulty.
For every stupid question there is at least one intelligent answer.
Don't guess - ask instead.
If you don't ask you won't know.
If your gonna construct something, make it·as simple as·possible yet as versatile as posible.
Sapieha
Changing wiring or code to switch things every which way produced even more same values
or a big Nothing, or non stop keypress values reporting.
Didn't get better results than what I had only same or worse.
Anyway I added in a ROW variable to report which ROW the keypress was on when a value was
assigned and that shows everything wired properly the keypad 1,2,3 is row 0 And *,0,# row is row 3.(every key is showing correct row)
Yes * ,0 report the same value.
The keys down midddle column 2,5,8,0 have a habit of not always being the same. Sometimes they do switch to
a unique value. If only they did that all the time! Like key2 is 80% of the time the same as key1 and 20% of the time it seems to work.
This was the case all along. I have tried to detect if there is a pattern
to this but it does seem very random, it can switch to 50%/50% breifley.
It is a bit of a concern that only the middle row plays up. Ive rewired it and also used a whole new set of pins 16..22 and
could not do better.
Could be the keypad itself,only a possibility.
I will post when its working, Ive given this a reasonable flogging so would like to try a new keypad. Maybe a 4x4.
Mike.
I was just having the save trouble as you with a 3x4 keypad.· I connected a 0.1uf capacitor between each of the·row pins and Vss and it now works fine.· I'm using a keypad I purchased from SparkFun http://www.sparkfun.com/commerce/product_info.php?products_id=8653·the columns and rows are not in order.··The·first and last pin have no internal connection with the keypad.· Pin 1 (second pin from left) is column 1, pin 2 is row 0, pin 3 is column 0, pin 4 is row 3, pin 5 is column 2, pin 6 is row 2, and pin 7 is row 1.
Since the keypad only had three columns, I took Beau's advice and used a pull-down resistor on P3 of the Propeller.· I followed the rest of his advice (under the heading 1) and it's turning bits to one just like it should.
I haven't gotten past displaying the ouput in binary to make sure just one bit changes when one button is pressed.· Try the caps, hopefully they will work for you too.
Duane
Post Edited (Duane Degn) : 11/1/2009 3:13:36 AM GMT
I have added caps to the columns, It works great. Thanks for the suggestion, I'd given up.
Why do they make the difference?
Do you have long leads going from the Prop to the Keypad? The demo that I wrote was intended for designs where this distance is short. The idea works using the very tiny amount of capacitance each I/O has and exploits that particular aspect. If the leads are too long the charge built up on the I/O caps can bleed off sooner, or can be more susceptible to external interference. By adding additional caps your just countering the effect of what longer leads would have.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.