hi could someone help me with the wiring for cherry mx keys on a teensy 4.1 in a matrix way
i read a lot about resistors and diodes buth somehow im confused, i made a pcb board by jlc pcb buth somehow everything went wrong, flippping the diodes resolved the issues buth with my new pcb plates i got a lot of noise (pressing key 5 also activated 6 for example) could someone with knowhow look to my diagram i made in eagle? im not a professional just a hobby enthousiastic that would like to make this works
this is currently my third atempt that i would send to jlc, there are also screens on it (this works so no problem there) on the sides i connect my rows (2) and on the top my cols (6)
is this board correct ore will i have problems?
question; are the diodes correct?
question; the resistors on top left are 10k are theyt needed in teensy ?
i would use following lib: keypad so that i can detect press release and hold
would this work?
@Grumpy_Mike @LarryD is saw i similar post where you two responded on and wondered if you could help me with my project questions?
Looking at a PCB layout is a last resort kind of problem.
We need to see the schematic.
@LarryD aznd @Grumpy_Mike i made a basic example (2 rows 2cols)
and used this code
/* @file MultiKey.ino
|| @version 1.0
|| @author Mark Stanley
|| @contact mstanley@technologist.com
||
|| @description
|| | The latest version, 3.0, of the keypad library supports up to 10
|| | active keys all being pressed at the same time. This sketch is an
|| | example of how you can get multiple key presses from a keypad or
|| | keyboard.
|| #
*/
#include <Keypad.h>
const byte ROWS = 2; //four rows
const byte COLS = 2; //three columns
char keys[ROWS][COLS] = {
{'1','2'},
{'4','5'}
};
byte rowPins[ROWS] = {2,3}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {4,5}; //connect to the column pinouts of the kpd
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
unsigned long loopCount;
unsigned long startTime;
String msg;
void setup() {
Serial.begin(9600);
loopCount = 0;
startTime = millis();
msg = "";
}
void loop() {
loopCount++;
if ( (millis()-startTime)>5000 ) {
Serial.print("Average loops per second = ");
Serial.println(loopCount/5);
startTime = millis();
loopCount = 0;
}
// Fills kpd.key[ ] array with up-to 10 active keys.
// Returns true if there are ANY active keys.
if (kpd.getKeys())
{
for (int i=0; i<LIST_MAX; i++) // Scan the whole key list.
{
if ( kpd.key[i].stateChanged ) // Only find keys that have changed state.
{
switch (kpd.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED:
msg = " PRESSED.";
break;
case HOLD:
msg = " HOLD.";
break;
case RELEASED:
msg = " RELEASED.";
break;
case IDLE:
msg = " IDLE.";
}
Serial.print("Key ");
Serial.print(kpd.key[i].kchar);
Serial.println(msg);
}
}
}
} // End loop
this did nothing in my serial monitor when pressing the knobs
then is changed this line
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
to
Keypad kpd = Keypad( makeKeymap(keys), colPins,rowPins, ROWS, COLS );
so i switched cols and rows their pins
al the buttons work now except when i press col1 ROW1 also COL1 ROW2 is activated in the monitorring?

diagram that doesnt work
changing the pins from rows to cols and cols to rows works but with errors
i'm quite a bit lost, followd the tutorial of gammon (https://www.gammon.com.au/forum/?id=14175) and it just dont work, what am i doing wrong
things i tried:
- new teensy: stil errors
- new buttons all four: same error
- resolder everthing= still error
- other pins on teensy : stil error
-switching colpins: same error but on the changed button
im stumped.....
The T4.1 has more than 25 inputs so why wrestle with matrixing unless this is a class exercise requirement. Just connect one key switch per GPIO.
Ixebuster is not an option i use 20pins already for other stuff
But I can't see any pull up resistors. These are in your "diagram" in post #5
You are feeding us information in tiny chunks. As you did layout a PCB then there must be a schematic you can output and post?
No pull up resistors.
Is this "other stuff" connected up?
Is there currently in the software you are using any code that "looks after" the other stuff? In other words is the code you say you are running actually the code, the whole code and nothing but the code, as they don't say in a court of law.
I did notice that the code you are running is the MultiKey code from the libraries example folder. This sort of thing you should have mentioned, as it is I thought that it was code you had written.
I did check the library code to see if it was using timers that might not have been compatible with the Teensy but I couldn't see anything.
Hi Mike thank you for the respons
I thought that teensy had pullup redisters ore im a wrong about this?
What do you mean about the schematic? I padted it in the post?
The other items (oled screens, mux, slide pots) are currently not connecties because i ony want to test the button matrix
Yes it has pull up resistors but only if you enable them, I don't see the library doing that. Even so these are very high impedance pull resistors in the order of 50K.
I mean that we have only ever seen bits of schematic, never the whole thing. So we don't know exactly what we are dealing with. Post #5 was a good start but you clearly didn't have the pull up resistors like that diagram said, and there was a heap of words saying why this was not actually the schematic.
Also when no key is being pressed the row inputs are in effect floating. That means they are not connected to anything. That means that they can read either a high or low depending on what interference they pick up. An unconnected input does not always read high.
The solution to this is to enable the internal pull down pins on the row inputs. Unfortunately not many processors have pull down resistors. The teensy 4.1 processor might but I don't know, you need to look at the data sheet for its processor. Also the Library doesn't do that anyway.
So it might be worth adding a 100K pull down resistor on the row inputs.
Do you see why we need to see a proper schematic, not just bits of them with words saying they are not like this.
Hi @Grumpy_Mike i Will add the resistors to the rows as you mentioned, do you have any lead on the diodes why i had the flip them? I found this very strange
I already tried adding resistors but i did it to the columns and that was wrong i think (also didnt got anything of results)
It all depends on how the Keypad library scans the matrix. Perfectly normal nothing strange about it.
Any keyboard matrix can be scanned in two ways, by row or by columns. If you scan it the other way the diodes need switching so that the key press gets connected to the row or column being the input.
This link:-
http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html
shows the two ways a matrix can scan. However this is specifically about an LED matrix, but a switch matrix works in the same way.
Right I think I have sorted this out.
Basically your matrix circuit is wrong because it was designed to be used with a different sort of scanning algorithm that that used by the Keypad library.
I built a 4 by 3 matrix and used my oscilloscope to look at the waveforms it produced, to find this out. The problem is caused by the diodes, these are not needed, and indeed if you have them it will mess up the algorithm that Keypad uses.
So the solution to your problem is to simply wire them in in a matrix with no diodes and no resistors. On your PCB you can remove the diodes and replace them with a soldered link of tinned copper wire or just wire to short them out.




