Go Down

Topic: The project is almost done **Matrix coded 100%**just a last help for midi outs (Read 671 times) previous topic - next topic

Oday_Alasali

May 15, 2019, 04:53 am Last Edit: May 18, 2019, 05:48 am by Oday_Alasali Reason: Reached a new level where people might be able to help easily as I hope.
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  :)  :) .... 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

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

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)*********




Coding Badly


@Oday_Alasali, stop cross-posting.  Last warning.

Other thread removed.


Oday_Alasali

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

Coding Badly

I saw your warning...
...and ignored it.

...but I can't delete threads...
Unnecessary.  I have already cleaned up your mess.



Grumpy_Mike

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

Oday_Alasali

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

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 );

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

Grumpy_Mike

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

Oday_Alasali

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)

Oday_Alasali

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.

Oday_Alasali

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

Grumpy_Mike

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


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

Oday_Alasali

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☹️☹️

Oday_Alasali

I feel that I'm bashing my head with a wall with this thing I'm doing  :smiley-confuse:  :'(

Oday_Alasali

I have uploaded this code to check something

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

Go Up