← blog.defg.xyz

How to build 64 keys MIDI keyboard

December 5, 2013 · MIDIArduino
Hi folks.... Been a long time since I've promised to write a post on how to build 64 keys midi keyboard. In fact this post will be on what needs to be done to extend the original post where we built midi keyboard from 32 key piano toy. In this case, of course, you will require a toy with more keys... I have not seen much of the toy pianos with 64 keys (have you?) but I guess you could build a matrix from scratch yourself using push buttons (that is fun!)



You will need to slightly modify the schematics and code to increase the number of keys.

On schematics you will have to replicate same 32 keys scan matrix and as already discussed you can organize it in several ways 8*8 or 16*4 scan matrix. Let's see how it is achieved in the 8*8 rows/columns case

Assuming you already have a scan matrix with 64 keys or were able to extend 32 keys scan matrix to 64 keys you will have now 8 rows and 8 columns from original project 8*4. Now you need to do same extension on the Arduino side by adding 4 digital inputs to support extra 4 rows displayed as YELLOW group on the schematics. Hope this part does make sense. If it does not I suggest to read links that were posted on original blog post to understand how scan matrix works - that should make it clearer.

Below is modified code to handle the extra 4 rows. I've added comments to highlight the extra code added.

After modifying original sketch it should allow all 64 keys to be played at the same time (not that you would do it).

You may notice there is a lot of repetition in the code. It was left intentionally that way to highlight parts that needs to be repeated. And in fact it could be made simpler by organizing rows and groupValue(s) in array. You can check the Velocity midi keyboard example as it makes use of array for rows and groupValue(s).

One of the steps you will need to do in the sketch is to Map keys to MIDI notes. You can use the following resources:

Midi notes map (NOTE to NUMBER):
http://www.phys.unsw.edu.au/jw/notes.html

Generally good resource on MIDI:
http://www.midi.org/techspecs/midimessages.php


Below is a sketch modification required to implement 8*8 matrix




Above we have discussed the 8*8 matrix to MIDI implementation.

I have not seen a 16*4 matrix, but if you have one, modifications will be more complex. We will not discuss details but roughly explain what's needed in this case and hopefully you will go for 8*8.

You will increase number of  columns (extra 8) and will have to add one more 74HC595 to implement 8 more columns. Number of rows will remain 4. Code modifications required will be following. You will need to add values to the bits array to increase the scan loop to 16 (8 more scans for new 8 columns). A disadvantage of the 16*4 matrix is that it will be about twice as slow as 8*8 as it will require 8 more serial scans (while in 8*8 it requires only 4 more). Schematic is also more complex in 16*4 implementation as it will require extra 74HC595 unless you use a better serial to parallel chip that has 16 outputs instead of 8. And overall, going from 16*4 to 8*8 you will only save a couple of I/Os - not much difference.

In fact 8*8 matrix could be implemented without 74HC595 if you ok to use all I/Os on the Arduino but make scan matrix faster... I might put a short post on it. That would make sense in the case of Arduino Mega, where you have plenty of I/Os and simplicity of schematics and implementation speed is what you want to achieve...

Hope that makes things a bit clearer... :)