Go Down

Topic: Keyboard (Piano) Scanner Casio CTK 485 - Arduino Mega 2560 (Read 740 times) previous topic - next topic

seileremerson

Apr 02, 2020, 02:47 pm Last Edit: Apr 14, 2020, 01:35 pm by seileremerson
Hello, initially I would like to say that my experience with programming and Arduino is the most basic possible, in case I know how to put the programming on the board, but I don't know how to program. Sorry for my English (Google Translate)

Well let's get to the problem, I have an old CASIO CTK 485 keyboard, with 61 keys, a simple keyboard with no key sensitivity. It turns out that his motherboard burned and there is no way to fix it, so I found some projects on the internet that use Arduino to create a controller in order to use the keyboard on the computer.

Among the projects I found this https://github.com/oxesoft/keyboardscanner, which uses the Arduino that I own the Mega 2560, but it only works with keyboards with sensitivity control on the keys. Furthermore, it is necessary from what I understand to convert the Arduino's USB signal to an emulated MIDI signal using software.

I would like to use my Arduino mega 2560 connected to the key wires, in the project above, the 16 wires are connected to the digital output. I already have the layout of the key matrix in the 8x8 case that I found in the keyboard service manual.
I looked on the various google pages and I can't find anything to help me with my mega 2560, so I come to ask the community for help.

CASIO CTK 485 Service Manual: https://www.manualslib.com/manual/1199647/Casio-Ctk-485.html?page=5#manual

Matrix:
https://drive.google.com/file/d/1TGL9TPSyXwyCuUAh00MxrbGivFmqURsn/view

Pins:
https://drive.google.com/file/d/1qoLTb0JXzXIVgIPiLArU9sGTYDDEnK3b/view

Someone could help me with this project, remembering that I am a layman.

seileremerson

#1
Apr 02, 2020, 08:40 pm Last Edit: Apr 03, 2020, 12:58 am by seileremerson
Good afternoon folks, after a night and a morning of searching I found the solution to connect my old CASIO CTK 485 to the Arduino Mega 2560.
I will present the step by step that I followed to help adventurers who, like me, do not understand much about electronics and programming.

In a search for forums, youtube, google I found several solutions focused on Arduino Uno together with circuits composed of other elements like Cis of which I don't understand anything. However, to my unhappiness, I found only one material with the Arduino Mega 2560, which had little information for my case.
So I decided to dig deeper into the Arduino forum when I came across the post by our friend Oday_Alasali, who with the help of our friend Grumpy_Mike managed make the 49-key CASIO keyboard work.

The first step I had to do was: disassemble, remove the solder from the flat cable that came out of the keys on my keyboard and went to his motherboard.



After that, it was necessary to map the keys, which I believed were mapped by my CASIO service manual. Sad mistake, the configuration of the keys were all wrong, so I had to take the multimeter on the diode scale and test each key to find out which combination of wires corresponded to the activated keys.
I used a spreadsheet to help me with the organization, I will provide the link.

PLAN MAPER

For those who do not know, it is the combination of wires that generates the contact of the keys and corresponds to the notes. In my case, I got a matrix as follows:



After finding each combination, it was necessary to find which note corresponded to each key, in order to finally find the MIDI number corresponding to each note. This part is very important for our program.
I used the table on this website , to find out which MIDI number corresponded to each key.




With this information in hand, I proceeded to the program code provided by our colleagues mentioned above.
The first thing I changed was the following lines, informing the number of columns and rows in my matrix.


Code: [Select]
const byte ROWS = 8; // 8 Linhas
const byte COLS = 8; // 8 Colunas


After that, I made the modification in the matrix itself, informing the MIDI numbers corresponding to each key mapped above.

Code: [Select]
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, 90, 91},
  {92, 93, 94, 95, 96, 97, 98, 99}
};


Finally, I configured which outputs I would use on my Arduino Mega 2560.

Code: [Select]
byte rowPins[ROWS] = {22, 26, 30, 34, 38, 42, 46, 50}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {A0, A2, A4, A6, A8, A10, A12, A14}; //connect to the column pinouts of the kpd


Due to the space for fitting the pins I opted to use alternate outputs, but this is a matter of taste.



After that, using the Arduino software I put the program inside the board.
I used Hairless to convert the signal sent by USB to a MIDI signal and LoopBe1 to simulate a MIDI port in this step we already have sound.
I still need to learn how to actually use a controller keyboard, but I leave that information to help other colleagues who may need it.
I leave the complete code I used based on the code provided by friend friends Oday_Alasali and Grumpy_Mike

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

