Piano keyboard to arduino.

Hey everyone,

Me and a friend are trying to connect a piano keyboard to the arduino.
We came as far to connecting a light directly with the breadboard and that works, but we now have to decode the signals the keyboard sends.
We are using a matrix with 6 rows and 5 collums. The problem is that we have to find a way to see what buttons we press. We only have 12 digital slots on the arduino uno, so the tip we got was to change the current on the collums one by one and then we can see what row is beeing used.. But we dont really know how to get a current to all the Collums with the arduino uno.

Code so far(we know its not good at all but its all we tried and all we understand a little ;))

#include <Keypad.h>

const int ledPin = 2;
int var1 = 0;
int var2 = 0;
int octbegin =  0;
int octeind = 1;
int octaaf = 0;


const byte rows = 6; //6 rows
const byte cols = 5; //5 columns
char keys[rows][cols] = {
  {'1','2','3','4','5'},
  {'6','7','8','9','10'},
  {'11','12','13','14','15'},
  {'16','17','18','19','20'},
  {'21','22','23','24','25'},
  {'26','27','28','29','30'}
};
byte rowPins[rows] = {8, 7, 6, 5, 4, 3}; //connect to the row pinouts of the keypad
byte colPins[cols] = {13, 12, 11, 10, 9}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

#define ledpin 13

void setup()
{
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
}

void loop()
{
  char key = keypad.getKey();

 if(key)  // Check for a valid key.
  {
    switch (key)
    {
      case '1':
        Serial.println("test");
        digitalWrite(ledPin, HIGH);  
  }
}

for (var1 = 0; var1 < 2; var1++;)
{
 digitalwrite(var1)
 octaaf = 63;
if (var1 = octbegin)
{
octaaf = octaaf * 64;
}
}
Serial.print(octaaf)

Arduino has 20 digital inputs, you can use analog as digital. With 8 x 8 matrix it's easy to get 64 keys. How to read matrix, look in playground:
http://arduino.cc/playground/Main/InterfacingWithHardware#keyb

Does the keyboard have the rest of the piano attached?

hey dudes,

my mate and I are working on a schoolproject and are using an arduino and C#.
we used a keypad tutorial: http://arduino.cc/playground/Main/KeypadTutorial
we cant really find out what we are doing wrong, because nothing happens when we press any button on our keyboard, shouldnt it be sending "test" to our serial monitor?

here is our code, help us out please :)!!:

#include <Keypad.h>

const int ledPin = 2;
int var1 = 0;
int var2 = 0;
int octbegin =  0;
int octeind = 1;
int octaaf = 0;
int serial_in;

