Wednesday, December 4, 2013

How to build 64 keys MIDI keyboard

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 Schematics and Code to to increase 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. Lets see how it is achieved in 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.

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 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 following resrouces:

I have not seen 16*4 matrix but if you got one, modifications will be more complex. We will not discuss details but roughly explain whats 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 bits array will to increase scan loop to 16 (8 more scans for new 8 columns). Disadvantages of 16*4 matrix is it will be about twice slower than 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 from 16*4 to 8*8 you will economy couple of I/Os only - 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 case of Arduino Mega where you have plenty of I/Os and simplicity of schematics and implementation speed is what you want to achieve...

14 comments:

hi! need some info, i have a 48 keys keyboard, how can i program that? i assume that i have to erase two block of the text taking the 60 value (C4) as my center? or i need a totally new code? (in not good programer) thanks!

Hello, thanks for the project, it's what i've been looking for ages.I got a little problem/question, the PCB for my keys are a little weird.It has 17 wires, the keys are divided in 10 groups with 6 keys each and a group with one key alone, what are the steps so i can wire and code it correctly?

Thanks for posting this sketch , it's a great job.I'm trying to make a MIDI controller, and use your schedule and already managed to add 4 analog controls with CONTROL CHANGE for each. I am now trying to add the nRF24L01 , but it is very complicated because it already can transmit the analog controls but do not know how to transmit the digital controls (MATRIX ) .Have you ever tried to do this program ? or you can help me with this schedule ?

the codes are in the following dialogue.

I'm using a ARDUINO MEGA 2560 in the transmitter and the receiver ARDUINO UNO . I changed the DIGITAL pins MEGA 2560 to 22 ... 29 .I added the libraries of nRF24L01 .I called the pins 48, 50 , 51, 52 and 53 for nRF24L01 .

Please , I hope you can help me .I had several unsuccessful attempts .

Hey first off all great project.The thing is that I dont really understand how to program this for a 9x12 keyboard.And const int row8 = 1; means that the 1 pin is a input but whats the pinnumber that goes to the midi connector.