Shop OBEX P1 Docs P2 Docs Learn Events
matrix keypad — Parallax Forums

matrix keypad

ArchiverArchiver Posts: 46,084
edited 2001-07-03 07:20 in General Discussion
Hi,

As an addition to Tracy Allen's matrix schematic consider this:

Normal 3x4 matrix:

} | |
---o
o
o--- r1 P0
| | |
---o
o
o--- r2 P1
| | |
---o
o
o--- r3 P2
| | |
---o
o
o--- r4 P3
| | | switches between row and column at o character
c1 c2 c3 requires 7 I/O lines for 12 switches
P7 P6 P5


Adding 4 diodes

/ / / /
\ \ \ \ 4x pullup resistor 10k
/ / / /
} | | |
1} 2| 3| D1/|
---o
o
o
+--- r1 P0
| | | |
4} 5| D2/| 7|
---o
o
+
o--- r2 P1
| | | |
6} D3/| 8| 9|
---o
+
o
o--- r3 P2
| | | |
D4/} 0| #| *|
---+
o
o
o--- r4 P3 diodes between row (cathode) and column
(anode) at /
| | | | switches between row and column at o
character
c1 c2 c3 c4 requires 4 I/O lines for 12 switches


Now only the rows are connected to the stamp. Make one row a low output
(others are input) and
check the remaining inputs. Then make the next row a low output etc.
r1 low output -> c4 pulled low -> keys 7,9,* give low input on P1,P2,P3
r2 low output -> c3 pulled low -> keys 3,8,# give low input on P0,P2,P3
r3 low output -> c2 pulled low -> keys 2,5,0 give low input on P0,P1,P3
r4 low output -> c1 pulled low -> keys 1,4,6 give low input on P0,P1,P2

Example: r3 ia low output: press 2 -> r1 low input
press 5 -> r2 low input
press 0 -> r4 low input

This scheme could very easily be expanded to support more switches while
reducing the
required I/O lines. It just takes a few extra diodes (e.g 1N4148).

