Author Topic: Simulate a matrix keypad with a microcontroller  (Read 11116 times)

0 Members and 1 Guest are viewing this topic.

Offline dayveTopic starter

  • Newbie
  • Posts: 4
Simulate a matrix keypad with a microcontroller
« on: June 29, 2014, 02:14:00 am »
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?
 

Online David Hess

  • Super Contributor
  • ***
  • Posts: 16615
  • Country: us
  • DavidH
Re: Simulate a matrix keypad with a microcontroller
« Reply #1 on: June 29, 2014, 02:35:40 am »
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.

 

Tac Eht Xilef

  • Guest
Re: Simulate a matrix keypad with a microcontroller
« Reply #2 on: June 29, 2014, 03:05:25 am »
Or look around at what's available in crosspoint / crossbar switch ICs e.g. the Zarlink / 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.
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Simulate a matrix keypad with a microcontroller
« Reply #3 on: June 29, 2014, 06:23:23 pm »
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 ;)
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Simulate a matrix keypad with a microcontroller
« Reply #4 on: June 29, 2014, 06:57:04 pm »
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.pdf

But, you might be able to work this out without actual "switches". As David suggested.
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Simulate a matrix keypad with a microcontroller
« Reply #5 on: June 29, 2014, 07:44:06 pm »
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.pdf

But, you might be able to work this out without actual "switches". As David suggested.

16 solid state relays would cost a fortune ;)
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13747
  • Country: gb
    • Mike's Electric Stuff
Re: Simulate a matrix keypad with a microcontroller
« Reply #6 on: June 29, 2014, 07:53:06 pm »
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
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Simulate a matrix keypad with a microcontroller
« Reply #7 on: June 30, 2014, 12:22:13 am »
PIC or Arduino
interrupt 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.
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Dinsdale

  • Regular Contributor
  • *
  • Posts: 77
  • Country: us
    • pretzelogic
Re: Simulate a matrix keypad with a microcontroller
« Reply #8 on: June 30, 2014, 11:25:06 pm »
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.
This can't be happening.
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Simulate a matrix keypad with a microcontroller
« Reply #9 on: July 01, 2014, 06:56:55 am »
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.

and 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.
 

Offline Dinsdale

  • Regular Contributor
  • *
  • Posts: 77
  • Country: us
    • pretzelogic
Re: Simulate a matrix keypad with a microcontroller
« Reply #10 on: July 01, 2014, 04:33:26 pm »
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.
This can't be happening.
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Simulate a matrix keypad with a microcontroller
« Reply #11 on: July 01, 2014, 04:40:49 pm »
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.

agree 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 ;)
 

Offline mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13747
  • Country: gb
    • Mike's Electric Stuff
Re: Simulate a matrix keypad with a microcontroller
« Reply #12 on: July 01, 2014, 05:07:51 pm »
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.
Or one 4052 & 5 lines
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline Dinsdale

  • Regular Contributor
  • *
  • Posts: 77
  • Country: us
    • pretzelogic
Re: Simulate a matrix keypad with a microcontroller
« Reply #13 on: July 01, 2014, 07:26:31 pm »
Quote
Or one 4052 & 5 lines
But... but... that's TWICE as many parts as 1 part!  ;D
This can't be happening.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Simulate a matrix keypad with a microcontroller
« Reply #14 on: July 02, 2014, 03:18:29 am »
[... you'll need to run the keyboard simulator at least 4x the speed of the micro that's using it, maybe fas...
Not really.  Interrupt on pin change negates that issue which would only be a problem if polling the scan lines.
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Dinsdale

  • Regular Contributor
  • *
  • Posts: 77
  • Country: us
    • pretzelogic
Re: Simulate a matrix keypad with a microcontroller
« Reply #15 on: July 02, 2014, 06:20:35 am »
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.
This can't be happening.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Simulate a matrix keypad with a microcontroller
« Reply #16 on: July 02, 2014, 08:46:17 am »
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 !!!
Don't ask a question if you aren't willing to listen to the answer.
 

Offline Dinsdale

  • Regular Contributor
  • *
  • Posts: 77
  • Country: us
    • pretzelogic
Re: Simulate a matrix keypad with a microcontroller
« Reply #17 on: July 02, 2014, 12:49:14 pm »
Quote
It seems like we are all overthinking this until the OP responds with his observations that e can consider for a final proposal !!!
Ha 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?
This can't be happening.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf