Switch Matrix for Keyboard

Hello,

I'm a computer programmer but beginner Arduino user, and I'm planing to build a custom musical keyboard. Arduino would read the key states and send information via serial USB, and I already made a program in my machine to read that information and do something useful, including sending MIDI to other running applications or interfaces.

Considering the keyboard has 30 keys, I started searching for how to connect these and found a lot of information on shift registers and matrix options. I was planing to use the standard matrix design, with 6x5 which consumes 11 pins and seems to solve the problem (with my Arduino Uno). However I found another solution here in the forum, with a different design: http://forum.arduino.cc/index.php?PHPSESSID=12qunhfl5e3kh04ekrgrd38u35&topic=253215.msg1792669#msg1792669

Sorry to redirect you to another page, but I'm unsure if I were allowed to reproduce the posted information here.

In that post the genius solution presented by PaulRB allows one to (if I counted it right) connect n(n-1) keys, where n is the number of pins. Is there a name for this pattern?

My concern and consequently what I'd like to ask for advice too is about speed. Since this is a keyboard, I need ideally the lower latency possible. That particular solution would allow me to expand things further, but it relies on changing pins mode from output to input constantly. Would this cause some delay, in contrast with using "traditional" matrix with constant output and input number of pins?

The code would be pretty much similar to that exemple, but with the addition of a test before writing the new state to the memory. If the value is different than before, it will send a signal over the serial port.

Thank you

I use hardware SPI for this.
It can handel both in and out for the shift registers.

See example image:

If it is for midi then don't you need a velocity measure? That involves a single pole changeover switch and measuring the time between the breaking of the normally closed connection to the making of the normally open one. The time gives the velocity which is the second midi parameter in the note on message.

LarryD:
See example image:

Big image!

I see D1 to D8 to prevent the HC595 being overloaded by multiple column keypresses, but that will not allow you to reliably determine which keys they are, for which you need a diode on every crossover. In which case (or in any case), the input can more easily be a counter controlled by clock and reset. (OK, I know you can't use the interrupt that way but - why would that matter?)

Image re-sized

Works great as is, no other diodes are needed.

For the interrupts, all ones are shifted into the 595 and it is left that way.
No constant need for scanning.
Since you have a one in all the rows, when you touch any key an interrupt is generated via D9-16.
With the interrupt triggered, code simply sends the 595 with a walking 1 pattern while looking for return key in pattern from the 165.
Very fast.
Multiple key presses are ignored in the code.

If you are referring to ghosting, point taken. See: How a Key Matrix Work

LarryD:
I use hardware SPI for this.
It can handel both in and out for the shift registers.

Thank you for your answer but ideally I'd like to build this without extra hardware, just the Arduino diodes and switches!

Grumpy_Mike:
If it is for midi then don't you need a velocity measure?

Actually no, fixed velocity. I do need multiple key presses to work properly but no velocity.

Basically what I have are just two questions:
1.How is that matrix layout called (by PaulRB, which I linked) so I can research more into it
2.Does using it would slow down the process, since the pins are constantly changed from input to output and so on? I mean, slow in relation to a simple traditional diode matrix 6 outs by 5 ins (consumes 11 pins instead of 6).

Thanks!