Shop OBEX P1 Docs P2 Docs Learn Events
Issue with 4x4 input matrix? — Parallax Forums

Issue with 4x4 input matrix?

thTechiethTechie Posts: 7
edited 2012-07-24 16:04 in Propeller 1
Hi everybody!

Recently I got a couple of the 4x4 input matrices from the store (http://www.parallax.com/Store/Accessories/HumanInterfaceDevices/tabid/822/CategoryID/90/List/0/SortField/0/Level/a/ProductID/739/Default.aspx). I got them, hooked em up to the prop just as it says in the prop object that's given on that page. I was quite disappointed to find that only some of the buttons actually work right. I thought that it might just be a bad one, so I tried the second one I got, same results. So I thought it might be a bad pin or something on the prop (although all of the pins work depending upon the combo), so I tried it with a different prop, same results. So I tried different pins (because each of the buttons actually responds, but some don't go on and off like they should [they just keep alternating states], and others make it look like more than one button is being pushed at a time), same results. I even tried ditching the matrix and just connecting a wire and the rapid switching of states was gone, but oddly the multiple button pushes issue was still there, on both different props and different pins. This made me think it was possibly the code, but it's pretty easy code with not too much too it, so I really have no idea what's happening. Anybody out there have any suggestions on other things to try or is there some like magic way to get these to work or does anyone have their own experiences with these?

TL;DR: Can't get them to work, no matter what I do, they're hooked up exactly as the object for them says to hook them up and I've changed pins, and props with no luck. Suggestions?

Thanks a lot for anyone that can shed some light on this very frustrating situation!

Kenny

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2011-12-05 05:44
    Feel free to explore ideas that might fix this, but at the same time you might contact Parallax Customer Service. They want to know if there are defective parts or wrong documentation out there.

    There is a possibility that the connector is not hooked up right and you have high resistance in your wiring. It would not hurt to double check that.
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-12-05 13:12
    Hmm .. I guess you have some problems with the capacity or maybe the resistance in the keypads themselves. Propably the contacts inside of the keypad simply have been oxidated.

    I'd try to use a common way to run the keypad by pulling the input-lines low via resistor and drive the row-lines high by propeller pins. The change in the driver is not to much!
    If this works the capacity-read-method might be unreliable depending on the type of keypad over the age.
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-12-05 15:10
    thTechie: Firstly, welcome to the fabulous prop world.

    I am presuming you are using pasm (assembler). I have not looked at the code you are referring to. However, I have some experience with similar keypads and found that the capacitance affects the results. So to summarise, after you set the outputs, place a few nops in the code before you readback the inputs. That way you should avoid the problem.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2011-12-05 15:18
    It is unlikely an issue of a faulty product. As a former employee, I can attest to the quality of products Parallax designs and carries. What is likely at issue is it was either connected wrong or an issue with the driver. Membrane keypads are about as simple mechanically as you can get, there are 4 columns and 4 rows and when a keypress occurs one of the columns is shorted to the corresponding row for that key.

    Detecting the keypress requires setting a single row or column to a different value and detecting that value on the column or row (notice the reversal of the names, if you output on the row you read the column and vice versa).

    A quick look at the documentation and I do see a possible issue, they don't specify any biasing resistors on the input. I would put some weak pull-ups on the input lines to bias the inputs (without them the inputs are left floating which is generally considered a no-no).

    So put a 10kOhm resistor on each input pin and tie it to 3.3V, place a 0 on one of the outputs and read the inputs, if any of the inputs are 0, the corresponding key is currently depressed. Repeat this for each output line (make it 0 while making all other outputs to 1) and you will get a matrix of all the buttons that are pressed during the scan sequence.

    If you want to gain a better understanding of the keypad you can use a multimeter in continuity mode and explore the column-row-key mapping. While holding down a key, the multimeter will beep when you are probing its column and row line.
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-12-05 15:37
    thTechie,

    Welcome to the forum! ... Sorry to hear of your keyboard troubles... If I can ask a few questions, how far is the Keypad from the I/O's on the propeller? ...and are you positive you have pin1 on the keyboard corresponding with the correct I/O's? (It is common to get the order reversed.) How much electrical noise is in your environment?

    Since this object works without any external components, it uses the I/O's themselves as capacitors. first the I/O is made an OUTPUT and charges, then the I/O is made an input and read... If a button is pressed, the I/O becomes discharged and is detected.

    Multiple button presses are allowed with
    the understanding that “BOX entries can be confused. An example of a
    BOX entry... 1,2,4,5 or 1,4,3,6 or 4,6,*,# etc. where any 3 of the 4
    buttons pressed will evaluate the non pressed button as being pressed,
    even when they are not. There is no danger of any physical or
    electrical damage, that s just the way this sensing method happens to
    work.
  • Martin_HMartin_H Posts: 4,051
    edited 2011-12-05 15:48
    I just bought one of these, but I plan to use the single pin interface. You put resistors along the rows and columns and then use an rc circuit to measure the voltage. The only thing you give up is that you can only detect a single key, while the row column scanning can detect any number of keys.
  • NikosGNikosG Posts: 705
    edited 2011-12-05 15:56
    From a persolal experience using the 4x4 Matrix mebrane keypad (#27899) when I needed to add a cable extention the keypad changed its behavior.
    attachment.php?attachmentid=87433&d=1323128184
    I needed to write a new code in order to overcome the problem with the cable extention!
  • thTechiethTechie Posts: 7
    edited 2011-12-05 17:23
    Hey everyone! Thanks for all the responses. I tried Paul's method first and either I modified the SPIN code wrong or something happened because it wouldn't give me anything other than all 1's. Then I tried MagIO2's suggestion and tied the input lines low with a 10k resistor and it works (and without modifying the standard object too)!

    I'll keep that in mind NikosG for when I actually decide to move this project off a breadboard.

    Thanks again, you guys were great!
    Kenny
  • lardomlardom Posts: 1,659
    edited 2011-12-05 17:43
    Continuity tests with a multimeter is necessary to reveal faults with your keypad. Do the continuity tests first. Otherwise you have to consider that your circuit or your code could be faulty.
  • camelot2camelot2 Posts: 54
    edited 2011-12-07 14:30
    After many days debugging my PropBasic program to sense the Parallax 4x4 keypad, I finally buzzed out the keypad. This is what I found:


    1 (4,8)
    2 (3,8)
    3 (2,8)
    A (1,8)
    4 (4,7)
    5 (3,7)
    6 (2,7)
    B (1,7)
    7 (4,6)
    8 (3,6)
    9 (2,6)
    C (1,6)
    * (4,5)
    0 (3,5)
    # (2,5)
    D (1,5)

    (y,x) = connector pins shorted
    when character is pressed

    The above does not agree with the documentation "Figure 1: Matrix Keypad Connections" titled "4x4 Matrix Membrane Keypad (#27899)"
    Can someone confirm my results? thanks - Dave
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-12-07 14:35
    camelot2,

    With the exception of your Columns being reversed, It does confirm correctly... you have the pin order swapped :-)

    i.e. Your Pin 8 is actually Pin 1 ... same for the rest...

    8 = 1
    7 = 2
    6 = 3
    5 = 4
    4 = 5
    3 = 6
    2 = 7
    1 = 8
  • camelot2camelot2 Posts: 54
    edited 2011-12-07 15:11
    hi Beau, if what you say is correct then the connector at the end of the cable is mislabled. Do you agree? Dave
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-12-07 15:21
    I don't have a keypad directly in front of me. I do know that we sold another keypad prior to this one, and the one we currently sell is supposed to be compatible. ...and it is, but someone may have somehow overlooked this type of reversal.

    Is there a marking that indicates pin number 1, and if so, can you take a photo and double check your pin-out configuration ... I'll compare that to the older keypad and see if there is a discrepancy of either pin #1 and/or the column reversal. ...and see how that looks in the documentation.

    Thanks
  • camelot2camelot2 Posts: 54
    edited 2011-12-07 15:42
    the connector is marked, 8 on the left side and 1 on the right side when the keypad is facing you and the characters are on top just like the " Figure 1: Matrix Keypad Connections". Dave
  • camelot2camelot2 Posts: 54
    edited 2011-12-15 05:22
    hi Beau, just wondering what you found out - Dave
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2011-12-15 07:01
    I contacted the Product owner and they were looking into this.

    There was a change to the pin order in the documentation in April of this year....
    ...This should not have been changed, it was correct the first time. I think the figure in the referenced BASIC Stamp code was incorrect because it was in reference to an older keypad that we used, and that reference should have been updated instead.

    Reference thread:
    http://forums.parallax.com/showthread.php?131054-Keypad-Documentation-Error&highlight=27899

    From what I can determine, initially (when the code was written) we used a different 4x4 keypad. Since then we have sourced a different 4x4 keypad that has a slightly different pin-out. The 'Quick-Fix' to keep compatibility was to swap the pin order AND swap the column order. It appears that the additional column swap was not observed, but that is the difference between the 'old' keypad, and the 'current' keypad that we are using. If you look on the back of the current 4x4 keypad, there is a small indicator denoting pin number 1.

    Determine which Keypad you have:
    Old Keypad: pins 1 and 8 are shorted with a button press of "A"
    New Keypad: pins 1 and 8 are shorted with a button press of "1"

    Old keypad pinout reference:
    http://embrace.grayhill.com/embrace/IMAGES/PDF/D-06-09.pdf
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-17 00:17
    Kenny,

    I also had trouble with a matrix keypad. The wires I used to connect the keypad to the Prop interfered with Beau's driver. I added 0.1 caps to the columns (or it may have been the rows) and it worked great. I suggested this same fix to another forum member and it fix their problem as well. I think it's worth a try in your case.

    This method might even work for Niko's long wires?
  • NikosGNikosG Posts: 705
    edited 2012-07-24 16:04
    Recently I received a mail in order to help a user of this forum overcome the problem with the cable extention.
    Here is the the modified "KeypadDemo1" code for the cable extension that Iused (post#8).
    {{ 4x4 KeypadNikosDemo1.spin
    Returns the entire 4x4 keypad matrix into a single WORD variable indicating which buttons are pressed. }}
    
    '-----------------Extention cable-----------
    '  1-> ---12   2-> ---14   3-> ----7   A-> ----3
    '  4-> --192   5-> --224   6-> --112   B-> ---48  
    '  7-> -3072   8-> -3584   9-> -1792   C-> --768  
    '  *-> 49152   0-> 57344   #-> 61440   D-> 45056
    
    
    '-----------------original cable-----------
    '  1-> ----8   2-> ----4   3-> ----2   A-> ----1
    '  4-> --128   5-> ---64   6-> ---32   B-> ---16  
    '  7-> -2048   8-> -1024   9-> --512   C-> --256  
    '  *-> 32768   0-> 16384   #-> -8192   D-> -4096  
      
    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    OBJ
      text : "Parallax Serial Terminal"
      KP   : "4x4 Keypad Reader"
    
    VAR
      word  keypad
      word PressedKey
      byte Counter
     
    PUB start
      ' Start PST
      text.start(115200)
       text.clear
    
      repeat
        keypad := KP.ReadKeyPad     '<-- One line command to read the 4x4 keypad
         
         'text.dec(keypad)        'Display RAW keypad value
             text.moveLeft(2) 'in order to do tests
        PressedKey:= MiniKeyboardPressedKey (keypad)
        text.dec(PressedKey)        'Display RAW keypad value  
    
    PUB MiniKeyboardPressedKey (n)| kc[16],kv[16] ,pc
    ' this function calculates 
    
    '-----------------original cable-----------
    '  1-> ----8   2-> ----4   3-> ----2   A-> ----1
    '  4-> --128   5-> ---64   6-> ---32   B-> ---16  
    '  7-> -2048   8-> -1024   9-> --512   C-> --256  
    '  *-> 32768   0-> 16384   #-> -8192   D-> -4096
    
    'kc[1]:= 8      '%0000000000001000    1
    'kc[2]:= 4      '%0000000000000100    2
    'kc[3]:= 2      '%0000000000000010    3
    'kc[4]:= 1      '%0000000000000001    A
    'kc[5]:= 128    '%0000000010000000    4
    'kc[6]:= 64     '%0000000001000000    5
    'kc[7]:= 32     '%0000000000100000    6
    'kc[8]:= 16     '%0000000000010000    B
    'kc[9]:= 2048   '%0000100000000000    7
    'kc[10]:= 1024  '%0000010000000000    8
    'kc[11]:= 512   '%0000001000000000    9
    'kc[12]:= 256   '%0000000100000000    C
    'kc[13]:= 32768 '%1000000000000000    0
    'kc[14]:= 16384 '%0100000000000000    *
    'kc[15]:= 8192  '%0010000000000000    #
    'kc[16]:= 4096  '%0001000000000000    D
    
    
    '-----------------Extention cable-----------
    '  1-> ---12   2-> ---14   3-> ----7   A-> ----3
    '  4-> --192   5-> --224   6-> --112   B-> ---48  
    '  7-> -3072   8-> -3584   9-> -1792   C-> --768  
    '  *-> 49152   0-> 57344   #-> 61440   D-> 45056
    
    
    'kc[1]:= 12       '%0000000000001100    1
    'kc[2]:= 14       '%0000000000001110    2
    'kc[3]:= 7        '%0000000000000111    3
    'kc[4]:= 3        '%0000000000000011    A
    'kc[5]:=  192     '%0000000011000000    4
    'kc[6]:=  224     '%0000000011100000    5
    'kc[7]:= 112      '%0000000001110000    6
    'kc[8]:= 48       '%0000000000110000    B
    'kc[9]:= 3072     '%0000110000000000    7
    'kc[10]:= 3584    '%0000111000000000    8
    'kc[11]:= 1792    '%0000011100000000    9
    'kc[12]:= 768     '%0000001100000000    C
    'kc[13]:= 49152   '%1100000000000000    *
    'kc[14]:= 57344   '%1110000000000000    0
    'kc[15]:= 61440   '%1111000000000000    #
    'kc[16]:= 45056   '%1011000000000000    D
    
    
    kc[1]:= %0000000000001100
    kc[2]:= %0000000000001110
    kc[3]:= %0000000000000111
    kc[4]:= %0000000000000011
    kc[5]:= %0000000011000000
    kc[6]:= %0000000011100000
    kc[7]:= %0000000001110000
    kc[8]:= %0000000000110000
    kc[9]:= %0000110000000000
    kc[10]:=%0000111000000000
    kc[11]:=%0000011100000000
    kc[12]:=%0000001100000000
    kc[13]:=%1100000000000000
    kc[14]:=%1110000000000000
    kc[15]:=%1111000000000000
    kc[16]:=%1011000000000000
    
    
    'pc:= " " ' nul
    
    'kv[1]:= "1"
    'kv[2]:= "2"  
    'kv[3]:= "3" 
    'kv[4]:= "A" 
    'kv[5]:= "4" 
    'kv[6]:= "5" 
    'kv[7]:= "6" 
    'kv[8]:= "B" 
    'kv[9]:= "7" 
    'kv[10]:= "8" 
    'kv[11]:= "9"  
    'kv[12]:= "C" 
    'kv[13]:= "*" 
    'kv[14]:= "0" 
    'kv[15]:= "#" 
    'kv[16]:= "D" 
    'pc:=999
    kv[1]:= 1
    kv[2]:= 2  
    kv[3]:= 3 
    kv[4]:= 10   'A
    kv[5]:= 4 
    kv[6]:= 5 
    kv[7]:= 6 
    kv[8]:= 11  'B
    kv[9]:= 7 
    kv[10]:= 8 
    kv[11]:= 9  
    kv[12]:= 12  'C
    kv[13]:= 14  '*
    kv[14]:= 0  '0
    kv[15]:= 15  '#
    kv[16]:= 13  'D
    
    
    'repeat  
     repeat counter from 1 TO 16
      if n == kc[counter]
        pc :=kv[counter] 
    result:=pc   
    
    
    
    DAT
    {{
    &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    &#9474;                                                   TERMS OF USE: MIT License                                                  &#9474;                                                            
    &#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9508;
    &#9474;Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation    &#9474; 
    &#9474;files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,    &#9474;
    &#9474;modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software&#9474;
    &#9474;is furnished to do so, subject to the following conditions:                                                                   &#9474;
    &#9474;                                                                                                                              &#9474;
    &#9474;The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.&#9474;
    &#9474;                                                                                                                              &#9474;
    &#9474;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE          &#9474;
    &#9474;WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR         &#9474;
    &#9474;COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,   &#9474;
    &#9474;ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                         &#9474;
    &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
    }}    
    

    As you can see I have replaced the original values of KV[16] array with other values. However I don't know if these values work properly with all the other cables extensions with different length.
Sign In or Register to comment.