const byte rows = 6; //6 rows
const byte cols = 5; //5 columns
char keys[rows][cols] = {
  {'1','2','3','4','5'},
  {'6','7','8','9','10'},
  {'11','12','13','14','15'},
  {'16','17','18','19','20'},
  {'21','22','23','24','25'},
  {'26','27','28','29','30'}
};
byte rowPins[rows] = {13, 12, 11, 10, 9}; //connect to the row pinouts of the keypad
byte colPins[cols] = {6, 5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

void setup()
{
  Serial.begin(9600);

}

void loop()
{
  char key = keypad.getKey();
    
    
    
 if(key)  // Check for a valid key.
  {
    switch(key)
    {
      case '1':
        Serial.println("test");
       break;
        case '2':
        Serial.println("test");
       break;
       case '3':
        Serial.println("test"); 
       break;
       case '4':
        Serial.println("test");
        digitalWrite(ledPin, HIGH); 
       break;
       case '5':
        Serial.println("test");
        digitalWrite(ledPin, HIGH); 
       break;
       case '6':
        Serial.println("test"); 
       break;
       case '7':
        Serial.println("test");
       break;
       case '8':
        Serial.println("test");
       break;
       case '9':
        Serial.println("test");
        digitalWrite(ledPin, HIGH); 
       break;
       case '10':
        Serial.println("test");
       break;
       case '11':
        Serial.println("test");
       break;
       case '12':
        Serial.println("test");
       break;
       case '13':
        Serial.println("test");
       break;
       case '14':
        Serial.println("test");
       break;
       case '15':
        Serial.println("test");
       break;     
  }
}





}

How about debugging your code?

void loop()
{
  char key = keypad.getKey();

  Serial.println( key );

Then you'll know wtf your function is getting and can move from there.

You're the ones with the hardware and I don't want to play back and forth Q&A. Besides, someone else here has a thread on the same basic subject. Would that be your partner?

we are getting nothing on serial monitor, so our key is nothing???
what causes this and how do we fix??
thx for the help.

You are the ones with the hardware. Very hard to test from here, my PSI is not enough. Only good for 1 or 2 meters.

Learn to debug by practice. Add some more print statements to see where your code is going.

If 5V should be coming out of the keypad to a pin when a key is pressed then add a junction, 220-330 ohm resistor and led to ground and see if power is flowing. If the pin is supposed to be grounded then test that.

This is school work you say. A major part of your lesson is going to be learning to troubleshoot. Check, change, test, repeat until all wrinkles are gone. Or take easier courses like underwater basket weaving.

I've merged these two threads, because they looked to me to have very similar content.
HTH

AWOL

(@GoForSmoke - I teach SCUBA - maybe I'll bring up your specialism with PADI)

we have tried everything!!! but we really cant find out what we do wrong.
please anyone help us out we need help pls SOS

Did you try GoForSmoke's suggestion in reply #4? What output did you get?

 {'11','12','13','14','15'},
case '11':
        Serial.println("test");
       break;

'11' ?
What have you been taught about characters?

Print the same "test" string for every case is...not sensible.

if you read comment #5 it tells: we are getting nothing on the serial monitor . :frowning:

void setup()
{
  Serial.begin(9600);
  Serial.println ("Setup");
}

void loop()
{
  char key = keypad.getKey();
   
  if(key)  // Check for a valid key.
  {
     Serial.print ("Key: ");
     Serial.println (key, HEX);

oolino:
if you read comment #5 it tells: we are getting nothing on the serial monitor . :frowning:

Can you post the code you were using when this occurred?

to AWOL: we tried, but we are getting the message:
Setup
Key: 35
allthough, we dont even have 35 keys???

to wildbill:

#include <Keypad.h>

const int ledPin = 2;
int var1 = 0;
int var2 = 0;
int octbegin =  0;
int octeind = 1;
int octaaf = 0;
int serial_in;

const byte rows = 6; //6 rows
const byte cols = 5; //5 columns
char keys[rows][cols] = {
  {'1','2','3','4','5'},
  {'6','7','8','9','10'},
  {'11','12','13','14','15'},
  {'16','17','18','19','20'},
  {'21','22','23','24','25'},
  {'26','27','28','29','30'}
};
byte rowPins[rows] = {13, 12, 11, 10, 9}; //connect to the row pinouts of the keypad
byte colPins[cols] = {6, 5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

void setup()
{
  Serial.begin(9600);

}

void loop()
{
  char key = keypad.getKey();
    
    Serial.println( key );

}

Setup
Key: 35

No-one said you had 35 keys.
35 hex is ASCII '5'.

HTH

we didnt even press any button, it just showed up...

So, you probably need to check your wiring.
If you followed the code I posted, it didn't "just show up".
Can you repost your code.

sure mate, here it is:

#include <Keypad.h>

const int ledPin = 2;
int var1 = 0;
int var2 = 0;
int octbegin =  0;
int octeind = 1;
int octaaf = 0;
int serial_in;

const byte rows = 6; //6 rows
const byte cols = 5; //5 columns
char keys[rows][cols] = {
  {'1','2','3','4','5'},
  {'6','7','8','9','10'},
  {'11','12','13','14','15'},
  {'16','17','18','19','20'},
  {'21','22','23','24','25'},
  {'26','27','28','29','30'}
};
byte rowPins[rows] = {13, 12, 11, 10, 9}; //connect to the row pinouts of the keypad
byte colPins[cols] = {6, 5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

void setup()
{
  Serial.begin(9600);
Serial.println ("Setup");
}

void loop()
{
  char key = keypad.getKey();
    
   if(key)  // Check for a valid key.
  {
     Serial.print ("Key: ");
     Serial.println (key, HEX);
  }
}

You realy need to address this

{'11','12','13','14','15'},
  {'16','17','18','19','20'},
  {'21','22','23','24','25'},
  {'26','27','28','29','30'}

problem before we go much further.
Two chars into one char does not go.