Shop OBEX P1 Docs P2 Docs Learn Events
using a 4x4 16 btn keypad — Parallax Forums

using a 4x4 16 btn keypad

samsn4samsn4 Posts: 49
edited 2007-11-21 12:24 in Propeller 1
I sure someone has messed with them before, question is how do i 'poll' and pin to wait for a high? the keypad that i have is a Greyhill with 8 pins, one pin per row/colum.


Thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Daniel Mueth
WSIU-TV Master Control

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"Just plug it in and let's see what happens"

Comments

  • HarleyHarley Posts: 997
    edited 2007-11-14 20:41
    samsn4,

    What you need is to provide a unary code (or it's inverse) to the row or column pins of the switch, and read the state of the remaining column or row. If any switch is closed, then a unary code will be read. Then the row and column values need to be converted from unary to binary and combined with one set shifted 2 positions to left for ms and ls half nibbles.

    I have used this on a 4 x 7 set of switches, where the 7 lines are driven also to LED segments. The cathodes of six LEDs are controlled by FETs driven by another port (this was a -871 PIC, but matters none).

    For debouncing I used several LED scan periods for a total of 20 ms (10 * 2 ms LED on time) of switch closed or open. If the code read is steady for the 20 ms, it is considered valid. Takes a bit of code, but is fast compared to human push/release times.

    If you are interested I could supply the PIC code for this operation.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Harley Shanko
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-11-14 23:31
    Dan,
    You'll learn more by understanding how it works and coming up with a strategy than by asking on the board after you've only had it a day.

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting Software
    Southern Illinois University Carbondale, Electronic Systems Technologies
  • DroneDrone Posts: 433
    edited 2007-11-15 04:36
    Dear Daniel,

    1. See these threads about the Propeller and keypad scanning:

    http://forums.parallax.com/showthread.php?p=661586

    http://forums.parallax.com/showthread.php?p=646590

    2. This thread discusses a Propeller object that supports numeric keypads with a PS/2 interface:

    http://forums.parallax.com/showthread.php?p=633302

    3. This BS2 thread cites a Nuts and Volts magazine column No. 22 that supposedly addresses keypad applications complete with code that might easily be ported to spin. But unfortunately the link to the Nuts & Volts article cited in the post is broken.

    http://forums.parallax.com/showthread.php?p=653177

    However, I was able to find the Nuts & Volts No. 22 column on the Parallax Web site. Here are the links:

    Column Text:

    www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol1/col/nv22.pdf

    Accompanying Code:

    www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol1/code/nv22.zip

    4. A hardware keypad decoder solution: E-Lab Digital Engineering Inc. (www.elabinc.com) offers the EDE1144 hardware keypad decoder chip that sells for $7 USD in an 18 pin PDIP RoHS compliant package (www.jameco.com P/N 171970). I belive the EDE1144 chip is a pre-programmed PIC processor. See the E-Lab site (link above) for more info.

    When & if you come up with a solution, please share it with us.

    Good Luck, David
  • DroneDrone Posts: 433
    edited 2007-11-15 05:50
    Daniel, One more thing...

    Attached is a small schematic of a keypad decoder I found somewhere. It uses an analog approach via an A/D converter. You can decode a keypad with only two pins via a delta-sigma A/D. I don't have any code to go with this; I've never implemented it.

    David
    355 x 480 - 29K
  • samsn4samsn4 Posts: 49
    edited 2007-11-16 11:35
    thanks guys, My complete project is updating the electronics in my 1964 Ford Falcon. Alarm, Remote Locks, . . .
    I will be shure to post my code for all. I'm calling it the Prop Car.

    Thanks Again

    edit: added pic of car

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Daniel Mueth
    WSIU-TV Master Control

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    "Just plug it in and let's see what happens"

    Post Edited (samsn4) : 11/16/2007 11:46:53 AM GMT
    600 x 450 - 44K
  • samsn4samsn4 Posts: 49
    edited 2007-11-19 04:26
    OK, here's what i got so far, What am i not doing ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Daniel Mueth
    WSIU-TV Master Control

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    "Just plug it in and let's see what happens"
  • Mike GreenMike Green Posts: 23,101
    edited 2007-11-19 04:57
    Your GetKey logic is completely wrong ... you are trying to read the output pins with the "if outa[noparse][[/noparse] x ] == 1" stuff and that just reads the output register bit. You want to do something like:
    pri keypress
       repeat i from 0 to 3 ' try %1110, %1101, %1011, %0111 in sequence on I/O pins 7 through 4
          repeat j from 0 to 3 ' try looking at I/O pins 3 through 0 for a logic low
             outa[noparse][[/noparse] 7..4 ] := %1111 - |< i
             if ina[noparse][[/noparse] j ] == 0
                return i * 4 + j
       return -1 ' no key closures seen this pass
    
    pri getkey | first
       repeat until keypress == -1 ' wait for no keys pressed
       repeat ' wait for the same scan codes at least 10ms apart
          repeat while (first := keypress) == -1 ' wait for 1st key press
          waitcnt( clkfreq / 100 + cnt ) ' wait for at least 10ms
          repeat while (result := keypress) == -1 ' wait for 2nd key press
          if first == result ' if they're the same, we're done
             return
    
    


    The keypress routine returns the scan code of the first key closure seen.
    The getkey routine calls keypress about every 10ms and returns the
    scan code if the keypress is the same for at least two consecutive calls.
  • OzStampOzStamp Posts: 377
    edited 2007-11-19 05:00
    Hi Dan.

    As Martin H said you need to develop a strategy.. flowchart.
    Pencil down a flowchart as to what is required.
    Once you done stuff like that for years these things Graphically appear in your mind
    If you have a 16 WAY keypad the simplest all digital way is to use 4 outputs
    and 4 inputs...

    There are many way's to scan a Keypad.


    A very common strategy is or could be ..

    1·· >> detect a keypress ( do not care which one)
    ···· This would involve setting all·the ROW pins·high and detecting a HIGH on· any the COLUMN pins

    2 If you have a 1 on any of the COLUMN pins turn off all·ROW PINS
    ·· and now turn on each·ROW pin by itself...

    3· keep track of which ROW pin is high and detect which COLUMN pin is high.

    Some simple math and a lookup table and your away.

    cheers

    Ron Melbourne OZ
  • Brian_BBrian_B Posts: 842
    edited 2007-11-19 05:40
    Heres a little keypad read program I was working on

    VAR
    · long· number

    PUB KeyPadRead | index

    · dira[noparse][[/noparse]16..19]~~
    · dira[noparse][[/noparse]20..23]~
    ·
    ·
    ·
    ·
    ·····
    ···· repeat index from 16 to 19
    ····· outa[noparse][[/noparse]16..19]~
    ····· outa[noparse][[/noparse]index]~~
    ······ if ina[noparse][[/noparse]20] == 1
    ········ number := 10 + index
    ······ if ina[noparse][[/noparse]21] == 1
    ········ number := 30 + index
    ······ if ina[noparse][[/noparse]22] == 1
    ······· number := 50 + index
    ······ if ina[noparse][[/noparse]23] == 1
    ······· number := 70 + index




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Thank's Brian


    www.truckwiz.com

    ·"Imagination is more important than knowledge..." ·· Albert Einstein

    http://www.diycalculator.com/subroutines.shtml· My favorite website ( Bet you can't guess why)


    Post Edited (Brian Beckius) : 11/19/2007 6:31:44 AM GMT
  • DroneDrone Posts: 433
    edited 2007-11-21 12:16
    Attached is my 4X4 keypad scanner/decoder; tested OK. Description:

    4X4 Keypad scan demo, key scan codes appear on a debug LCD.
    This code is written top-down to illustrate the keypad scan process.
    There is an option to output key-clicks or beeps to a pin; tested with a Piezo speaker.
    There is also an option to set the key-press delay/repeat rate.
    Comments include a schematic diagram of the keypad and interface.

    Regards,

    David

    Post Edited (Drone) : 11/21/2007 2:08:17 PM GMT
  • AleAle Posts: 2,363
    edited 2007-11-21 12:24
    Well, that looks like a really old Falcon smile.gif, I saw some old ones but the front had already changed. That car was sold in my country till 1990, a bit changed, but the same one smile.gif, three motor sizes: 2.6, 3.0 and 3.6 l, I think it used regular gas, not super... but I'd not bet on that.

    (Once I wanted to do an electronic tachometer and speedometer for my Renault 12 smile.gif, be careful with the bright of LEDs, under daylight they are dim, but at night they can be quite bright, so a dimming is a sure bet. I love these things !
Sign In or Register to comment.