Shop OBEX P1 Docs P2 Docs Learn Events
I2C LCD Keypad — Parallax Forums

I2C LCD Keypad

ShredderShredder Posts: 19
edited 2006-08-23 05:35 in BASIC Stamp
Hey guys.. so I have a keypad attached to my Matrix Orbital GLK12232-25-WBL..
I am trying to get the keypresses and cant quite figure it out.
heres what it says on the matrix orbital site

Q: How do i read the keypad data?

A: The keypad is read by I²C master read. In short, this means that a read of the module will always return the first unread key press. A read is initiated by writing to the module with its base address plus 1, then clocking the module's return byte after the module releases the SDA line. To poll the display for a keypad press, you send your I2C display address plus one.

ex. to write to the display you use 8A hex, to read you would use 8B hex.

The module contains a ten key press buffer so that it can be polled for key presses at an infrequent rate (every 250 to 1000 mS is typical). All returned key presses indicate the presence or absence of additional logged key presses by the most significant bit (MSB - bit 7). If the user has pressed two keys since the last poll of the keypad interface, the first read will return the key code with bit 7 set and the second read will return the key code with bit 7 clear. The application must take into account this bit to keep up with user key presses. If there are no keypresses detected, the module will return zero (0x00).



here is the Code I tried

Keypad VAR Byte

Main:
I2COUT 1, 80, [noparse][[/noparse]254, 88] 'Command Prefix, clear screen
'I2COUT 1, 80, [noparse]/noparse
I2COUT 1, 80, [noparse][[/noparse]"Testing..."]
PAUSE 5000
I2COUT 1, 80, [noparse][[/noparse]254, 88] 'Command Prefix, clear screen
I2COUT 1, 80, [noparse][[/noparse]254, 69] 'Command Prefix, clear keypad buffer

Everything bellow here is commented out cause its all different kinds of things I tried

'DO
'I2COUT 1, 81, [noparse][[/noparse]Keypad] 'tried this from docs "writing to the module with its base address plus 1"
'I2CIN 1, 80, [noparse][[/noparse]Keypad]
'I2COUT 1, 80, [noparse][[/noparse]Keypad]
'DEBUG Keypad
'LOOP


'DO
'I2COUT 1, 80, [noparse][[/noparse]254, 38] 'Command Prefix, poll keypad
'I2CIN 1, 81, [noparse][[/noparse]Keypad] 'base address +1
'DEBUG Keypad
'LOOP


