Simulate a matrix keypad with a microcontroller - Page 1
Forum section: electronics / beginners

author: dayve
author_rank: Newbie
timestamp: June 29, 2014, 02:14:00 am
content: I've done all kinds of searching for "matrix keypad" and "microcontroller". That all comes up with ways to connect a matrix keypad to a microcontroller. I want my microcontroller to behave as if it *is* a matrix keypad connected to another device via a header. I could run scripts on the micro that would "type" them into a larger device. Basically, I have to do the same keystrokes a bunch of times, so I just want to automate it.Looking at the schematic for a matrix keypad:It seems like I could run a 4x4 grid of wires and connect them at all the crossing points, then use a 4066 chip to control each set of 4 wires.So, in that first diagram above, I'd have the yellow wires running through a 4066, and the green wires running through another 4066. The green and yellow lines would be tied together at all crossing points (to simulate each key). The micro would control the 4066 chips. That should emulate a physical keypad, right?

author: David Hess
author_rank: Super Contributor
timestamp: June 29, 2014, 02:35:40 am
content: That will work if the voltages are within the range that the 4066 can handle. I have used optocouplers in the past for the same thing.A better way is to detect the row or column strobes and then drive 1 of the 5 lines to simulate the keypress. That only take 10 total I/O lines.

author: Unknown
author_rank: Unknown
timestamp: June 29, 2014, 03:05:25 am
content: Or look around at what's available in crosspoint / crossbar switch ICs e.g. theZarlink / Microsemi MT8806 & mates.I vaguely recall someone else - TI or Dallas/Maxim? - having a range of similar devices, but can't find them at the moment.

author: rob77
author_rank: Super Contributor
timestamp: June 29, 2014, 06:23:23 pm
content: if the speed is not a concern (shouldn't be when simulating key presses) then use relays- it's safe for whatever application.i did the same thing many years ago: PC LPT -> latch -> 74154 (4bit to 1 of 16 decoder) -> transistors switching DIP relays. relay contacts were wired as a keypad. simple and little bit noisy , but works with any voltages on the keypad side

author: Jeroen3
author_rank: Super Contributor
timestamp: June 29, 2014, 06:57:04 pm
content: Isolated Solid State Relays, those small ones with mosfets, might be more suitable than standard optocouplers or relays.They are able to switch up to a few hundred milli amps AC or DC with voltages up to 500. Accurate specs are highly dependent on the price you want to pay for them.Example of expensive one:http://www.omron.com/ecb/products/pdf/en-g3vm_62j1.pdfBut, you might be able to work this out without actual "switches". As David suggested.

author: rob77
author_rank: Super Contributor
timestamp: June 29, 2014, 07:44:06 pm
content: Quote from: Jeroen3 on June 29, 2014, 06:57:04 pm16 solid state relays would cost a fortune

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: June 29, 2014, 07:53:06 pm
content: You're on the right track with analogue switches, but the wrong type.use a pair of analogue multiplexers, with the commons linked together.One selects row, the other selects column, then the enable to press the key

author: SL4P
author_rank: Super Contributor
timestamp: June 30, 2014, 12:22:13 am
content: PIC or Arduinointerrupt on pin change for row/column scan (only one at a time is fired)Lookup key value that you want to return.Set matching (column/row) bit on second port until scan pin reverts to idle state.Done.You can use various methods to support multiple/simultaneous button presses.

author: Dinsdale
author_rank: Regular Contributor
timestamp: June 30, 2014, 11:25:06 pm
content: SL4P has the right idea. I don't know what the 4066 does for you; you're not doing any level translation or anything?The only "gotcha" I see for doing it as SL4P says is that you'll need to run the keyboard simulator at least 4x the speed of the micro that's using it, maybe faster. It would be easy to "just miss" the column drive and send a row active just when the user moves to the next column. That's the danger of the two micros not being synced up.

author: rob77
author_rank: Super Contributor
timestamp: July 01, 2014, 06:56:55 am
content: Quote from: Dinsdale on June 30, 2014, 11:25:06 pmand what if the target device is using analog scan of the keypad ? i'm doing this quite often with atmega - few resistors and 1 ADC input to interface the 4x4 keypad.the safest way to simulate a keypad is relays or of you're 100% sure the voltages are low enough then the proposed cmos switch method.

author: Dinsdale
author_rank: Regular Contributor
timestamp: July 01, 2014, 04:33:26 pm
content: I'm guessing at the connected device. Just like everyone else.If you need isolation, then 4 4066s and 16 lines from the micro should work.If just logic levels, then 8 lines from the micro.5 parts vs 1 part.You could hack the keypad (4066s) for the ADC scheme. But that's not a standard keypad. And 16 or 20 more resistors.You could be totally correct. But when half the circuit is not specified, my guess is as good as yours. Just trying to save the dude some parts in case he's not thinking of some shortcuts that may be possible.

author: rob77
author_rank: Super Contributor
timestamp: July 01, 2014, 04:40:49 pm
content: Quote from: Dinsdale on July 01, 2014, 04:33:26 pmagree with you. my comment wasn't meant to be offensive, i just wanted to highlight that it's better to be prepared for the worst case scenario

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: July 01, 2014, 05:07:51 pm
content: Quote from: Dinsdale on July 01, 2014, 04:33:26 pmOr one 4052 & 5 lines

author: Dinsdale
author_rank: Regular Contributor
timestamp: July 01, 2014, 07:26:31 pm
content: QuoteBut... but... that's TWICE as many parts as 1 part!

author: SL4P
author_rank: Super Contributor
timestamp: July 02, 2014, 03:18:29 am
content: Quote from: Dinsdale on June 30, 2014, 11:25:06 pmNot really. Interrupt on pin change negates that issue which would only be a problem ifpollingthe scan lines.

author: Dinsdale
author_rank: Regular Contributor
timestamp: July 02, 2014, 06:20:35 am
content: Given that this keypad simulator is just doing keypad simulation and nothing else, it can spend all of its time polling a port for the user's column input. If you have an interrupt driven system, you have the latency to deal with.I checked latency for a PIC16F triggered by an external interrupt - 4 cycles, worst case.The shortest polling loop I can do is 4 cycles. But when user data is "true", it takes 3 cycles (no jump to start-of-loop) -- polling wins by 1 cycle.When polling just misses the data, it's 4 cycles until it can read it again plus 2 more to fall out of the loop -- interrupts win by 2 cycles.So given any interrupt latency at all, I think you would still need to be running faster than the user micro.Ages ago, we did this very thing on a Raytheon 500 based system. Instead of a micro we did a Mealy-Moore machine. It was so much faster than the Raytheon bus that none of this was an issue.

author: SL4P
author_rank: Super Contributor
timestamp: July 02, 2014, 08:46:17 am
content: Given the level of detail we are discussing, either/any approach is also dependent on how the host application responds to n-key rollover and multiple simultaneous presses.A solution to the basic obstacle of latency - look up the output byte, then only send it if the scan input is still the same value (or hold the output byte for the next pass of the scan -- eliminates the lookup on the second scan pass.)I can't imagine any practical application where interrupts will be slower than polled operation in this situation.It seems like we are all overthinking this until the OP responds with his observations that e can consider for a final proposal !!!

author: Dinsdale
author_rank: Regular Contributor
timestamp: July 02, 2014, 12:49:14 pm
content: QuoteHa ha. Yeah, I know. While I was counting cycles I was asking myself: "What are you doing this for? There is no actual project." I guess I like to beat a point to death sometimes.Yo, dayve, are you still out there?