Shop OBEX P1 Docs P2 Docs Learn Events
Does the 4X4 matrix keypad need diodes to install an extension cable? (Solved by work-around) — Parallax Forums

Does the 4X4 matrix keypad need diodes to install an extension cable? (Solved by work-around)

mikeologistmikeologist Posts: 337
edited 2017-11-23 23:22 in Propeller 1
I'm building my 4X4 matrix keypad to a 5X5. The first step for me is to add an extension cable that lets me wire in the extra two pins needed.
The issue I'm having is that adding a simple extension cable causes the 7 key and the * key to both read as *.
I have installed the resistor and pull-down resistor needed, but I'm wondering if adding some 1N4148 diodes to the keypad inputs would eliminate this issue?
If that's likely to help I can just replace the orange jumpers 0-4 with the diodes, or should I do 5 up and 5 down?
I've attached pictures and the modified files.

**After everyone's help, I just ended up making a keypad that doesn't leak**
**Pictures and code below**
**Thanks everyone, this was a huge help**
«1

Comments

  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2017-11-20 23:50
    You need ~10-15k pull-downs on the lines for the keypad. They are notorious for noise that will push faulty reads. See this thread where I went through the same exact thing. I added SMT resistor pull-downs on my Prop Mini and never had an issue after that.

    http://forums.parallax.com/discussion/152388/resolved-buggy-reads-from-4x4-keypad-to-propeller-using-4x4-keypad-reader-spin
  • Also, if I plug the keypad in directly to the above setup without the extension it works just fine. I have tried different cables and connectors in an attempt to eliminate the problem.
  • You need pull-downs on the lines for the keypad. They are notorious for noise that will push faulty reads. See this thread where I went through the same exact thing. I added SMT resistor pull-downs on my Prop Mini and never had an issue after that.

    http://forums.parallax.com/discussion/152388/resolved-buggy-reads-from-4x4-keypad-to-propeller-using-4x4-keypad-reader-spin

    I have them installed, see the picture. That is unless I've done so improperly, which is entirely possible.

  • Yeah, sorry, I edited my response, but what values are you using? Hard to read the color codes.
  • perhaps the resistances are wrong, but I went by the guide. 1K and 220 If I remember correctly.
  • That may be it. 220 is ok for inline, but 1k pull downs would be a problem. Changing to 10k or a little above (I used 12k) should help.
  • That may be it. 220 is ok for inline, but 1k pull downs would be a problem. Changing to 10k or a little above (I used 12k) should help.
    COOL,
    I will do so in just a bit and post my results. Thanks a bunch for your help.
  • jmgjmg Posts: 15,173
    Also, if I plug the keypad in directly to the above setup without the extension it works just fine. I have tried different cables and connectors in an attempt to eliminate the problem.

    Adding a cable adds capacitance, which can mean you need more settling time on any Scan code.

  • In 5x5 Keypad Reader.spin:

    Line 87 shows:
        keypad += ina[5..10] 
    

    I believe Line 87 should be:
        keypad += ina[5..9] 
    


    Also, there is a little bit of parallax effect in your picture (no pun intended), so it is hard to trace some wires to the FLiP. The bottom most wire almost looks like it is plugged in to P1 not actually P0, but otherwise, I don't see any wiring issues apart from resistor values.

    According to the 4x4 keypad docs, the inline resistors should be 1k which would reduce line capacitance if that is the issue; the pull downs are not listed in the Parallax document, but listed in several forum threads as a fix.
  • Would like to bring this to your attention too http://learn.parallax.com/tutorials/language/blocklyprop/4x4-keypad-7-segment-led

    Ken Gracey
  • Based on your advise and the resistors I had on hand I settled on 10k inline and 10k pull-down and it did the trick. Thank You :smile:

    However, when I change line 87 from 10 to 9 I lose keys. the bottom row doesn't show up because everything is shifted by one somewhere else in my code.
    I'll comb back through and try to find the other mistake that's responsible.

    That was in fact a parallax effect and the pins were properly aligned.

    I updooted your helpful answers :smile:
  • Ken Gracey wrote: »
    Would like to bring this to your attention too http://learn.parallax.com/tutorials/language/blocklyprop/4x4-keypad-7-segment-led

    Ken Gracey

    Sure appreciate it. In fact I built this from the BOE tutorial, but the resistance values pictured were different than what worked.
    Thanks to WBA Consulting though, I'm back on track.
  • Just to share, here is the bridge interface that I made to join the 9 new keys.
    I will create a new thread with pictures, diagrams, and code when I complete the upper keys in the next couple days.
    1656 x 3915 - 1M
  • Cluso99Cluso99 Posts: 18,069
    The 10K series/inline are going to be too large due to your 10K pulldown. Typically we use 10:1 ratios, but you could get away with anything below 5K series.

  • Cluso99 wrote: »
    The 10K series/inline are going to be too large due to your 10K pulldown. Typically we use 10:1 ratios, but you could get away with anything below 5K series.

    With the 10k pulldown and 1k inline I still got the false reading, so I subbed the inline for 10k and it worked great. I have some 2.2k I could put in there instead to get me close to that ratio. I can also bump the pulldown to 15k when my next box-o-junk shows up.

    What does that ratio preserve or represent?
  • Cluso99 wrote: »
    The 10K series/inline are going to be too large due to your 10K pulldown. Typically we use 10:1 ratios, but you could get away with anything below 5K series.

    With the 10k pulldown and 1k inline I still got the false reading, so I subbed the inline for 10k and it worked great. I have some 2.2k I could put in there instead to get me close to that ratio. I can also bump the pulldown to 15k when my next box-o-junk shows up.

    What does that ratio preserve or represent?

    Realized my mistake. With the 10k pulldown I had 220 inline. Switching now to your spec of 10k pulldown and 1k inline.
  • Cluso99Cluso99 Posts: 18,069
    Depends on the full circuit and timing. The 10:1 forms a voltage divider where the "1" has little effect. In the circuit I am not sure you even require a 1K (or 220R). I haven't checked the diagrams BTW.
  • Cluso99 wrote: »
    Depends on the full circuit and timing. The 10:1 forms a voltage divider where the "1" has little effect. In the circuit I am not sure you even require a 1K (or 220R). I haven't checked the diagrams BTW.

    Thank you for explaining that.

    The leaky keyboard just bothers me.
    The more I thought about using diodes the more I realized I just need to toss the whole keypad and make one that doesn't leak.
    So I made a test model and it works flawlessly without any resistors.

    What I saw as the source of the leaks was the unrestricted hot bus that was connecting 4 keys. I believe that the polarity switch allows the signal to go down the intended line and any other well grounded neighbors that share the bus.
    My solution was to use 1N4148 diodes off of the hot bus to every button.

    Works like a charm and I got to test out my wire wrapping skills, been a while.

    Attached the modified code.

    What do you all think?
  • Cluso99Cluso99 Posts: 18,069
    Pleased you have it working. And you have learnt a lot to boot :)
  • Cluso99 wrote: »
    Pleased you have it working. And you have learnt a lot to boot :)

    Thanks a bunch for your help. I updated the header for easier searching.

    Ultimately I need a 45 key keyboard.
    In a 2D matrix this will take 14 pins minimum.
    With the use of diodes a third dimension can be added.
    In 3D it could be 3X3X5, only use 11 pins, and still allow for multitouch.
    Then I can turn it into an SPI with a PSoC 42xx.

    I'll post the results of both in a new thread.
  • Using diodes and pull resistors have 63 keys on 6 pins.
    Using 16 resistors have 64 keys on only one pin.
    Using charlieplexing have 72 keys on 9 pins.

    Using a 4024 and two 4051s have 64 keys on three pins and can press more than one key at a time.

    I prefer using a ps2 keyboard.
  • VIRAND wrote: »
    Using diodes and pull resistors have 63 keys on 6 pins.
    Using 16 resistors have 64 keys on only one pin.
    Using charlieplexing have 72 keys on 9 pins.

    Using a 4024 and two 4051s have 64 keys on three pins and can press more than one key at a time.

    I prefer using a ps2 keyboard.

    I would love to see your schematic with the 4024 and 2x 4051s if at all possible, please.

    Charlieplexing takes a lot of clock cycles; that is if I'm reading the code samples properly.

    Using SN74AHCT373N Latches for a 2-bit counter to cycle the 4 inputs and a 74147 encoder I could take my 3D array down to 5 pins.
    It would take about 100 1N4148 diodes, the two ICs mentioned above, and run 42 keys on just 5 pins with multi-touch; this will use very little code.
    Should cost about $9-10.

    This same setup would allow for 8 input pins and 4 outs X 4 pages, netting 128 keys on the same 5 pins.

    You really made me read and think with this post, thanks.

    I would love to use a ps2 keyboard but I need specific keypad and I like to make things :cool:
  • ...details for previous comment...
    Diodes: they encode 8x8 rows and columns in binary, but key 000,000 can't be used because it's the same code as no key.
    Resistors: 8x8 columns connected to series of 1K, rows connected to series of 10K, key press makes a unique resistance from 11K to 88K, much higher for no key.
    Charlieplexing:
    http://forums.parallax.com/discussion/download/94687/CharliePlexing.jpg
    4024 and 4051s: binary counter drives 8row and 8column multiplexers to connect a pin thru (counted & pressed) key, other two pins reset and increment counter.
    PS2 keyboard: often used with propeller and needs 2 pins.
  • Sorry I'm away for a holiday and have no way to post the schematic for the ICs now. The 4051 is interesting as it works as an 8 pole switch (or multiplexer/demultiplexer) even for analog signals, just like how the switches in 4066 work, but in the 4051 one of the eight switches are selected to be on by a 3 bit value. Trying to be helpful without schematic, pins 6,7,8 need to be ground on the 4051. 4024 is simply obvious, it just has clock reset and counting pins.
  • It is very convenient to scan up to 10 lines of a keypad matrix with a 4017 but use something else for the other dimension.
  • VIRAND wrote: »
    Sorry I'm away for a holiday and have no way to post the schematic for the ICs now. The 4051 is interesting as it works as an 8 pole switch (or multiplexer/demultiplexer) even for analog signals, just like how the switches in 4066 work, but in the 4051 one of the eight switches are selected to be on by a 3 bit value. Trying to be helpful without schematic, pins 6,7,8 need to be ground on the 4051. 4024 is simply obvious, it just has clock reset and counting pins.
    VIRAND wrote: »
    It is very convenient to scan up to 10 lines of a keypad matrix with a 4017 but use something else for the other dimension.

    That's very helpful. I get exactly how they're used now, thanks.
    We described very similar applications.
    Also, I forgot about reserved values so I'd have to revise my total to 126.
  • VIRAND wrote: »
    Sorry I'm away for a holiday and have no way to post the schematic for the ICs now. The 4051 is interesting as it works as an 8 pole switch (or multiplexer/demultiplexer) even for analog signals, just like how the switches in 4066 work, but in the 4051 one of the eight switches are selected to be on by a 3 bit value. Trying to be helpful without schematic, pins 6,7,8 need to be ground on the 4051. 4024 is simply obvious, it just has clock reset and counting pins.

    3 to 10 is awesome. use two latches to make a 2 bit counter and you can turn those three inputs into a single clock line. Then simplify it further by combining the concepts as a ripple counter with the first unused pin tied to the reset. The CD4020BE would do nicely and give you 14-1=13 scan pins for the price of 1 clock pin.
    Then we're pretty much in sync for encoding the other end to 3 pins.
    Assuming 10 in reverse, minus reserved values, nets 323 buttons, and I'm guessing around 700 clocks to read and decode with multi-touch.

    Now, If I can synergize a bit further: I love the idea of a single clock pin, but I hate the idea of my tiny propeller having to decode the multi-touch. To that end I'm keeping the output of my keypad decoded.
    Running with that concept I should maximize my inputs.
    For 42 keys I'll make 7 inputs (CD4020BE). 3 outs, and 2 pages for a total of 1+5=6 pins. This config take a single clocked input and produces a 5-bit parallel output. While this may sound less-than-optimized, I estimate that it will only take about 60 clocks to read it with multi-touch.

    You've really pushed me to put together something cool. I can't wait to share the results.
  • Notice that 4017 is a ten counter with decoded outputs, and (4024,4020,4040) are all binary counters that can be decoded to matrix with 4051s or something else. I'm not sure how you use 4020 to feed matrix inputs directly without extra useless counts; it sounds like shift registers would be faster. I can see how 4020 or 4040 can be used with more 4051s then, but with more than one 4051 on a matrix dimension then their pin 6 might have to be used to select which 4051 is currently active and I'm not sure the simplest way but to have an inverter (NOT gate) connected to a counting pin and between the pin 6's of two 4051s which enables switches when low, "inhibits" when high.

    I think 74373 works as a shift register when it's latches are connected like a chain. 74573 almost the same but its pins are in nice order of ins on one side, outs on the other. Other chips I can't recall, are serial in parallel out, and parallel in serial out type shift registers, with which any matrix should be scannable with 4 pins or less. That method maybe a simpler alternative to counting and multiplexing.
  • VIRAND wrote: »
    Notice that 4017 is a ten counter with decoded outputs, and (4024,4020,4040) are all binary counters that can be decoded to matrix with 4051s or something else. I'm not sure how you use 4020 to feed matrix inputs directly without extra useless counts; it sounds like shift registers would be faster. I can see how 4020 or 4040 can be used with more 4051s then, but with more than one 4051 on a matrix dimension then their pin 6 might have to be used to select which 4051 is currently active and I'm not sure the simplest way but to have an inverter (NOT gate) connected to a counting pin and between the pin 6's of two 4051s which enables switches when low, "inhibits" when high.

    I think 74373 works as a shift register when it's latches are connected like a chain. 74573 almost the same but its pins are in nice order of ins on one side, outs on the other. Other chips I can't recall, are serial in parallel out, and parallel in serial out type shift registers, with which any matrix should be scannable with 4 pins or less. That method maybe a simpler alternative to counting and multiplexing.

    I still have to read the rest of the comment again and think about it, but you eliminate the extra counts on a 4020 by shorting the next count to the reset pin. Then if you are running n inputs you run n+1 cycles in the software and ignore the last return. That will restart the cycle with only one extra clock.

  • I just took another look at the 4020 and it's missing so many bits that I can't think of any practical use for it in keyboards or anything else. It needs 16 clocks just to countup once.

    See what I mean about 4020, maybe use 4040 instead.




Sign In or Register to comment.