I have a 4x4 matrix for 16 buttons. Each row/column is directly connected to the pins of an unknown microcontroller. When I connect the pins directly to each other, the microcontroller behaves correctly, as if the respective button was pressed.

I want to control the pins directly with an Arduino or connect them directly to GND/VCC. However, when I turn them on this way, the microcontroller either:

  • does nothing
  • behaves as if several buttons are pressed at once.

Why is that? Am I missing something, like pullup-resistors?

The microcontroller supports certain button presses at the same time. I think it has to do with the row scanning. <- This turned out to be true, the microcontroller checked one row at the time. So it was necessary to activate the column pin only when the right row was selected.

  • \$\begingroup\$ To scan matrix keyboards I use timer interrupts , in each I read the input first then change the output , this allows for the largest latency for the inputs and as a consequence higher values for pull up/down resistors and lower current consumption. In this scenario Arduino have the time to output the right signal but no guarantee that everybody does-it this way. \$\endgroup\$ – Dorian Dec 3 '18 at 11:10

The question is: how are you "controlling" the wires using an arduino? The microcontroller is probably pulling the rows (or columns) up (or down) one at a time, an then checking the voltage on the other axis to detect button presses in that row/column.

To emulate this using an arduino, you would have to monitor the energized axis, and then output to the sensing axis in a synchronized fashion. Depending on how the unknown microcontroller is programmed, this may be very difficult, because it could read very soon after energizing. Perhaps too fast for your arduino to react.

It's also worth noting that other arrangements exist besides row/column. Are you sure this is how the keypad is arranged?

  • \$\begingroup\$ This is exactly what I just did, it works! Setting all column pins to LOW, reading which of the row pins was set to LOW, and then setting the right column pin to HIGH only when the right row was reached, otherwise keep it LOW. I was concerned that the Arduino might be too slow, since the microcontroller seems to run with 12MHz. But the row sampling/strobe interval seems to be large enough! Thank you! \$\endgroup\$ – 2080 Dec 3 '18 at 10:22
  • \$\begingroup\$ Luckily the column and row pins were sequential and separate on the controller. I created an input matrix and also measured all pins over time, so I knew which ones were outputs with pullups. So I could be quite sure it was that way. \$\endgroup\$ – 2080 Dec 3 '18 at 10:28

The keyboard use multiplexing, see here the theory.

What can you do ?

First you need identify the inputs and the outputs and find out if the unknown processor drives the outputs in positive or negative logic. This should be easy since you already made some tests and the board still works. In positive logic an input connected to VDD would show as many buttons pressed at once. In negative logic an input connected to GND will show as many buttons pressed at once. An output will do nothing connected to VCC or GND. Since I suppose you can see the rows and the columns you only need to do this test for one line of each. Even if you didn't burned an output yet please use a small resistor for tests (470 ohm will do). The example in the link is in positive logic (an active input/output is high)

You can try to simulate the keyboard behavior by connecting four arduino inputs to the processor keyboard outputs and four arduino outputs to processor keyboard inputs but it's unlikely that this will work reliably since for a simulated key press the output should follow the connected input very fast. A microcontroller with CLC engine like some microchip PIC-s have can do that but Arduino not.

You can use an optocoupler matrix, if the matrix is in positive logic connect the phototransistor collector to output emitter to input and in reversal if in negative logic. If it works than you can use also multiplexing to drive the optocouplers as you see in the end of the article from the above link. You can find very cheap quad optocouplers like this one, you will need four of them, less then 10$ for all.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.