Go Down

Topic: The project is done (Old 49 keys casio) to midi using Arduino MEGA (Read 1 time) previous topic - next topic

Grumpy_Mike

Quote
or is it impossible to run up this keyboard as midi
If this keyboard can run, it can run with MIDI.

What we are not seeing is any consistency getting your keyboard to report what key is pressed. On reply #17 I thought we had it, but subsequent code showed we had not. That is why I asked you to go back and check what you found there still worked.

This might be a problem with your solder joints or the wiring or the code. What I did say, over and over now, is that you are telling the keyboard libiary you have one size of matrix and then giving it a decoding matrix that is not this size. You must fix that problem first and that is where to start. Without fixing this problem first you can not go any further.

Oday_Alasali

If this keyboard can run, it can run with MIDI.

What we are not seeing is any consistency getting your keyboard to report what key is pressed. On reply #17 I thought we had it, but subsequent code showed we had not. That is why I asked you to go back and check what you found there still worked.

This might be a problem with your solder joints or the wiring or the code. What I did say, over and over now, is that you are telling the keyboard libiary you have one size of matrix and then giving it a decoding matrix that is not this size. You must fix that problem first and that is where to start. Without fixing this problem first you can not go any further.
For wiring I just soldered the wires directly on the board, so for the matrix size it's not compiling to be 6 x 9 because with the rows line it's 7 so it compiles with 7, is there an easy code that u can create for this so we try.

Oday_Alasali

In reply #17 that code gave differents keys number but IDK where is the problem to be found at the moment, I just felt we had this thing nearly working and now I'm in a different maze.

Oday_Alasali

I tested the keyboard with diode test and its likely that each flow is connected to one place among the whole board no multiconnection is happening so is this basically a code problem or this keyboard is a mess  :smiley-confuse:

Oday_Alasali

Just a simple question,,, if you saw the board of the original casio near the keyboard slots would that help in anything???

Grumpy_Mike

Quote
if you saw the board of the original casio near the keyboard slots would that help in anything?
No I don't think so.

Quote
so for the matrix size it's not compiling to be 6 x 9 because with the rows line it's 7 so it compiles with 7,
Sorry I don't understand what you mean. Just because code compiles does not mean there are no mistakes in it. It just means the compiler understands your commands. Whether those commands do what you wish is another matter.

Quote
but IDK where is the problem to be found at the moment,
Sorry what is the IDK?

Oday_Alasali

Sorry IDK means I don't know, I know the complie thing is about the code getting accepted and not about it being right, but what I mean is that Its not getting accepted to 6x9 because of the first line that is not included with (6)

for example :

1 1 1 1 1 1 1 1 1  ((This line is counted from the 6)) if I make it 6x9 like this it doesnt complie
1
2
3
4
5
6

Grumpy_Mike

The keys matrix in the code in reply #17 was correct, it compiles and it works. I don't know why on later versions of the code you have changed this. Forget everything you did after the code in #17. I have changed this code slightly here.
Code: [Select]

#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.println(myKey);       //  kpd.key[i].kchar

                }

            }
        }
    }
}


You will note that all the entries are in the keys matrix are negative numbers.
So run that code and make sure that for each key you have on the keyboard you get printed a negative number. There should be no repeat numbers and all keys should give some number. If that does not happen then stop there and check your wiring and report back what you see.

Then if that works press a key on the keyboard, and you will see a negative number. Go to the key matrix in your code and change the negitave number you saw for the positave number which is the MIDI note number that corrisponds to the key you just pressed. Do you understand this? Please say if you don't, because I think you are not understanding what I say and are ignoring things.

Repeat this until all the entries in the key matrix are positave numbers, that is that you have replaced all the negative numbers. Then when you press a key you will see printed in the serial monitor the MIDI note number that corrisponds to each key. When you are at this stage we are ready to change the code to send out the MIDI.

Oday_Alasali

Of course I understood, well maybe I was ignoring the things I didnt understand but that was in the begining after that I'm following what you were saying. Any way these are the results I got what do you think about it from key 1 to 49 pressed in order, Any hope  :'( ??

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


And I did something by my self just to look that out, if I exchange what I'm pressing with the key this is how it looks
char keys[COLS][ROWS] = {
  {-36, -45, -54, -63, -72, -81},
  {-37, -46, -55, -64, -73, -82},
  {-38, -47, -56, -65, -74, -83},
  {-39, -48, -57, -66, -75, -84},
  {-40, -49, -58, -67, -76, -85},
  {-41, -50, -59, -68, -77, -86},
  {-42, -51, -60, -69, -78, -87},
  {-43, -52, -61, -70, -79, -88},
  {-44,}
};

I see everything connected but cant understand what is this about 

Grumpy_Mike

Well take all the minus signs out from the keys matrix, and then those are the numbers you want to send out as MIDI messages.

Then alter the rest of the code from the setup function like this:-
Code: [Select]
void setup() {
 Serial.begin(115200); // set this the same as Hairless
}

void loop() {
 // 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.
     {
       pressed = kpd.key[i].kchar;
       switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
         case PRESSED:
           sendMIDI(chanel | 0x90, pressed, 100);
           break;
          case RELEASED:
           sendMIDI(chanel | 0x80, pressed, 0);
           break;
       }
     }
   }
 }
}  // End loop

