I2C LCD Keypad
Shredder
Posts: 19
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
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?
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
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 -->
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.
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.
"This address is 0x50 by default"
now I am even more confused lol
0x50 is in what format?
The format 0x50 implies $50 or hexadecimal notation. $50 in decimal is decimal 80 as
you were using.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
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
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
·
I think I'll try posting in their forums too.
Here is the code..
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