buttons multiplexing
max72
Posts: 1,155
I would like your opinion about the possibily to read the state of a relatively huge amount of buttons.
The idea is to have more buttons than pins available (say 64 buttons, and some prop pins used for other activities).
I usually test the single buttons and use a debounce routine, but I have a 1:1 relationship, in this case it wouldn't work.
Is there a way to multiplex them?
Thanks in advance,
Massimo
The idea is to have more buttons than pins available (say 64 buttons, and some prop pins used for other activities).
I usually test the single buttons and use a debounce routine, but I have a 1:1 relationship, in this case it wouldn't work.
Is there a way to multiplex them?
Thanks in advance,
Massimo
Comments
I'll check the datasheet.
Massimo
Probably I could accept two buttons at the same time in two different areas, so maybe I could have two separate areas with independent circuits.
At least I know it is possible... time to jolt down some specs.
Massimo
So you mean other than the usual Keyboard matrix (rows x columns cross point) design ?
http://pcbheaven.com/wikipages/How_Key_Matrices_Works/
For 64 buttons, you would need 16 io lines, as a simple 8x8 matrix, or depending on the wiring, you might decide that a 16 bit i2c expander makes more sense ?
I see a PCA9655E is under $1, which gives 16io, and you can connect 64 of those, if you want "relatively huge amount" to reach 4096 buttons....
Enjoy!
Mike
The idea is to use mushroom style buttons to create a kind of push game ( I saw one, professional and high quality, and it was great fun).
So I would have to decide if allow multiple press.
I would light the buttons to be pressed (LEDs around the buttons, TBC).
Light control would be multiplexed too.
I guess 64 is already a large enough number, probably I'll settle for less.
A PS2 keybard would work, as long as I could hack it and connect the mushrooms in place of the standard keys.
Massimo
Usualy they have some small rubber-caps under the plasic-keys. Leave them there where they are and push them with something else, mounted above.
or the hard way ... follow the traces and hook up buttons/wires....
the keyboard-objects available return sometimes a key-code and sometimes a scancode also. So multiple buttons may be available too.
Enjoy!
Mike
The multiplexer chips ar 16 to 4 and rarely used beyond 32 buttons.
There is also a 4x4 matrix chip called a 74c922 that is really handy and off loads the effort of supporting 10 key and 16 key numeric entry. It handles all the issued - debound, second key roll over, and auto repeat. Guther's SX assembly textbook has an excellent example of providing all these features in a DIY keyboard as large or larger than yours.
So is this a reaction-time game ? - for how many players, and what button separation ?
If you want to chase reaction times, a generic keyboard is likely too slow.
You could pre-prime the scan matrix, so it was ready for just the valid keys (and a few other non-lit ones, you can probably just ignore) and that would get the reaction time capture down to sub us levels.
The original is made of panels about 20X20cm, and the pressure required is quite high. They are more slam-panels.. so I thought about emergency mushrooms.
There are many option, and 1 or two players (I saw a bunch of kids slamming the panels at the same time and having a great time, but this wasn't really "legal" play..)
Combining the widely spaced panels and the pressure required the game is a combination of reflexes and physical activity, and is not requiring a tight timing.
I think it would make a great diversion in a rainy day.
Massimo
I have to study the 4017 and 165 combination.
In the meanwhile I got a PS2 keyboard to open.... for sure cheap and low pin count... have to see if it is easy to hack.
Considering the hardware cost I'll start smaller (4X4 probably), but I would like to have room to grow. So I'll work on a modular approach.
Massimo
Here is the diagram of the circuit using the '165/'4017 to scan key switches. If you have a couple of extra I/O pins you can get rid of the resistors and capacitor and simplify programming a bit as well.
Missing are pull down / pullup resistors on the Shiift register Dn lines.
(the 4017 pulses hi 1:10, so I would use pull-downs and look for any hi on Dn)
A 4021 can be used with similar effect to '164, and you can remove the R's and C if you want.
a) If the DS pin on the Shift register is connected to any 4017.Qn, then you can sample Qn state with a 9th clock, and do not need to change CLK pin direction.
b) As the PL is level based, if the 4017 clocks on the leading edge of PL, then the 4017 ticks to a new scan, and SR loads, and when PL is de-activated to shift, the Dn data on the trailing edge is what is sent.
This makes CLK speed much more tolerant.
c) if you use a HEF4017, instead of HC4017, the lower drive on the pins means the diodes can be dispensed with.
(but the top clock speed does lower)
d) A 4000 series HEF4021/HEF4017 would have a maximum CLK speed the Prop could exceed, so test < 1MHz to begin with.
This Circuit still needs 8 passives + 2 packages, so you may decide the sub $1 i2c device (PCA9655E) is a better bet.
That includes Pullups, and has an INT pin, that allows very low RFI operation, as you can set all SCANs low, and wait for a input button press.
This could trigger the time capture, and a following key-scan-check would confirm the correct button, but the scan time is not part of the response time.
The i2c device can also drive LEDs, and 64 PCA9655E can clip on a single i2c lane.
I know this circuit could be improved, and your suggestion of putting one of the outputs from the '4017 or '4021 shift register as the serial input of the '165 and reading it's state as the ninth bit of the '165 is an excellent one.
You are right, the pulldown resistors are missing. There should be 8 pulldown resistors on the parallel inputs to the '165. Thanks for noticing that, missed them when I copied the diagram from my notebook to paint.
I'll have to study a lot..
Massimo
That would work but would require 8 chips for 64 keys and 10 chips to do what these 2 chips do. Both chips and board real estate cost money. A small inexpensive microcontroller is the best way to go for low cost high volume production (ie PC keyboards).