Keyboard matrix beginnerish help (keypad library)

Hello, I posted earlier about another music project but after several days of trying to fix code I wanted to put it on hold for a while. I took apart one of my electronic keyboards which had midi out but I want to make it as diy as possible. So I took the keys out and left the matrix chip and other things away.

Now I have figured out how many columns and rows it has inside the keyboard matrix
But the problem is the library im using seems to only accept one number into the key mapping

Im using Pro Micro cheap china copy

My keyboard has 49 keys
8 rows and
7 columns (7th is just one Note)
it turns into 15 wires
Connected to my Arduino pro micro (you can find pin-in inside code)

Now my problem is I don’t know how to name code the keys for the “char hexaKeys”
since its such a big number on these keys

First I tried to name them with C1, C1# // D2, D#2, and so on
But I realised it didn’t accept more than one letter into the mapping
So I tried to do the alphabet and numbers but its not enough for 49 keys

“char hexaKeys[ROWS][COLS] = {
{‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’},
{‘H’, ‘I’, ‘J’, ‘K’, ‘L’, ‘M’, ‘N’},
{‘O’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘Y’},
{‘X’, ‘Z’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’},
{‘6’, ‘7’, ‘8’, ‘9’, ‘0’, ‘6’, ‘7’},
{‘0’, ‘1’, ‘2’, ‘3’, ‘5’, ‘6’, ‘7’},
{‘0’, ‘1’, ‘2’, ‘3’, ‘5’, ‘6’, ‘7’},
{‘0’, ‘0’, ‘0’, '0, ‘0’, ‘0’, ‘0’},”

Then I started thinking maybe I have to write another code, or can I somehow convert this hex into something else that can fit characters into the code?
I want to turn this later on into midi events (usb or analog)

I started thinking more while writing the topic and I tried to put the notes into the graph in the code comments and its like my brain hit a wall and I realised I am going to deep and “entering the matrix” .
(As you can see in the code with hexakeys its all a mess but thats not the trouble right now)

Maybe im misunderstanding this library?

Music aspect will have to be solved later anyway
. But if I at least could give the matrix keys a name I could later transfer them to notes with the help of serial monitor. Appreciate all help and insight


/* @file CustomKeypad.pde
  || @version 1.0
  || @author Alexander Brevig
  || @contact
  || @description
  || | Demonstrates changing the keypad size and key values.
  || #
#include <Keypad.h>

const byte ROWS = 8; //8 rows
const byte COLS = 7; // 7 columns  (each column is 1 / 4 octave of thekeyboard which is 8 notes)

//Math to clarify the music ascept and make sure i think of this the right way
// I am not including the last column with only one single note in this

// so one octave is 12 notes
// and 12 notes are  = 1.5 columns (looking at PCB)
//  which means 8 notes  is one column (12 divided by 1.5)
// since it has 6 columns which are full it must be (8*6=48) 48 notes and that gives me 4 octaves of notes (correct, not counting the last 49th note)

// The columns all each have 8 diodes for each switch, which then if a key i press together
//                  -and separate from inputs (depending on switch pressed) goes to the output wires

// the input wires (goes to column later goes through the diodes depending on key pressed)
// then the signal coming from diodes goes to the output wires

// output wires later goes into (Arduino (micro pro) IN PINS 16, 14, 15, 18, 19, 20, 21)

// 7 columns

//ROWS >>>>>


//define the cymbols on the buttons of the keypads (<- comment is from original library example)
char hexaKeys[ROWS][COLS] = {
  {'c1', 'g1', 'd1', 'd#1', 'e1', 'e#1', C, ,
 {'c#1', 'g#1', 'e2', 'g1', 'c1', 'g1',f},
  {'d1', 'a1', 'e#2', 'g1', 'c1', 'g1',f},
 {'d#1', 'a#1', 'f2', 'g1', 'c1', 'g1',f},
  {'e1', 'b1', 'c2', 'g1', 'c1', 'g1',f},
 {'e#1', 'c2', 'c2', 'g1', 'c1', 'g1',f},
  {'f1', 'c#2', 'c2', 'g1', 'c1', 'g1',f},
 {'f#1', 'd2', 'c2', 'g1', 'c1', 'g1',f},

    byte rowPins[ROWS] = {2, 3, 4, 5, 6, 7, 8 , 9}; //connect to the row pinouts of the keypad
    byte colPins[COLS] = {16, 14, 15, 18, 19, 20, 21}; //connect to the column pinouts of the keypad

    //initialize an instance of class NewKeypad
    Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

    void setup() {

    void loop() {
    char customKey = customKeypad.getKey();

    if (customKey) {

With the following definition, are you getting A on the Serial Monitor when you press K00 (A)? Are you getting 7 on Serial Monitor when you press K46 (7), and son on? If yes, then what is your problem? The matrix defines the ASCII codes for the corresponding valid ASCII printable character, and it should be only one charctaer; it must not be like 'cd' and etc.

char hexaKeys[ROWS][COLS] = {
{'A', 'B', 'C', 'D', 'E', 'F', 'G'},
{'H', 'I', 'J', 'K', 'L', 'M', 'N'},
{'O', 'P', 'Q', 'R', 'S', 'T', 'Y'},
{'X', 'Z', '1', '2', '3', '4', '5'},
{'6', '7', '8', '9', '0', '6', '7'},
{'0', '1', '2', '3', '5', '6', '7'},
{'0', '1', '2', '3', '5', '6', '7'},
{'0', '0', '0', '0, '0', '0', '0'}

I do get response when skipping the diodes with a wire so I guess its wrong polarity in the "script" or from Arduino?

Take a look at my MIDI Controller library. It supports keyboard matrices like that directly, just specify the pins, and the notes, and it sends out MIDI Note On/Off events (over USB/Serial/Debug, you name it).

MIDI_controller/Ex.11.Button-Matrix.ino at master · tttapa/MIDI_controller · GitHub (Documentation)

This is an example of the "ButtonMatrix" class of the MIDI_controller library.
Connect a 4 × 3 matrix of buttons with the rows to pins 2, 3, 4 and 5, 
and the columns to pins 6, 7 and 8.
Pull-up resistors are not necessary, because the internal ones will be used. 
If you want to be able to press multiple buttons at once, add a diode 
in series with each button, as shown in the schematic on the Wiki:
The note numbers are specified in the 'addresses' array.
Map accordingly in your DAW or DJ software.
Written by tttapa, 24/09/2017

#include "MIDI_Controller.h" // Include the library

const uint8_t velocity = 0b1111111; // Maximum velocity (0b1111111 = 0x7F = 127)
const uint8_t addresses[4][3] = {   // the note numbers corresponding to the buttons in the matrix
  {  1,  2,  3 },
  {  4,  5,  6 },
  {  7,  8,  9 },
  { 10, 11, 12 }

// Create a new instance of the class 'ButtonMatrix', called 'buttonmatrix', with dimensions 4 rows and 3 columns, with the rows connected to pins 2, 3, 4 and 5
// and the columns connected to pins 6, 7 and 8, that sends MIDI messages with the notes specified in 'addresses' on MIDI channel 1, with velocity 127
ButtonMatrix<4, 3> buttonmatrix({2, 3, 4, 5}, {6, 7, 8}, addresses, 1, velocity);

void setup() {}

void loop() {
  // Refresh the buttons (check whether the states have changed since last time, if so, send it over MIDI)

Here’s the diagram for the example:

You can flip the rows and collumns, but you have to change both the code and the schematic if you do that.


Wow thank you! This was exactly what I was looking for but I was certain I looked through whole of google on these keywords! Ill try

Also some questions, if it turns out my diodes are the "wrong way" compared to the standards (numpads or w/e) how would I be able to solve this? And what do you mean with switching schematics and code for flipping rows/columns (was that referring to polarity?) ? Thanks