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
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.

Oday_Alasali

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?

Oday_Alasali

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

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.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

Grumpy_Mike

Quote
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.

Oday_Alasali

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

Oday_Alasali

In order of keys I suppose it has to be like this and I hope this is what you are asking for, or then I'ma be so stupid   :smiley-cry:


Code: [Select]
KEY    MIDI NOTES
READS    36-84
+
KEY
NUMBERS
______  ___________
Key 36(1)  36: C
Key 45(2)  37: C#/Db
Key 54(3)  38: D
Key 63(4) 39: D#/Eb
Key 72(5)  40: E
Key 81(6)  41: F
Key 37(7)  42: F#/Gb
Key 46(8)  43: G
Key 55(9)  44: G#/Ab
Key 64(10)  45: A
Key 73(11)  46: A#/Bb
Key 82(12)  47: B
Key 38(13)  48: C
Key 47(14)  49: C#/Db
Key 56(15)  50: D
Key 65(16)  51: D#/Eb
Key 74(17)  52: E
Key 83(18)  53: F
Key 39(19)  54: F#/Gb
Key 48(20)  55: G
Key 57(21)  56: G#/Ab
Key 66(22)  57: A
Key 75(23)  58: A#/Bb
Key 84(24)  59: B
Key 40(25)  60: C
Key 49(26)  61: C#/Db
Key 58(27)  62: D
Key 67(28)  63: D#/Eb
Key 76(29)  64: E
Key 85(30)  65: F
Key 41(31)  66: F#/Gb
Key 50(32)  67: G
Key 59(33)  68: G#/Ab
Key 68(34)  69: A
Key 77(35)  70: A#/Bb
Key 86(36)  71: B
Key 42(37)  72: C
Key 51(38)  73: C#/Db
Key 60(39)  74: D
Key 69(40)  75: D#/Eb
Key 78(41)  76: E
Key 87(42)  77: F
Key 43(43)  78: F#/Gb
Key 52(44)  79: G
Key 61(45)  80: G#/Ab
Key 70(46)  81: A
Key 79(47)  82: A#/Bb
Key 88(48)  83: B
Key 44(49)  84: C























Grumpy_Mike

Thanks that looks a lot better.
What are the numbers in brackets? Are they the key numbers? If so then try this code:-
Code: [Select]

#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 );
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 = keyToMIDI[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);
}

It compiles but I have not tested it. Set the baud rate of Hairless to 115200.

The array that converts your key presses into MIDI note numbers is called keyToMIDI.

Oday_Alasali

The numbers are the wire number according to the ribbons in the picture I provided and the matrix I will try that code as soon as possible and I will reply back, thanks alot for your help.

Grumpy_Mike

Quote
The numbers are the wire number according to the ribbons in the picture
Ah, you might have to have a different matrix then, you might get some sounds out of some keys though. It is just a matter of getting them in the right order. I think we are close now though.

Oday_Alasali

Mate I tried this code and for the first time I'm getting the keyboard working also worked for FL studio but as u said its so messed up  :smiley-mr-green: most of the keys are working to be Note 36 which is the first note and some keys do different notes for each time you press at it,, But I know that we are nearly close to complete up this thing with your help and I appreciate that.


EDIT: and 2 keys are not reading in midi but they are working and the arduino blinks when pressed

Oday_Alasali

Ah, you might have to have a different matrix then, you might get some sounds out of some keys though. It is just a matter of getting them in the right order. I think we are close now though.
Well my diode test to the matrix is 100% right because I think it only work in one way but could the numberings be wrong?? if yes then I'm in a middle of a tornado thats made of possibilities even through coding or pins on the arduino

Oday_Alasali

Sorry but since my head is really missed up I forgot to edit the picture of the pins, It was all changed since the first post but the placements are the same as the code

Code: [Select]
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






Grumpy_Mike

OK try this:-
Code: [Select]

#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 );
byte keyToMIDI[] = { 36,42,48,54,60,66,72,78,84,37,43,49,55,61,67,73,79,38,
                     44,50,56,62,68,74,80,39,45,51,57,63,69,75,81,40,46,52,
                     58,64,70,76,82,41,47,53,59,65,71,77,83};
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 = keyToMIDI[kpd.key[i].kchar - 36];
       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 & 0x7F);
  Serial.write(velocity);
}

Oday_Alasali

Its still messed up most of the keyboard is reading as the first note

but ******All keys are working***** : before a few didnt even read


Grumpy_Mike

OK we are going to have to do some debugging here.
Open the serial monitor and set the baud rate to 115200 from the drop down menu in the corner. Run this code and press the keys on the keyboard in turn and post the printout so I can see if I can work out what is happening.

Code: [Select]

#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 );
byte keyToMIDI[] = { 36,42,48,54,60,66,72,78,84,37,43,49,55,61,67,73,79,38,
                     44,50,56,62,68,74,80,39,45,51,57,63,69,75,81,40,46,52,
                     58,64,70,76,82,41,47,53,59,65,71,77,83};
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 = keyToMIDI[kpd.key[i].kchar - 36];
       Serial.print("Key to look up is:-");
       Serial.println(kpd.key[i].kchar - 36);
       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 & 0x7F);
  Serial.write(velocity);
  */
}

Go Up