void sendMIDI(byte type, byte note, byte velocity){
  Serial.write(type);
  Serial.write(note);
  Serial.write(velocity);
}

Oday_Alasali

I dont know if this is what you meant


Code: [Select]
#include <MIDI.h>
#include <Keypad.h>

const byte ROWS = 6; //six rows
const byte COLS = 9; //nine columns
 
char keys[COLS][ROWS] = {
  {36, 45, 54, 63, 72, 81},
  {37, 46, 55, 64, 73, 82},
  {38, 47, 56, 65, 74, 83},
  {39, 48, 57, 66, 75, 84},
  {40, 49, 58, 67, 76, 85},
  {41, 50, 59, 68, 77, 86},
  {42, 51, 60, 69, 78, 87},
  {43, 52, 61, 70, 79, 88},
  {44,}
};
 
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(49), rowPins, colPins, ROWS, COLS );
byte keyToMIDI[] = { 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};
byte pressed = 32;
byte chanel = 0; // MIDI channel to use


void setup() {
 Serial.begin(115200); // set this the same as Hairless
}

void loop() {
 // 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.
     {
       pressed = kpd.key[i].kchar;
       switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
         case PRESSED:
           sendMIDI(chanel | 0x90, pressed, 80);
           break;
          case RELEASED:
           sendMIDI(chanel | 0x80, pressed, 0);
           break;
       }
     }
   }
 }
}  // End loop

void sendMIDI(byte type, byte note, byte velocity){
  Serial.write(type);
  Serial.write(note);
  Serial.write(velocity);
}




Well I've tried this and still everything is messed up most from the first note and some notes on other keys

Grumpy_Mike

Quote
Well I've tried this and still everything is messed up most from the first note and some notes on other keys
Which means you have not done it properly, or there is something I am not understanding.

Can you recheck your steps.

Oday_Alasali

There is no steps this is the code I just modified and used and still the same results but with different keynumbers

Grumpy_Mike

Quote
There is no steps
Do you understand what "Can you recheck your steps" mean? Please do say when you don't understand something I have told you to do, I have told you this before, my rule is third time and I walk away!

OK I have been doing some checking and somewhere along the line you changed
Code: [Select]
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
into
Code: [Select]
Keypad kpd = Keypad( makeKeymap(48), rowPins, colPins, ROWS, COLS );
The variable keys is NOT a number, it is a pointer to an array.

However the big big problem now is that the Keypad library doesn't seem to return a released state, so while you can send MIDI note on, you can't trigger MIDI note off.

Try this code. I expect that for very short key presses you might get a note stuck on, and for longer presses you will just here a short note, but I want to test that the notes are in the right order.
Code: [Select]

#include <Keypad.h>

const byte ROWS = 6; //six rows
const byte COLS = 9; //nine columns
 
char keys[COLS][ROWS] = {
  {36, 45, 54, 63, 72, 81},
  {37, 46, 55, 64, 73, 82},
  {38, 47, 56, 65, 74, 83},
  {39, 48, 57, 66, 75, 84},
  {40, 49, 58, 67, 76, 85},
  {41, 50, 59, 68, 77, 86},
  {42, 51, 60, 69, 78, 87},
  {43, 52, 61, 70, 79, 88},
  {44}
};
 
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 );
int pressed = 32;
byte chanel = 0; // MIDI channel to use


void setup() {
 Serial.begin(115200); // set this the same as Hairless
}

void loop() {
 // 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.
     { 
       pressed = (kpd.key[i].kchar);           
       switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
         case HOLD:
           sendMIDI(chanel | 0x80, pressed, 0);
           break;

         case PRESSED:
           sendMIDI(chanel | 0x90, pressed, 80);
           break;
         case RELEASED: // this never seems to trigger
            sendMIDI(chanel | 0x80, pressed, 0);
         break;
   
       }
     }
       
   }
 }
}  // End loop

void sendMIDI(byte type, byte note, byte velocity){
  Serial.write(type);
  Serial.write(note);
  Serial.write(velocity);
}

Oday_Alasali

Do you understand what "Can you recheck your steps" mean? Please do say when you don't understand something I have told you to do, I have told you this before, my rule is third time and I walk away!
Well didn't you say that I exchange the numbers I made from the key reads instead the ones in the code and I did that .

_____________________________________________________________________________

Regarding the last code you gave me this one is the best till now even thou it's mixed but new readings are happening for keys and that never happenedŁˆ most of the keys were putting out the first note in the codes before

so what do you think about that ,.

Go Up