Greetings peter

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-06-30 06:10
    It is actually possible to have 72 switches read by 4 io pins, using a heap
    of diodes, and pulling each pin high or low to each other pin, and pulling
    each pin high or low (5v or 0v externally). Pulling 2 lines or 3 lines low /
    high in all combinations gives 72 possibilities. It would be code hungry,
    and messy to make but it can be done.
    Chris

    Original Message
    From: Peter Verkaik <peterverkaik@b...>
    To: <basicstamps@yahoogroups.com>
    Sent: Friday, June 29, 2001 6:47 PM
    Subject: [noparse][[/noparse]basicstamps] RE: matrix keypad


    > Hi,
    >
    > As an addition to Tracy Allen's matrix schematic consider this:
    >
    > Normal 3x4 matrix:
    >
    > } | |
    > ---o
    o
    o--- r1 P0
    > | | |
    > ---o
    o
    o--- r2 P1
    > | | |
    > ---o
    o
    o--- r3 P2
    > | | |
    > ---o
    o
    o--- r4 P3
    > | | | switches between row and column at o character
    > c1 c2 c3 requires 7 I/O lines for 12 switches
    > P7 P6 P5
    >
    >
    > Adding 4 diodes
    >
    > / / / /
    > \ \ \ \ 4x pullup resistor 10k
    > / / / /
    > } | | |
    > 1} 2| 3| D1/|
    > ---o
    o
    o
    +--- r1 P0
    > | | | |
    > 4} 5| D2/| 7|
    > ---o
    o
    +
    o--- r2 P1
    > | | | |
    > 6} D3/| 8| 9|
    > ---o
    +
    o
    o--- r3 P2
    > | | | |
    > D4/} 0| #| *|
    > ---+
    o
    o
    o--- r4 P3 diodes between row (cathode) and column
    > (anode) at /
    > | | | | switches between row and column at o
    > character
    > c1 c2 c3 c4 requires 4 I/O lines for 12 switches
    >
    >
    > Now only the rows are connected to the stamp. Make one row a low output
    > (others are input) and
    > check the remaining inputs. Then make the next row a low output etc.
    > r1 low output -> c4 pulled low -> keys 7,9,* give low input on P1,P2,P3
    > r2 low output -> c3 pulled low -> keys 3,8,# give low input on P0,P2,P3
    > r3 low output -> c2 pulled low -> keys 2,5,0 give low input on P0,P1,P3
    > r4 low output -> c1 pulled low -> keys 1,4,6 give low input on P0,P1,P2
    >
    > Example: r3 ia low output: press 2 -> r1 low input
    > press 5 -> r2 low input
    > press 0 -> r4 low input
    >
    > This scheme could very easily be expanded to support more switches while
    > reducing the
    > required I/O lines. It just takes a few extra diodes (e.g 1N4148).
    >
    > Greetings peter
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed with. Text in the Subject
    and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-07-01 11:33
    Hi Chris,

    >It is actually possible to have 72 switches read by 4 io pins, using a heap
    >of diodes, and pulling each pin high or low to each other pin, and pulling
    >each pin high or low (5v or 0v externally). Pulling 2 lines or 3 lines low
    /
    >high in all combinations gives 72 possibilities. It would be code hungry,
    >and messy to make but it can be done.
    >Chris

    Would you care to elaborate a bit more?
    Following your scheme I calculate:
    1 output + 3 inputs give 4 possibilities to detect 3 switches -> 12
    switches (my scheme)
    2 outputs + 2 inputs give 6 possibilities to detect 2 switches -> 12
    switches
    3 outputs + 1 input give 4 possibilities to detect 1 switch -> 4
    switches
    So I come no further than 28.

    How many diodes would be required for your 72 switches and how would they
    electrically connect using only 4 I/O lines?

    Please elaborate.

    Greetings peter
  • ArchiverArchiver Posts: 46,084
    edited 2001-07-02 10:16
    I agrre with your message, but you can use 1 switch to pull 3 inputs low or
    high in all combinations, this gives heaps more. You can then pull 2 inpits
    high / low in all combinations. You can then pull each pin high (to external
    5v) in all combinations (ie, 2 and three at a time) gives 15, then pull them
    low gives another 15.
    If I get time, I will try to come up with a clear explanation. A freind and
    I were challenging each other recently and we came up with approx 72.
    Like I said, it sure would be messy though, especially with code.
    Regards, Chris.

    Original Message
    From: Peter Verkaik <peterverkaik@b...>
    To: <basicstamps@yahoogroups.com>
    Sent: Sunday, July 01, 2001 6:33 PM
    Subject: [noparse][[/noparse]basicstamps] RE: matrix keypad


    > Hi Chris,
    >
    > >It is actually possible to have 72 switches read by 4 io pins, using a
    heap
    > >of diodes, and pulling each pin high or low to each other pin, and
    pulling
    > >each pin high or low (5v or 0v externally). Pulling 2 lines or 3 lines
    low
    > /
    > >high in all combinations gives 72 possibilities. It would be code hungry,
    > >and messy to make but it can be done.
    > >Chris
    >
    > Would you care to elaborate a bit more?
    > Following your scheme I calculate:
    > 1 output + 3 inputs give 4 possibilities to detect 3 switches -> 12
    > switches (my scheme)
    > 2 outputs + 2 inputs give 6 possibilities to detect 2 switches -> 12
    > switches
    > 3 outputs + 1 input give 4 possibilities to detect 1 switch -> 4
    > switches
    > So I come no further than 28.
    >
    > How many diodes would be required for your 72 switches and how would they
    > electrically connect using only 4 I/O lines?
    >
    > Please elaborate.
    >
    > Greetings peter
    >
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed with. Text in the Subject
    and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-07-02 12:29
    Hi Chris,

    >I agrre with your message, but you can use 1 switch to pull 3 inputs low or
    >high in all combinations, this gives heaps more. You can then pull 2 inpits
    >high / low in all combinations. You can then pull each pin high (to
    external
    >5v) in all combinations (ie, 2 and three at a time) gives 15, then pull
    them
    >low gives another 15.
    >If I get time, I will try to come up with a clear explanation. A freind and
    >I were challenging each other recently and we came up with approx 72.
    >Like I said, it sure would be messy though, especially with code.
    >Regards, Chris.

    This clearifies somewhat. Instead of looking at single inputs to detect one
    switch
    you look at the inputs as a group. So fot the 1 output with 3 inputs you get
    8 possibilities
    (3 bits equals 8 states) to detect switches. The all-ones state (i.e 111) is
    however
    used to indicate that no switch is pressed, so I am left with 7.
    Following this scheme I calculate:

    1 output + 3 inputs give 4 possibilities to detect 7 switches -> 28
    switches
    2 outputs + 2 inputs give 6 possibilities to detect 3 switches -> 18
    switches
    3 outputs + 1 input give 4 possibilities to detect 1 switch -> 4
    switches
    So I come no further than 50.

    Also you did not say how many diodes are necessary and how they connect.
    I am not that interested in the code, but a schematic would be nice.

    Greetings peter
  • ArchiverArchiver Posts: 46,084
    edited 2001-07-02 12:39
    Hi Chris,

    I believe the following is also part of your scheme:

    0 outputs + 4 inputs give 1 possibility to derect 15 switches -> 15 switches

    This would give a total of 65 switches.

    Anxious to see your schematic.

    Greetings peter
  • ArchiverArchiver Posts: 46,084
    edited 2001-07-02 20:11
    Another way to to get more combinations with few keys is to use key
    combinations (control-alt-delete!. So with four keys, each with two
    states (open and closed):
    4 single keys
    6 two-key combinations
    4 three-key
    1 four-key
    ---
    15 total

    There is also of course one way to get zero keys, giving 16 binary
    states. A 16 to 4 encoder chip (available in standard CMOS or TTL)
    can do that logic function, to map 16 individual keys into 4 bits at
    the output. Or it can be done with diodes. But I don't see how to
    get 72 out of it!

    Unless, if each switch can have more than 2 states, then the
    possibilities multiply. Say, each switch is a SPDT with center off,
    so it can be either high, low or open. Then there are 9 combinations
    with 2 of these, 27 with three, and 81 with four.

    SPDT center off
    +5
    o
    <---o--/\/\---P0 stamp
    com
    o 10k



    I can imagine that there would be a device, call it a "81 to 4
    ternary decoder" (using diode?) that would be able to decode all of
    those states (call the device a "microprocessor"?!).

    The Stamp itself can test ternary switch positions, using the fact
    that the capacitance of a floating input will hold a charge when a
    pin is switched from output to input. To test for the three
    different states, the stamp pin is made a LOW output, then
    immediately back to an input. If the input reads high, then the
    switch is in the upper position. If input reads low, then another
    test is needed. Make the pin output HIGH briefly and then back to
    input. If the pin reads low, the switch is in the lower position; if
    it reads high, the switch is in the middle, open position.

    FWIW, a 4x4 keypad (each key with two states) allows 120 2-key combinations.

    -- best regards
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
    mailto:tracy@e...



    >Hi Chris,
    >
    >>I agrre with your message, but you can use 1 switch to pull 3 inputs low or
    >>high in all combinations, this gives heaps more. You can then pull 2 inpits
    >>high / low in all combinations. You can then pull each pin high (to
    >external
    >>5v) in all combinations (ie, 2 and three at a time) gives 15, then pull
    >them
    >>low gives another 15.
    >>If I get time, I will try to come up with a clear explanation. A freind and
    >>I were challenging each other recently and we came up with approx 72.
    >>Like I said, it sure would be messy though, especially with code.
    >>Regards, Chris.
    >
    >This clearifies somewhat. Instead of looking at single inputs to detect one
    >switch
    >you look at the inputs as a group. So fot the 1 output with 3 inputs you get
    >8 possibilities
    >(3 bits equals 8 states) to detect switches. The all-ones state (i.e 111) is
    >however
    >used to indicate that no switch is pressed, so I am left with 7.
    >Following this scheme I calculate:
    >
    >1 output + 3 inputs give 4 possibilities to detect 7 switches -> 28
    >switches
    >2 outputs + 2 inputs give 6 possibilities to detect 3 switches -> 18
    >switches
    >3 outputs + 1 input give 4 possibilities to detect 1 switch -> 4
    >switches
    >So I come no further than 50.
    >
    >Also you did not say how many diodes are necessary and how they connect.
    >I am not that interested in the code, but a schematic would be nice.
    >
    >Greetings peter
  • ArchiverArchiver Posts: 46,084
    edited 2001-07-02 20:30
    Hi Tracy,

    >There is also of course one way to get zero keys, giving 16 binary
    >states. A 16 to 4 encoder chip (available in standard CMOS or TTL)
    >can do that logic function, to map 16 individual keys into 4 bits at
    >the output. Or it can be done with diodes. But I don't see how to
    >get 72 out of it!

    The encoder solution does not allow for simultaneuos keypresses as it is a
    priority encoder. I figured
    the same out with diodes, but the chip would be better. All this however
    does not involve a
    matrix keypad, which was the starting point: many switches without (complex)
    hardware.
    If I want many switches I could also hook up a PS/2 keynoard with on eof
    those PAKs.

    I mentioned the diode solution to save 3 or 4 I/O lines which are more
    valuable than the 4 diodes.
    I too don't see how Chris can get 72 switches in a matrix circuitry using
    only 4 I/O lines.
    I await his schematic.

    Greetings peter
  • ArchiverArchiver Posts: 46,084
    edited 2001-07-03 04:23
    What is the best way to get a schematic to interested people (when I get
    time to do one) ?
    Regards,
    Chris

    Original Message
    From: Peter Verkaik <peterverkaik@b...>
    To: <basicstamps@yahoogroups.com>
    Sent: Monday, July 02, 2001 7:29 PM
    Subject: [noparse][[/noparse]basicstamps] RE: matrix keypad


    > Hi Chris,
    >
    > >I agrre with your message, but you can use 1 switch to pull 3 inputs low
    or
    > >high in all combinations, this gives heaps more. You can then pull 2
    inpits
    > >high / low in all combinations. You can then pull each pin high (to
    > external
    > >5v) in all combinations (ie, 2 and three at a time) gives 15, then pull
    > them
    > >low gives another 15.
    > >If I get time, I will try to come up with a clear explanation. A freind
    and
    > >I were challenging each other recently and we came up with approx 72.
    > >Like I said, it sure would be messy though, especially with code.
    > >Regards, Chris.
    >
    > This clearifies somewhat. Instead of looking at single inputs to detect
    one
    > switch
    > you look at the inputs as a group. So fot the 1 output with 3 inputs you
    get
    > 8 possibilities
    > (3 bits equals 8 states) to detect switches. The all-ones state (i.e 111)
    is
    > however
    > used to indicate that no switch is pressed, so I am left with 7.
    > Following this scheme I calculate:
    >
    > 1 output + 3 inputs give 4 possibilities to detect 7 switches -> 28
    > switches
    > 2 outputs + 2 inputs give 6 possibilities to detect 3 switches -> 18
    > switches
    > 3 outputs + 1 input give 4 possibilities to detect 1 switch -> 4
    > switches
    > So I come no further than 50.
    >
    > Also you did not say how many diodes are necessary and how they connect.
    > I am not that interested in the code, but a schematic would be nice.
    >
    > Greetings peter
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed with. Text in the Subject
    and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-07-03 07:20
    Hi Chris,

    See message from Russ Miller: No more attachments.
    Preferable drawing formats are BMP, TIF or GIF.

    Greetings peter
Sign In or Register to comment.