const byte ROWS = 8; // 8 Linhas
const byte COLS = 8; // 8 Colunas
 
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, 90, 91},
  {92, 93, 94, 95, 96, 97, 98, 99}
};
 
byte rowPins[ROWS] = {22, 26, 30, 34, 38, 42, 46, 50}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {A0, A2, A4, A6, A8, A10, A12, A14}; //connect to the column pinouts of the kpd

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

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

seileremerson

#2
Apr 02, 2020, 08:49 pm Last Edit: Apr 03, 2020, 12:57 am by seileremerson
Versão do Texto em Português BR

Boa tarde pessoal, após uma noite e uma manhã de buscas encontrei a solução para ligar meu antigo CASIO CTK 485 ao Arduino Mega 2560.

Vou apresentar o passo a passo que segui para ajudar aventureiros que como eu, não entendem muito de eletrônica e programação.

Em uma busca pelos fóruns, youtube, google encontrei diversas soluções focadas ao Arduino Uno em conjunto com circuitos compostos por outros elementos como Cis dos quais eu não entendo nada. Porém, para minha infelicidade encontrei apenas um material com o Arduino Mega 2560, o qual possuía poucas informações para o meu caso.


Resolvi então buscar mais a fundo dentro do fórum do Arduino quando me deparei com o post de nosso amigo Oday_Alasali, que com a ajuda do nosso amigo Grumpy_Mike conseguiu fazer o teclado CASIO de 49 teclas funcionar.

O primeiro passo que precisei fazer foi: desmontar, remover a solda do cabo flat que sai das teclas do meu teclado e ia para a placa mãe dele.



Após isso, foi necessário mapear as teclas, as quais eu acreditava estarem mapeadas pelo manual de serviço do meu CASIO. Triste engano, a configuração das teclas estavam todas erradas, então, precisei pegar o multímetro na escala de diodos e testar cada tecla para descobrir qual combinação de fios correspondia as teclas acionadas.

Utilizei uma planilha para me auxiliar na organização, vou disponibilizar o link.

PLANILHA

Para quem não sabe, é a combinação de fios que gera o contato das teclas e corresponde as notas. No meu caso, consegui uma matriz da seguinte forma:



Depois de encontrar cada combinação foi necessário encontrar qual nota correspondia a cada tecla, para por fim encontrar o número MIDI correspondente a cada nota. Essa parte é muito importante para nosso programa.

Utilizei a tabela deste site, para saber qual número MIDI correspondia a cada tecla.





Com essas informações em mãos segui para o código do programa fornecido pelos nossos colegas mencionados acima.

A primeira coisa que alterei foram as seguintes linhas, informando o número de colunas e linhas da minha matriz.

Code: [Select]

const byte ROWS = 8; // 8 Linhas
const byte COLS = 8; // 8 Colunas


Após isso, fiz a  modificação na matriz em si, informando os números MIDI correspondentes a cada tecla mapeada acima.

Code: [Select]
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, 90, 91},
  {92, 93, 94, 95, 96, 97, 98, 99}
};


Por fim, configurei quais saídas utilizaria no meu Arduino Mega 2560.

Code: [Select]


byte rowPins[ROWS] = {22, 26, 30, 34, 38, 42, 46, 50}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {A0, A2, A4, A6, A8, A10, A12, A14}; //connect to the column pinouts of the kpd


Devido ao espaço para encaixe dos pinos optei em usar saídas alternadas, mas isso é questão de gosto.



Após isso, utilizando o software do Arduino coloquei o programa para dentro da placa.

Utilizei o Hairless para converter o sinal enviado pelo USB para um sinal MIDI e o LoopBe1 para simular uma porta MIDI nesta etapa já possuímos som.

Ainda preciso aprender como usar um teclado controlador de fato, mas deixo essas informações para ajudar outros colegas, que possam precisar.

Deixo o código completo que usei baseado no código disponibilizados pelos amigos amigo Oday_Alasali e Grumpy_Mike.


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

const byte ROWS = 8; // 8 Linhas
const byte COLS = 8; // 8 Colunas
 
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, 90, 91},
  {92, 93, 94, 95, 96, 97, 98, 99}
};
 
byte rowPins[ROWS] = {22, 26, 30, 34, 38, 42, 46, 50}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {A0, A2, A4, A6, A8, A10, A12, A14}; //connect to the column pinouts of the kpd

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

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




Go Up