Anyone using a matrix orbital with a keypad and the I2C interface with their BS2P or BS2PX?

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-17 11:11
    Shredder -

    I'm at least a bit confused by your instructions and the resultant coding. First you say:

    "Q: How do i read the keypad data?

    A: The keypad is read by I²C master read. In short, this means that a read of the module will always return the first unread key press. A read is initiated by writing to the module with its base address plus 1, then clocking the module's return byte after the module releases the SDA line. To poll the display for a keypad press, you send your I2C display address plus one.

    ex. to write to the display you use 8A hex, to read you would use 8B hex."

    But, then in the coding you use a SlaveID of $80 (see below), what's with that. Let's get this understood, before we getto the keypad input, just so we have some direction.

    I2COUT 1, 80, [noparse][[/noparse]254, 88] 'Command Prefix, clear screen
    'I2COUT 1, 80, [noparse]/noparse
    I2COUT 1, 80, [noparse][[/noparse]"Testing..."]

    Try changing that to:
    ' I am presuming the SlaveID is in HEX, if not remove the $ for decimal

    I2COUT 1, $8A, [noparse][[/noparse]254, 88] 'Command Prefix, clear screen
    'I2COUT 1, $8A, [noparse]/noparse
    I2COUT 1, $8A, [noparse][[/noparse]"Testing..."]

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • ShredderShredder Posts: 19
    edited 2006-08-17 17:43
    The Code snippet isnt my instructions, it comes from the Matrix Orbital website. And it confuses me also. The address in that is just an example of an address..
    This "I2COUT 1, 80, [noparse][[/noparse]"Testing..."]" actually works and prints to the LCD, 80 is the address on the I2C bus of the LCD

    The BS code I posted was lots of different things I tried.. none of which I could get to work for getting the keyboard input.

    This code here works.. clears the screen, prints "Testing..." on the lcd, waits, then clears the screen again.
    Keypad VAR Byte
    
    Main:
    I2COUT 1, 80, [noparse][[/noparse]254, 88] 'Command Prefix, clear screen
    I2COUT 1, 80, [noparse][[/noparse]"Testing..."]
    PAUSE 5000
    I2COUT 1, 80, [noparse][[/noparse]254, 88] 'Command Prefix, clear screen
    



    In your example, is "$8A" the same address as "80" ? Just ones hex and ones decimal? I'll try that when i go home for lunch.
  • ShredderShredder Posts: 19
    edited 2006-08-17 17:52
    This is from the manual

    This command sets the I2C write address of the module. This value must be an even number and the
    read address is one higher. For example if the I2C write address is set to 0x50, then the read address is 0x51.
    The change in address is immediate. This address is 0x50 by default, and is reset temporarily back to that
    value when the &#8217;manual over-ride&#8217; jumper is used on power up.
    



    "This address is 0x50 by default"

    now I am even more confused lol

    0x50 is in what format?
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-17 18:05
    Shredder -

    The format 0x50 implies $50 or hexadecimal notation. $50 in decimal is decimal 80 as
    you were using.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • ShredderShredder Posts: 19
    edited 2006-08-17 18:13
    Ok cool.. so then it seems to me that this code should work

    DO
    I2COUT 1, 80, [noparse][[/noparse]254, 38] 'A read is initiated by writing to the module with its base address plus 1
    I2CIN 1, 81, [noparse][[/noparse]Keypad] 'base address +1
    DEBUG Keypad
    LOOP


    but it didnt, should it be this?


    DO
    I2COUT 1, 81, [noparse][[/noparse]254, 38] 'A read is initiated by writing to the module with its base address plus 1
    I2CIN 1, 81, [noparse][[/noparse]Keypad] 'base address +1
    DEBUG Keypad
    LOOP
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-17 18:21
    Shredder -

    This came directly from the Matrix Orbital web site. Unfortunately, I see no similar information for reading from the key pad:

    quote

    Sending commands to a display from a BASIC Stamp using I2C communication. Supported BASIC Stamp: BASIC Stamp 2p models.
    BASIC Stamp: BASIC Stamp 2p models
    Communication Type: I2C
    Display Used: Any Matrix Orbital display that supports I2C such as the MOI or LK/VK/PK series.

    In this example we are talking to a display at address 80 Decimal (50 hex) over I2C communication protocol.


    Sending a Command to the display:

    '{$STAMP BS2p}

    I2COUT 1, 80, [noparse][[/noparse]254]······· 'Command Prefix
    I2COUT 1, 80, [noparse][[/noparse]88]········ 'Clear screen command

    In this example the command to clear the screen is sent to the display. Every command requires a "Command Prefix". In Matrix Orbital displays, that's Hex: FE Decimal: 254 ASCII: 254, you can send these bytes in any format you want, as long as you do it properly. In our example we sent them as DECIMAL...


    Setting the Backlight to go off in 2 minute:

    '{$STAMP BS2p}

    I2COUT 1, 80, [noparse][[/noparse]254]······ 'Command Prefix
    I2COUT 1, 80, [noparse][[/noparse]66]······· 'Backlight ON command
    I2COUT 1, 80, [noparse][[/noparse]2]········ 'Setting the number of minutes to be on

    To permanently turn the backlight on, you would send 0 as the third byte. When the display recieves the command, it will know how many more bytes of information it should get. In th backlight on case, the display knows to expect one more byte of information.

    end quote

    Regards,

    Bruce Bates
    ·
  • ShredderShredder Posts: 19
    edited 2006-08-17 18:30
    Yeah thats where I got the info to get the basics working.. it was really helpfull. The only thing I have seen is where they say "A read is initiated by writing to the module with its base address plus 1" which isnt much help [noparse];)[/noparse]
    I think I'll try posting in their forums too.
  • ShredderShredder Posts: 19
    edited 2006-08-23 05:35
    looks like I got it figured out.. so I figured I would post the code here for someone to see if they are looking to do the same thing..

    Here is the code..
    Keypad        VAR          Byte
    
    Main:
    I2COUT 1, 80, [noparse][[/noparse]254, 88] 'Command Prefix, clear screen
    I2COUT 1, 80, [noparse][[/noparse]"Testing..."]
    PAUSE 2500
    
    DO
    I2COUT 1, 81, [noparse][[/noparse]254, 88] 'Command Prefix
    I2CIN 1, 80, [noparse][[/noparse]Keypad]
     IF Keypad = "A" THEN I2COUT 1, 80, [noparse][[/noparse]"A pressed"]
    PAUSE 500
    DEBUG Keypad
    LOOP
    
    



    It seems you have to send out a command prefix to the address +1 , so 81 in this case. Sending text doesnt work.. it has to be a command of some sort.
    Then after you send the command you have to do the I2CIN at the normal address of 80
Sign In or Register to comment.