Today (25 March 2012) I downloaded and ran the keyboard library and samples and proceeded to test it...
Using a 4x4 keyboard and the CustomKeypad.ino I got no data from row 1 (the TX pin of Arduino Uno)...
The default pins as designated as:
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
Code work fine if I use different pins and avoid pin 1 (tx), so if the test code is correct and pin 1 can be used, could my new Arduino be faulty... na... I don't think so... more likely something to do with pin1 (tx)...
I note the library correctly assumes assigned pins may be used by another device...
I'm also guessing most (if not all) libraries also follow suit...
If this is true, in theory data lines can be multiplexed (allowing for time critical code)...
Therefore the following code should work...
void loop()
{
char key = keypad.getKey();
if(key)
{
lcd.write(key);
do some more stuff...
}
}
Can anyone confirm or deny if this assumption is correct?
Footnote:
Keypad: getkey() calls getKeyState(), which calls initializePins() to initialise the pins to the correct state...
LCD: The pins are designated as output prior to sending data to the LCD...
MikeOToole:
I note the library correctly assumes assigned pins may be used by another device...
I'm also guessing most (if not all) libraries also follow suit...
Can anyone confirm or deny if this assumption is correct?
I can't absolutely deny it but I believe that most libraries probably do not have the ability to be muxed. It was only due to my prompting that ladyada added the code that allows the LCD library to be muxed.
Then it looks like my example code above should work (can't test as I need some components)...
Hard to believe it's worth writing any library that does not allow multiplexing of data pins, especially when it only requires a little for loop before inputting/outputting data...
Test circuit to test the shared data pins using Keyboard and LCD libraries
Circuit parameters:
Security entry system with no false positives...
Generic 4x4 keypad to enter the password...
Generic LCD (4478 compatible) to display key press and other messages...
Piezo sounder and led to provide feedback...
Parts:
Arduino Uno (rev 3)...
Keypad: Generic 4x4 matrix keypad...
LCD: DEM20485SYH (20 character by 4 lines)...
Discrete components: 330R resistor, Led, 10k pot for LCD contrast...
Conclusion:
Circuit works perfectly, occasional spurious characters on LCD during lcd.clear() but nothing to worry about...
Notes:
Used the keyboard interrupt to facilitate better timing of events...
The lcd.clear() timing is quite long and erroneous characters can occur, however this is also true of circuits that do not share data pins... it's all down to timing and that's another day...
Any tips on how to prevent erroneous characters on LCD appreciated...