Keypad triggering interrupt

Status
Not open for further replies.

BReeves

Well-known member
Still working on my Teensy 2.0 stepper motor project. I am using a 4x4 keypad for input and have noticed an issue when running the stepper a step at a time in the Loop() code. Using the Keypad library and normal keypad.getKey(); in the Loop(). This creates a delay in the loop while it is scanning the keypad which is causing issues with my stepper code.

What I would really like to do is move the keypad code out of the loop and have it interrupt driven. Pressing a key tells the Teensy via an interrupt it's time to read the keypad. I have rewired the Teensy pins to free up one interrupt pin (7), about the best I can do and still have everything working. The keypad is connected to pins 12 through 19 and it would be a major ordeal to change.

My question is.. Is there a trick way to have the keypad trigger an interrupt on pin 7 when a key is pressed and would putting the Keypad.getkey() in the ISR code work? I did search the net but didn't come up with anything useful for my situation.

Thanks...
 
depending the circuit configuration you could use several (4?) diodes to allow voltage to you interrupt pin when one of the keys is pressed. The diode should prevent the keys from interacting with each other .
 
Did find a few references to using diodes to an interrupt pin but not much detail. I understand the diodes but not sure how the keypad library works. Like do I need to do anything other than add the diodes. Does the keypad library provide the low-high transition for the irq pin and will GetKey then grab what key was pressed.

Hard to believe I'm the first one that has needed an IRQ based keypad input.
 
I have no idea how that library works. I utilize a keypad but used my own code, its a 3x7 keypad. 3 of the pins are interrupts, the other 7 pins are normal digitals. When the interrupt is toggled it turns off the remaining digitals sequentially until the same interrupt pin goes low again. so it knows what key is held down. If you try the diodes select low voltage drop diodes. regular rectifiers have a 0.7 volt drop. you want to minimize the drop to insure there is enough voltage to trigger the intrrupt pin. some diode have a 0.3 volt drop. you may even need to use the diode to drive a transistor or FET that inturn drives the interrupt pin.
 
Guess I'll have to dig into the library code and see if I can figure out what it does with the keypad pins, build up a test board and start playing to see if I can make it work. The diode you are talking about with the low voltage drop is a Schottky, useful in many switching applications.
 
My guess is you could probably make your own version of the library that works similar to instumentk did, probably without needing any hardware changes, especially if you only need to only detect one button at a time.

My assumption is your keypad is setup as a 4x4 grid where you have 4 pins for the Rows and 4 pins for the columns... So lets say your ROWS are driving it and you are detecting on Columns.
You might be able to do something like:

Set the 4 column pins to INPUT_PULLDOWN mode... So with no button pressed they will have a LOW value
Set the 4 driving ROW pins to OUTPUT and set their values high.
Enable an interrupt on the 4 column pins: attachInterrupt(pin, <your function>, HIGH)

So when the user presses a button, one of the column pins will go high and trigger the interrupt. You can then in that function start to change the state of the 4 ROW values one at a time to logically low (digitalWrite(pin, LOW)) or could switch it to Input, or ... When your pin that had the interrupt goes LOW, you Know the last pin you changed the state of was the one that caused the interrupt, so you now know your ROW and Column...

You then need to find a way to reset to be ready for the next press. i.e know when the user released the button... You can probably also do that by having your interrupt detect when the signal goes LOW, to reset your state...
 
Thanks for taking the time to reply to this thread gang. I have given up trying to do a keypad interrupt on this project. Return on investment (time) simply didn't work out to make it worth it. The keypad issue only effects the motion when it's free running and really isn't anything I can't live with.
 
Status
Not open for further replies.
Back
Top