0
\$\begingroup\$

I'd like to wake up my AVR whenever any button on the keypad is pressed. I am using Keypad.h library and simple 4x4 keypad made of buttons connected straight to AVR digital pins. Keypad itself works perfect.

One question is: Why are there pull-ups connected to rows/cols in some schemes? When it works without them...

For waking AVR up I found that simple attaching 4-input AND to kepyad columns would solve the problem. Before sleep, AVR should set all columns to OUTPUT (HIGH) and then attach interrupt on INPUT INT1 (pin 1) when LOW. So AND inputs are all HIGH till any button is pressed, then it sets LOW on AND output, so INT1 is triggered. But then I saw Keypad.h library source:

 void Keypad::scanKeys() {
 // Re-intialize the row pins. Allows sharing these pins with other hardware.
for (byte r=0; r<sizeKpd.rows; r++) {
    pin_mode(rowPins[r],INPUT_PULLUP);
}

// bitMap stores ALL the keys that are being pressed.
for (byte c=0; c<sizeKpd.columns; c++) {
    pin_mode(columnPins[c],OUTPUT);
    pin_write(columnPins[c], LOW);  // Begin column pulse output.
    for (byte r=0; r<sizeKpd.rows; r++) {
        bitWrite(bitMap[r], c, !pin_read(rowPins[r]));  // keypress is active low so invert to high.
    }
    // Set pin to high impedance input. Effectively ends column pulse.
    pin_write(columnPins[c],HIGH);
    pin_mode(columnPins[c],INPUT);
}}

I don't get why are columns set as INPUTS at the end? Could this be skipped? If so, I'll change it to OUTPUT and connect all columns to 74HCT21 inputs and attach output to INT1 pin.

enter image description here

Are there any additional parts needed to connect the 74HCT21? Or it can be connected straight to the 3.3 V regulated power source like this?

Thank you very much!

\$\endgroup\$
1
\$\begingroup\$

When you will want your device to enter sleep mode you can change all the columns to OUTPUT and LOW. And enable the interrupt. Then diode-OR all of them together and bring that output to interrupt pin. Something like this:

schematic

simulate this circuit – Schematic created using CircuitLab

When either of the button is pressed the output from the diodes is LOW (~0.6V).

The pin of the interrupt should be configured as input with a internal pull-up. In the ISR of that interrupt you should bring all of the column pins back to high impedance input. And disable further interrupts on this pin for debouncing purposes.

\$\endgroup\$
  • \$\begingroup\$ If power consumption was a concern, would an external pull-up be a wiser choice to lower the consumed current while in this mode? \$\endgroup\$ – gregb212 Apr 22 at 17:22
0
\$\begingroup\$

This solution worked for me! Thanks. enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.