-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to also use arduino ports? #13
Comments
Interesting idea, thanks. I'll leave this issue open here for anyone else to see the approach. If there's additional interest, I can incorporate it in the library. There is also an alternative way to get large keyboards using more than one port expander. I found that scanning speed with big keyboards is poor with ATMega328 arduinos but may be ok with faster cpus. |
I'm working on a project that ideally would required a 9x9 keypad, so I could use that feature, but I'm not sure I'm skilled enough to understand what @salautom did. I could get away with an 8x8 matrix plugged into a PCF8575 and do a small separate matrix for row 9 and column 9 buttons directly plugged into the arduino. |
I have not tried the method mentioned above, but it should work OK. |
I should also add to the comment above that for the case when you can access the wiring (the second possibility mentioned by Assamita81) the existing libraries Keypad_I2Ca can be used for the 8x8 keypad and the library Keypad can be used with the direct i/o pins for the extra 18 keys. Fewest pins would be to arrange the direct i/o as a 3x6 matrix. |
Hi. I'm back. I've had so much bad experience with PCF8575 that I'm giving up on them. I'm moving onto trying the MCP23017 instead, I just ordered 5 of them to test them. |
I made some modifications for myself because I need a keypad of 10 rows and 8 columns
maybe an option to add this to your code??
byte colPins[COLS] = {-4, -5, -6}; //connect to the column pinouts of the keypad (negative values are ports on the arduino itself)
negative numbers are arduino pins.
modified 3 functions:
// individual pin setup - modify pin bit in IODIR reg.
void Keypad_MC17::pin_mode(byte pinNum, byte mode) {
if (pinNum > 127)
{
pinMode(abs(pinNum-256), mode);
}
else
{
word mask = 0b0000000000000001 << pinNum;
if( mode == OUTPUT ) {
iodir_state &= ~mask;
} else {
iodir_state |= mask;
} // if mode
_wire->beginTransmission((int)i2caddr);
_wire->write( IODIRA );
_wire->write( lowByte( iodir_state ) );
_wire->write( highByte( iodir_state ) );
_wire->endTransmission();
}
} // pin_mode( )
void Keypad_MC17::pin_write(byte pinNum, boolean level) {
if (pinNum > 127)
{
digitalWrite(abs(pinNum-256), level ? HIGH : LOW);
}
else
{
word mask = 1<<pinNum;
if( level == HIGH ) {
pinState |= mask;
} else {
pinState &= ~mask;
}
port_write( pinState );
}
} // MC17xWrite( )
int Keypad_MC17::pin_read(byte pinNum) {
if (pinNum > 127)
{
return digitalRead(abs(pinNum-256));
}
else
{
_wire->beginTransmission((int)i2caddr);
_wire->write( GPIOA );
_wire->endTransmission( );
word mask = 0x1<<pinNum;
_wire->requestFrom((int)i2caddr, 2);
word pinVal = 0;
pinVal = _wire->read( );
pinVal |= ( _wire->read( )<<8 );
pinVal &= mask;
if( pinVal == mask ) {
return 1;
} else {
return 0;
}
}
}
The text was updated successfully, but these errors were encountered: