Old Cassio 61Key piano with arduino mega matrix

Hello fellow programmers/hobbyists..
Im reusing a old cassio 61-key keyboard to plug on my DAW (LPX).
I did sucecefully flashed the arduino_mega and played a bit with the daw.
But im facing a few problems. Will try to explain best i can:

If I use it as 60-key matrix everything work's great, only downsize is that key-61 does not work (i can live with that for now, but want things to go as per OEM possible)

The working code I've used is this:

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

const byte ROWS = 10; // 6 Linhas
const byte COLS = 6; // 11 Colunas
 
char keys[ROWS][COLS] = {
{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},
{90, 91, 92, 93, 94, 95},
{96, 97, 98, 99, 100, 101},
{102, 103, 104, 105, 106, 107}
};
 
byte rowPins[ROWS] = {22, 24, 26, 28, 30, 32, 34, 36, 38, 40}; //conectar-se às pinagens de linha do teclado
byte colPins[COLS] = {A0, A1, A2, A3, A4, A5}; //conectar-se às pinagens das colunas do teclado

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

byte pressed = 32;
byte chanel = 0; // Canal MIDI para usar

void setup() {
 Serial.begin(115200); // definir isso o mesmo que no 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;// + 12;
       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, 64);
           break;
       }
     }
   }
 }
}  // End loop

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

Now when I try edit this code to work with the extra row it goes wild. Not only it does not detect the C7 key and also every time i press another key I do not get a note_off and get 3 or 4 ghost keys.
For the sake of it I test this key matrix plugged as C3 (key 60) and works fine, so hardware is not the cause.

Next I went editing and updating the code to find what part is messing everything up.

As soon as I edit this bit, I start getting weird results. In this case pin_42 (I did test with bunch of other pins same result)

byte rowPins[ROWS] = {22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42}; //conectar-se às pinagens de linha do teclado

also I did change the matrix to include with no working results, same bug :

{108, 0, 0, 0, 0, 0}

From test I found that the part that letting me put the row pins goes wild when I set an 11'th pin row of the matrix.

Have someone a ideia how to approach it? Hardware wise its ok because artifacts appear as soon I press a key and not only when I press keys that are matrix linked with the problematic one, so it can only be code issue.

Can someone give a newbie a hand? Or brain :slight_smile:

ctk500.pdf (1.54 MB)

SOLVED!!!!!!!!
As my suspicion it was a code bit that have caused the problem every time i tryed to set an 11'th row.
The problem was on library keypad.h residing on my library folder.
I've just changed the following line from 10 to 12 (one to spare)

#define MAPSIZE 12		// MAPSIZE is the number of rows (times 16 columns)

and uploaded the code and voilá its everything working with hairless.
Now next goal is MIDI native support for the keyboard and implement a few jog wheel's and encoders to the MIDI keyboard to customize it for my goals.

Anyone have ideia how to convert this working project into a MIDI native one?

Anyone have ideia how to convert this working project into a MIDI native one?

You need to use a processor with USB MIDI capability, like a Leonardo, or Arduino Micro. They can look like a USB MIDI device with the USB-MIDI.h library.

Nice, I've allready ordered a arduino nano to play with, but since I want to build some pads, faders, pots and encoders implemented in the same device it that may be too much pins for a "non-mega" arduino.
As for pads and buttons I know that I can make a matrix to drive the pads and the buttons.

My problem is now how to set up pins and note commands for the faders, pots and encoders, plus some LED's beneath the keys (key play, key record, etc)

Sort of, if I receive MIDI code for recording then LED1REC should light up via MIDI_IN.

Could Hiduino be the soluction for me?

Could Hiduino be the soluction for me?

It could be but I wouldn't even consider it. Once it is on your nano or Uno then it needs to be removed before you can change your code and then replaced before you can run it. This makes the development cycle very long and tedious. Better use an Arduino micro.

it that may be too much pins for a "non-mega" arduino.

You can always expand the number of inputs / outputs by adding one or more port expander chips like the MCP23S17. As each chip gives you 16 extra I/O pins and you can add up to 8 chips to the same 4 Arduino pins you can have 128 extra I/O pins which should be enough for anything.

My problem is now how to set up pins and note commands for the faders, pots and encoders, plus some LED's beneath the keys (key play, key record, etc)

It is not hard, read a pin if it has changed since last time sent then send the CC message. You do exactly the same with faders, read the pot is it changed significantly since last time you read it? If so send the new value to the CC channel.
Start off with just one and build it up.