The project is done (Old 49 keys casio) to midi using Arduino MEGA

So guys as the title says, I've seen this project done a lot in the old days and I wanted to try that out on an old 49 keys keyboard that is laying down (CASIO TYPE)

Basically I'm not a pro in coding . But anyway I've got the board and followed the instructions as guided

1- Scanned the keyboard matrix and wrote it all down Pictures attached the ribbons are made by 15 wires and the matrix is 9*6 and here are some pictures

2- On this point I'm not sure of what I'm doing but i got the 15 wires connected in order to the Arduino Mega Digital Pins starting from 22


3- I've connected the board to the computer now to begin with the real stuff :slight_smile: :slight_smile: .... But as I said I'm so trashatic when it comes to coding, I've searched multiple forums related to this project and watched everyvideo on Youtube but came with nothing related to the Arduino Mega regarding the coding or the source

4- As I was searching hopefully to find some code, I found a post on an old forum right here and I've went through it all

5- By the time I've spent I was able to get the keyboard matrix coded 100%
Serial monitor get all the readings perfectly

``

#include <Keypad.h>

const byte ROWS = 7; //Seven rows
const byte COLS = 10; //Ten columns
char keys[7][10] = {
 {1, 2, 3, 15, 14, 13, 12, 11, 10},
 {4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
 {5, 5, 5, 5, 5, 5, 5, 5, 5, 0},
 {6, 6, 6, 6, 6, 6, 6, 6, 6, 0},
 {7, 7, 7, 7, 7, 7, 7, 7, 7, 0},
 {8, 8, 8, 8, 8, 8, 8, 8, 8, 0},
 {9, 9, 9, 9, 9, 9, 9, 9, 9, 0},
};
byte rowPins[ROWS] = {26, 28, 30, 32, 34, 36, 38 ,}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {A0, A1, A2, A3, A4, A5, A6, A7, A8,}; //connect to the column pinouts of the kpd

Keypad kpd = Keypad( makeKeymap(49), rowPins, colPins, ROWS, COLS );

unsigned long loopCount;
unsigned long startTime;
String msg;


void setup() {
 Serial.begin(9600);
 loopCount = 0;
 startTime = millis();
 msg = "";
}


void loop() {
 loopCount++;
 if ( (millis() - startTime) > 5000 ) {
   Serial.print("Average loops per second = ");
   Serial.println(loopCount / 5);
   startTime = millis();
   loopCount = 0;
 }

 // Fills kpd.key[49] array with up-to 10 active keys.
 // Returns true if there are ANY active keys.
 if (kpd.getKeys())
 {
   for (int i = 0; i < LIST_MAX; i++) // Scan the whole key list.
   {
     if ( kpd.key[i].stateChanged )   // Only find keys that have changed state.
     {
       switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
         case PRESSED:
           msg = " PRESSED.";
           break;
         case HOLD:
           msg = " HOLD.";
           break;
         case RELEASED:
           msg = " RELEASED.";
           break;
         case IDLE:
           msg = " IDLE.";
       }
       Serial.print("Key ");
       Serial.print(kpd.key[i].kchar);
       Serial.println(msg);
     }
   }
 }
}  // End loop

