...and then, while writing this blog page, I remembered the INPUT_PULLUP thing. I had to rewrite the sketch as "watch a pullup pin while writing LOW on some of the other 23".
Till today, I was ready to bet that a 24-pin interface for a keyboard had to be some row/column fitting. For example, one row-select pin, six row pins, one column-select pin, 16 column pins. The shown keyboard (a K9405076 produced in 1996) physically has:
- 17 keys on first row
- 14 on second
- 15 on third
- 14 on fourth
- 14 on fifth
- 12 on sixth
for a grand total of 86 keys. The extra physical key on the first row is easily reportable as being part of the second row. I guessed that to read a key, the BIOS scanned every column (write a logical "true" on one, watch for any "row" changed, identify the key combination in a matrix). I only had to figure out the pin numbers (any pin could be row, column or select).
My first attempt was wrong because on the Arduino an "unconnected" input pin floats randomly between high/low states, and the only available Arduino feature for unconnected pins is the INPUT_PULLUP thing. So I had to give a try with a different schema: "for every keyboard pin, set everything Low and check if an High appears somewhere" to identify the column-select or row-select (the former would react on more than six keys). I connected the 24 keyboard pins to the area containing Arduino Mega digital I/O ports from 22 to 51, and started this:
// // keytest.ino -- 24 pin keyboard test void scan() { int n, i; for(n=22; n<52; n++) { for(i=22; i<52; i++) // set everything low { pinMode(i, OUTPUT); digitalWrite(i, LOW); } pinMode(n, INPUT_PULLUP); // examine pin n: "unconnected" --> HIGH digitalWrite(n, HIGH); // enable internal pullup if(digitalRead(n)==HIGH) continue; // just ignore unconnected pins Serial.print(n); // pin n is connected somewhere: announce it Serial.print(": "); for(i=22; i<52 && i!=n; i++) // for any remaining output pin: { digitalWrite(i, HIGH); // examined pin goes from LOW to HIGH ? if(digitalRead(n)==LOW) continue; Serial.print(i); // yes: announce the connection Serial.print(" "); digitalWrite(i, LOW); // set to LOW again to continue checking } Serial.println(); } } void setup() { Serial.begin(115200); } void loop() { scan(); }
I expected it output some numbers when pressing some keys. Alas, on many keys nothing happens, while a few keys (most notably on the right side) only show some pin numbers when pressed in combination of two or three, suggesting that row-select and column-select are the first two keyboard pins starting from keyboard center (the ones with longest vias). I'm currently stuck because I cannot understand if:
- (1) my FPC to 0.1" adapter thing does not work correctly,
- or (2) the keyboard is actually broken, maybe in the connector area,
- or (3) the scheme requires more than a single row-select pin and a single column-select pin.
So I checked again and again the FPC-side connection and tested my adapter - everything is OK.
And then I finally tested the FPC connector keyboard. I wasn't able to verify a single key - this still does not add useful information. I will clean the connector and test again.
Cheap chinese keyboards come for less than five bucks - but, hey!, this project is meant to use the spare parts: buying a thing to replace a non-broken spare part is unacceptable...