61-key midi organ keyboard code for arduino board

As long as the column select (from the micro I/O pins) is configured so all pins except the one being driven are set as inputs (neither high nor low) only the keys in the column being driven will appear at the shift register. That reads the state of the current column (and if two keys are pressed, they will both show up as 1 or 0 which ever denotes key pressed.) When the scan moves on to the next column, the same thing happens, assuming you have kept the state of the previous column in an array that will detect that more than one key is pressed. There is a bit (probably less than a millisecond) about which key was pressed first, but in most cases that won’t hurt anything. If you don’t change the unused micro pins in to inputs, then you need to add isolating diodes in to the +5V end of the key drive. Putting the diodes in the ground side of the switches will remove the low side noise margin as the 0.7V drop in the diode is the same as the ttl low lever (0.7V) you can fix that by referencing the diodes to -0.7V (making a switch low be ~0v because the diode is at -0.7V canceling out the 0.7V drop in the diode.) The start to all of this is a proper diagram of how the keys connect to the connectors as noted.


True, BUT, if 2 keys attached to the same column are pressed at the same time, that will connect BOTH of the associated shift registers lines to that active I/O pin. And one of the shift register lines will be high and the other low (when sensing one of those 2 keys). Shorted high to low.

As long as all of the ‘non-driven’ I/O pins of the shift register can be (and are) set to high impedance (off instead of high or low), then yes that works. tri-state outputs. It depends which shift register is being used. For the ones I have worked with, that is not an option. When the shift register is enabled (selected), all of the outputs go either high or low.

The way I know to get there, is to use an I/O expander instead of a shift register. Those are smarter (for this context), where each pin can individually be set as input or output. Then the configured output(s) will be driven high or low. and input(s) will be high impedance (sometime with a configurable pull up/down resistor as well).

Adding diodes on the shift register lines (or in the keyboard switch matrix) will prevent the short as well.

I may well be missing something as the sketch is confusing, but it appears to me that as long as the selector line on all the columns are set to input and only the selector in use is set as an output and set high or low, no other switch in another column will have any effect. The switch in the unselected column will reflect the state of the active switch to the select pin for that bank on the micro, but that pin is an input and won’t do anything (such as drive the pin in an undesired direction) on the shift register as far as I can see. What am I missing here?


Two switches in the SAME column.

My organ is at least 40 years old. I just got the output wires and there are no diodes. When testing with a multimeter, current flows in both directions.

Which means, from my understanding of the circuit, that you will need to add diodes between the shift register outputs and the wires for the keys. To detect multiple simultaneous key presses in a single ocatve. Or use an I/O expander with tri-state outputs instead of the shift registers. I am not an electronics engineer either, but have worked with hobby level electronics since most radios had tubes instead of transistors. Older than your organ.

OK now I see. This is just plain wrong. I was assuming the shift registers were being used as input devices, but I see they are in fact output devices which just won’t work in this case. A more sensible layout is the other way around the micro pins are the column select and the 12 shift register bits either go to 12 micro pins set for input (the most sensible / least hardware method) or replace the 74hc595s with 74hc597 parallel input shift registers. That works in the manner I outlined above. There is still the possibility of 3 keys being pressed at once (1 in the selected column and 2 different ones in another column) causing an incorrect input, but that may be rare enough to ignore and diodes will fix it (at the cost of yet more hardware.)


That works with an Arduino Mega board, shown in the starting post here. It has plenty of I/O pins. The referenced instructable used an UNO class board. That does not have enough pins to directly access the keyboard matrix and the Midi interface. Or it does, but barely. 20 I/O pins total, including 2 for USB.