6- Now the only thing I need is to get the midi working while I press a key because its not doing any sound (and this is the part where I'm asking for help)*********

@Oday_Alasali, stop cross-posting. Last warning.

Other thread removed.

I saw your warning, but I can't delete threads so what can I do for God sake. This is the only one I want it to be on the forum

Oday_Alasali:
I saw your warning...

...and ignored it.

Oday_Alasali:
...but I can't delete threads...

Unnecessary. I have already cleaned up your mess.

.

Ok exactly what help.
Post your code. Say what it does and say what you want it to do.

I just want the easiest code to make this happen and I will apply everything on it, if you would be able to help me with this I'm sure everything is done.

so is there anyway to modify this code using the matrix to send midi notes and be 100% functional if its kinda hard just give me hints or am I gonna need to change the whole code???

#include <Keypad.h>

const byte ROWS = 7; //Seven rows
const byte COLS = 10; //Ten columns
char keys[7][10] = {
 {1, 2, 3, 15, 14, 13, 12, 11, 10},
 {4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
 {5, 5, 5, 5, 5, 5, 5, 5, 5, 0},
 {6, 6, 6, 6, 6, 6, 6, 6, 6, 0},
 {7, 7, 7, 7, 7, 7, 7, 7, 7, 0},
 {8, 8, 8, 8, 8, 8, 8, 8, 8, 0},
 {9, 9, 9, 9, 9, 9, 9, 9, 9, 0},
};
byte rowPins[ROWS] = {26, 28, 30, 32, 34, 36, 38 ,}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {A0, A1, A2, A3, A4, A5, A6, A7, A8,}; //connect to the column pinouts of the kpd

Keypad kpd = Keypad( makeKeymap(49), rowPins, colPins, ROWS, COLS );

unsigned long loopCount;
unsigned long startTime;
String msg;


void setup() {
 Serial.begin(9600);
 loopCount = 0;
 startTime = millis();
 msg = "";
}


void loop() {
 loopCount++;
 if ( (millis() - startTime) > 5000 ) {
   Serial.print("Average loops per second = ");
   Serial.println(loopCount / 5);
   startTime = millis();
   loopCount = 0;
 }

 // Fills kpd.key[49] array with up-to 10 active keys.
 // Returns true if there are ANY active keys.
 if (kpd.getKeys())
 {
   for (int i = 0; i < LIST_MAX; i++) // Scan the whole key list.
   {
     if ( kpd.key[i].stateChanged )   // Only find keys that have changed state.
     {
       switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
         case PRESSED:
           msg = " PRESSED.";
           break;
         case HOLD:
           msg = " HOLD.";
           break;
         case RELEASED:
           msg = " RELEASED.";
           break;
         case IDLE:
           msg = " IDLE.";
       }
       Serial.print("Key ");
       Serial.print(kpd.key[i].kchar);
       Serial.println(msg);
     }
   }
 }
}  // End loop

Say what it does and say what you want it to do.

?

I am guessing you want to convert what you read as a key press to a MIDI message. A lot of the detail depends on how you want to send the MIDI.
Basically there are three methods to send MIDI from an Arduino:-

  1. Using the serial port to send MIDI to an old school 5 pin MIDI output. For this you need some circuitry to convert the serial output to the MIDI standard.

  2. Using the serial port to send MIDI to a "helper" program in the computer. You don't need any extra circuitry but you do need to install and configure this helper application on your computer. A good free one is called "hairless".

  3. Making the Arduino look like a USB HID MIDI device. You can only do this on the Arduino's that use a ATmega32u4 processor. That means using the Leonardo or the Micro.

You put the code here:-

       switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
         case PRESSED:
           msg = " PRESSED.";
           // send MIDI note on message here
           break;
         case HOLD:
           msg = " HOLD.";
           break;
         case RELEASED:
           msg = " RELEASED.";
         //send MIDI note off message here
           break;

I would also remove the use of the String class if you want long term stability because its repeated use can lead to running out of memory. It is fine for development but you will not need in in the long run. Why not simply print out the string in the switch statement?

Well I know about hairless and loopmidi \ serial converter to usb

I want the code to be rightly done to use it on fl studio

well the method is on Arduino Mega through out USB B (which is the same port of the board)

Man I'm not into coding that much so if there is something better to use please tell me and thanks a lot for your efforts, because when it work its going to work on the long run.

       switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
         case PRESSED:
           msg = " PRESSED.";
           // send MIDI note on message here
           break;
         case HOLD:
           msg = " HOLD.";
           break;
         case RELEASED:
           msg = " RELEASED.";
         //send MIDI note off message here
           break;

I've tried this code but nothing happend FL studio shows that something is pressing but no sound at all so I dont know where is the problem

I'm testing it with loopmidi+ Serial Midi converter to check

I've tried this code but nothing happend

No nothing will happen. I have just put a comment in the code saying what you need to do. You need to replace that comment with the real code. Any line that starts with a // is simply a comment.

There is a bit of programming to do.
But first you need to convert your key number into a MIDI note number, as only you have that information you will have to do this. Add a print of kpd.key[ i ].kchar to your code and write down the key number that gives you and what MIDI note that corresponds to. Then post that information.

Add that here:-

    if ( kpd.key[i].stateChanged )   // Only find keys that have changed state.
     {
       Serial.print(kpd.key[i].kchar); // add this to your code
       switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED

I want the code to be rightly done to use it on fl studio

Not come across that but it shouldn't matter.

Why have you deleted reply #4 - that is very very rude.

ya I know it shouldn't matter specifically for fl studio because when it's coded right any midi app will work with the keyboard.

Regarding reply delete excuse me but I don't know what are u talking about because I deleted nothing​:frowning::frowning:

I feel that I'm bashing my head with a wall with this thing I'm doing :confused: :cry:

I have uploaded this code to check something

#include <MIDI.h>
#include <Keypad.h>

const byte ROWS = 7; //Seven rows
const byte COLS = 10; //Ten columns
char keys[7][10] = {
  {1, 2, 3, 15, 14, 13, 12, 11, 10},
  {4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  {5, 5, 5, 5, 5, 5, 5, 5, 5, 0},
  {6, 6, 6, 6, 6, 6, 6, 6, 6, 0},
  {7, 7, 7, 7, 7, 7, 7, 7, 7, 0},
  {8, 8, 8, 8, 8, 8, 8, 8, 8, 0},
  {9, 9, 9, 9, 9, 9, 9, 9, 9, 0},
};
byte rowPins[ROWS] = {26, 28, 30, 32, 34, 36, 38 ,}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {A0, A1, A2, A3, A4, A5, A6, A7, A8,}; //connect to the column pinouts of the kpd

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );




void setup() {
    Serial.begin(9600);
}


void loop() {

    if (kpd.getKeys())
    {
      
        for (int i=0; i<LIST_MAX; i++)   // Scan the whole key list.
        {
            if ((kpd.key[i].stateChanged ) && (kpd.key[i].kstate == PRESSED))  // Only find keys that have changed state.
            {
              int myKey = (kpd.key[i].kchar);
                {                  
                Serial.print("Key ");
                Serial.print(myKey);       //  kpd.key[i].kchar
                
                }

            }
        }
    }
}

and these are the readings I'm having from key 1 to 49 on the serial monitor

Key 1
Key 4
Key 5
Key 6
Key 7
Key 8
Key 2
Key 4
Key 5
Key 6
Key 7
Key 8
Key 3
Key 4
Key 5
Key 6
Key 7
Key 8
Key 15
Key 4
Key 5
Key 6
Key 7
Key 8
Key 14
Key 4
Key 5
Key 6
Key 7
Key 8
Key 13
Key 4
Key 5
Key 6
Key 7
Key 8
Key 12
Key 4
Key 5
Key 6
Key 7
Key 8
Key 11
Key 4
Key 5
Key 6
Key 7
Key 8
Key 10

I don't know if that will give you a sign for something or to make it easy on me but I tried
and I know that the keys should be associated with notes to play and I know its like this
36, 37, 38, 39, 40, 41,
42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 58, 59,
60, 61, 62, 63, 64, 65,
66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83,
84,

But still I'm unable to code something like this from my knowledge

Regarding reply delete excuse me but I don't know what are u talking about because I deleted nothing

So was the whole of your post a single full stop?

OK on running that code but I asked you to put alongside each key number the MIDI note number you want it to correspond to. Do you not understand what I mean?

So for example KEY 3 - 60
so that would mean that when you press middle C on the keyboard it comes up as KEY 3 and so when you press KEY 3 you want to send MIDI note number 60 ( middle C).

I don't know the relationship between what piano keys you press results in what key is picked up from your matrix. Only you can tell me this because only you have access to what you have built.

Grumpy_Mike:
So was the whole of your post a single full stop?

OK on running that code but I asked you to put alongside each key number the MIDI note number you want it to correspond to. Do you not understand what I mean?

So for example KEY 3 - 60
so that would mean that when you press middle C on the keyboard it comes up as KEY 3 and so when you press KEY 3 you want to send MIDI note number 60 ( middle C).

I don't know the relationship between what piano keys you press results in what key is picked up from your matrix. Only you can tell me this because only you have access to what you have built.

Ok I want to know that and post the results but how?

I tried this and I dont know if this is what you mean and now my head is hurting more from the results

#include <MIDI.h>
#include <Keypad.h>

const byte ROWS = 6; //six rows
const byte COLS = 9; //nine columns
  
char keys[COLS][ROWS] = {
  {36, 37, 38, 39, 40, 41},
  {42, 43, 44, 45, 46, 47},
  {48, 49, 50, 51, 52, 53},
  {54, 55, 56, 57, 58, 59},
  {60, 61, 62, 63, 64, 65},
  {66, 67, 68, 69, 70, 71},
  {72, 73, 74, 75, 76, 77},
  {78, 79, 80, 81, 82, 83},
  {84, 85, 86, 87, 88, 89}
};
  
byte rowPins[ROWS] = {26, 28, 30, 32, 34, 36}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {A0, A1, A2, A3, A4, A5, A6, A7, A8}; //connect to the column pinouts of th

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
    Serial.begin(9600);
}

void loop() {

    if (kpd.getKeys())
    {

        for (int i=0; i<LIST_MAX; i++)   // Scan the whole key list.
        {
            if ((kpd.key[i].stateChanged ) && (kpd.key[i].kstate == PRESSED))  // Only find keys that have changed state.
            {
              int myKey = (kpd.key[i].kchar);
                {                 
                Serial.print("Key ");
                Serial.print(myKey);       //  kpd.key[i].kchar

                }

            }
        }
    }
}

Key 36
Key 45
Key 54
Key 63
Key 72
Key 81
Key 37
Key 46
Key 55
Key 64
Key 73
Key 82
Key 38
Key 47
Key 56
Key 65
Key 74
Key 83
Key 39
Key 48
Key 57
Key 66
Key 75
Key 84
Key 40
Key 49
Key 58
Key 67
Key 76
Key 85
Key 41
Key 50
Key 59
Key 68
Key 77
Key 86
Key 42
Key 51
Key 60
Key 69
Key 78
Key 87
Key 43
Key 52
Key 61
Key 70
Key 79
Key 88
Key 44

so what in humanity is this xD

so what in humanity is this xD

It is a hexadecimal number or number to the base sixteen. To be strict is is 0xD and represents the bit pattern 1101 or the number 13 in decimal notation.

Did you read reply #15?
You certainly didn’t understand it.

You have not supplied the information I need to compleat the code for you. Stop just trying random things and try and try to understand what I want.

You press a key on your Casio keyboard, and it prints out a number. Now what key did you press? Keys on a music keyboard have names A to G, for the white notes. Black notes are the sharp of the white note to the left of them written as #.

So in order to convert what your scanning matrix reads into what MIDI note to play, we need a list of what note name corresponds with what music key is being pressed.

The project can go no further without this information.

OK mate I understood you now thats easy just give me some time and you will see the list