I need help.Arduino Uno keyboard (Piano)

A friend of mine sent it to me and i just did what he did. He says it worked for him, but I'm beginning to see that may not be the case. Yes they are Diodes. He told me that the signals that run there will be isolated, just so that it doesn't cross. Sorry if i dont know much, it is my first time and i thought it was going to be simple.

Could you maybe tell me what i can change on the breadboard that may make it better. or what i can do to actually make it work

And what did he say? You seem to be drip feeding us with information.

That circuit on your board connects to something what?

My guess is that it is a scanning keyboard. I am guessing that you don't know what that means. The keyboard has two switches for each key. One indicates when the switch is broken and means a key has just been pressed. The other indicates that a switch is at the end of its travel.

The scanning bit means that it is constantly looking at one switch at a time maybe until a switch is detected, maybe not, but there is also something that gives you the note as well.

The keys do nothing to generate a MIDI signal. The job of the software is to time how long it takes between these two switch presses and process that information into a velocity value to accompany what ever note is pressed.

Your code contains none of this, which will be needed to make the system work.

So go back to your 'friend' and ask him these questions about the details that you are missing. Like what is this keyboard and what the software should be.

This is not simple by any means.

No, the keys are made from bent paper clips. There is no velocity sensitivity it is just on or off. There is no MIDI send in this project either.

ohk so i confronted him about this, he basically told me some bullshit story about how he didnt understand which is hard to believe since he's "Made his own", I did look on youtube and found this girls code. I plugged it in and the green light seems to be flashing less frequently and im seeing less of the warning message, Which im guessing is good?

Heres her code. Also do you mind just sending any sketch or image or something that you know will work for my bread board. I really appreciated the help your doing for me. Thank you

// midi channels
const int CHANNEL1 = 0;
const int CHANNEL2 = 1;

// pitch bend
const int PITCHBEND_CMD = 224;
const int PB_LSB = 0;
int PB_VALUE = 64;
bool PBisOn = false;

// control change 
const int CONTROLCHANGE1_CMD = 176;
const int CC_LSB = 1;
int CC_VALUE = 64;
bool CCisOn = false;

// notes
const int NOTE_ON_CMD = 144;
const int NOTE_OFF_CMD = 128;
const int NOTE_VELOCITY = 127;

// drums
int DRUM_VELOCITY =  0;
int DRUM_NOTE[] = {31,32,33,34,35,36}; 
const int DRUM_TOL = 19;
bool drumOn[] = {false,false,false,false,false,false};

// joystick analog pins
const int X_pin = 0;
const int Y_pin = 1; 

// drum pins
const int drumPin[] = {2,3,4,5,6,7};

// keyboard matrix
const int NUM_ROWS = 8;
const int NUM_COLS = 7;

// Row input pins
const int row1Pin = 5;
const int row2Pin = 6;
const int row3Pin = 7;
const int row4Pin = 8;
const int row5Pin = 9;
const int row6Pin = 10;
const int row7Pin = 11;
const int row8Pin = 12;

// 74HC595 pins
const int dataPin = 4;
const int latchPin = 3;
const int clockPin = 2;

boolean keyPressed[NUM_ROWS][NUM_COLS];
uint8_t keyToMidiMap[NUM_ROWS][NUM_COLS];

// bitmasks for scanning columns
int bits[] =
{ 
  B10000000,
  B01000000,
  B00100000,
  B00010000,
  B00001000,
  B00000100,
  B00000010,
  B00000001
};

// MIDI baud rate
const int SERIAL_RATE = 31250; // needs to be 31250 when going through midi port, can be 9600 for hairless

void setup()
{
  
  int note = 28; 
  
  for(int colCtr = 0; colCtr < NUM_COLS; ++colCtr)
  {
    for(int rowCtr = 0; rowCtr < NUM_ROWS; ++rowCtr)
    {
      keyPressed[rowCtr][colCtr] = false;
      keyToMidiMap[rowCtr][colCtr] = note;
      note++;
    }
  }

  // setup pins output/input mode
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);

  pinMode(row1Pin, INPUT);
  pinMode(row2Pin, INPUT);
  pinMode(row3Pin, INPUT);
  pinMode(row4Pin, INPUT);
  pinMode(row5Pin, INPUT);
  pinMode(row6Pin, INPUT);
  pinMode(row7Pin, INPUT);
  pinMode(row8Pin, INPUT);

  Serial.begin(SERIAL_RATE);
}

void loop()
{
  
  // keyboard
  for (int colCtr = 0; colCtr < NUM_COLS; ++colCtr)
  {
    //scan next column
    scanColumn(colCtr);

    //get row values at this column
    int rowValue[NUM_ROWS];
    rowValue[0] = digitalRead(row1Pin);
    rowValue[1] = digitalRead(row2Pin);
    rowValue[2] = digitalRead(row3Pin);
    rowValue[3] = digitalRead(row4Pin);
    rowValue[4] = digitalRead(row5Pin);
    rowValue[5] = digitalRead(row6Pin);
    rowValue[6] = digitalRead(row7Pin);
    rowValue[7] = digitalRead(row8Pin);

    // process keys pressed
    for(int rowCtr=0; rowCtr<NUM_ROWS; ++rowCtr)
    {
      if(rowValue[rowCtr] != 0 && !keyPressed[rowCtr][colCtr])
      {
        keyPressed[rowCtr][colCtr] = true;
        sendMidiMessage(NOTE_ON_CMD, CHANNEL1, keyToMidiMap[rowCtr][colCtr], NOTE_VELOCITY);
      }
    }

    // process keys released
    for(int rowCtr=0; rowCtr<NUM_ROWS; ++rowCtr)
    {
      if(rowValue[rowCtr] == 0 && keyPressed[rowCtr][colCtr])
      {
        keyPressed[rowCtr][colCtr] = false;
        sendMidiMessage(NOTE_OFF_CMD, CHANNEL1, keyToMidiMap[rowCtr][colCtr], NOTE_VELOCITY);
      }
    }
  }

  // joystick X-axis - pitch bend
  PB_VALUE = (analogRead(X_pin) / 1024.0) * 127;
  if (PB_VALUE < 53 || PB_VALUE > 56) {
    sendMidiMessage(PITCHBEND_CMD,CHANNEL1,PB_LSB,PB_VALUE);
    PBisOn=true;
  }
  else if (PBisOn==true && PB_VALUE > 53 && PB_VALUE < 56) {
    sendMidiMessage(PITCHBEND_CMD,CHANNEL1,PB_LSB,PB_VALUE);
    PBisOn=false;
  }

  // joystick Y-axis - control change
  CC_VALUE = (analogRead(Y_pin) / 1024.0) * 127;
  if (CC_VALUE < 53 || CC_VALUE > 56) {
    sendMidiMessage(CONTROLCHANGE1_CMD,CHANNEL1,CC_LSB,CC_VALUE);
    CCisOn=true;
  }
  else if ( CCisOn == true && CC_VALUE > 53 && CC_VALUE < 56) {
    sendMidiMessage(CONTROLCHANGE1_CMD,CHANNEL1,CC_LSB,CC_VALUE);
    CCisOn=false;
  }

  // drums
  for(int drumNo = 0; drumNo < 6; ++drumNo){
    DRUM_VELOCITY = (analogRead(drumPin[drumNo]) / 1023.0) * 127;
    if( drumOn[drumNo]==false && DRUM_VELOCITY > DRUM_TOL ){
      sendMidiMessage(NOTE_ON_CMD,CHANNEL2,DRUM_NOTE[drumNo],DRUM_VELOCITY);
      drumOn[drumNo]=true;
    }
    else if ( drumOn[drumNo]==true && DRUM_VELOCITY <= DRUM_TOL ) {
      sendMidiMessage(NOTE_OFF_CMD,CHANNEL2,DRUM_NOTE[drumNo],DRUM_VELOCITY);
      drumOn[drumNo]=false;
    }
  }
}

// functions

void sendMidiMessage(int cmd, int channel, int lsb, int msb) {
  Serial.write(cmd + channel); // send command plus the channel number
  Serial.write(lsb); // least significant bit 
  Serial.write(msb); // most significant bit
}

void scanColumn(int colNum)
{
  digitalWrite(latchPin, LOW);

  if(0 <= colNum && colNum <= 7)
  {
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //right sr
    shiftOut(dataPin, clockPin, MSBFIRST, bits[colNum]); //left sr
  }
  else
  {
    shiftOut(dataPin, clockPin, MSBFIRST, bits[colNum-8]); //right sr
    shiftOut(dataPin, clockPin, MSBFIRST, B00000000); //left sr
  }
  digitalWrite(latchPin, HIGH);
}
`type or paste code here`

Hi,
To add code please click this link;

Your code will then be in a scrolling window, it will be easier to read.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

People make things all the time when they don't know what they are doing. They even tell other people how to make things when they themselves don't know what they are doing. There is a special web site for them it is called 'Instructables' It is full of people telling other people howto make stuff when they have no idea of what they themselves are doing.

Two things,

  1. you know how to post code correctly here, so why is this posted as such a mess.
  2. You can't just use any old code, it has to be code that matches the hardware that you have. This code clearly does not match what you have. For example the code talks about a joystick and 75HC595 shift register which is clearly not part of your setup.

Plus the fact that there is the utterly stupid comment

Which shows the writer of the code didn't know what she was talking about.

I can't do that because there is vital information missing. Even if I knew that information I would not be able to do it blind (that is without having your hardware).

All keyboard manufacturers have their own way of scanning their keyboards. Your friend happened to be lucky in that he copied some project that used the same keyboard manufacture as he had. So what I need to know was what keyboard manufacture did he have and what do you have? It looks like the code you just posted was written for a different manufacturer than your friend, and possibly you.

I think you need to take a step back and learn what MIDI is and what it isn't. There are plenty of online tutorials that will teach you that. Then you need to find a tutorial to copy that is based on the manufacturer of the keyboard you have.

This is almost certainly caused by a baud rate miss match between your clone Arduino and your PC.
PC are notorious for having inaccurate baud rates for certain values, and coupled with your clone using that none standard serial chip.

I am assuming you don't have an oscilloscope to test the rate correctly, so I would suggest another alternative way for trying to get hairless to work all the time.

Chose a different hairless baud rate from its drop down menu and then change the baud rate in the code I posted to match. Start off at the faster speeds and get slower. You will probably find a baud rate accurate enough to produce no errors in communication.

This is because at both ends a specified baud rate is only as good as a fixed division ratio can give, so some baud rates are inherently inaccurate.

Thanks Tom.

Ill be sure not to visit that site. Thank you

I just did what Tom asked me to do, To put it in a Window. Is this cool?

Ohk, Could i not use her code and just take out the joystick or shift register, or will it still be the case that it doesnt match?

Ohk ill make sure to do that, Lol i didnt think it was this complicated, again he just apparently plugged his (Not even sure what brand it is). Mine is a Yamaha so i dont think it would be difficult to find stuff for that.

Ahh ohk i see

No but what i will do is just choose different hairless bauds. Am i looking for one that stays the most consistent in terms of the continuous light, and no errors?

Yes you are looking for no errors, the light is irrelevant.

Alright i just did it. I took the code you gave me and uploaded it to the Uno knock off, There are No errors or warnings.

So what would be the the next few steps that i have to take now? I'm guessing that one is getting the code in order and then setting up the bread board properly. And is it cool once i sorted those things out if i could message you and show you if something is wrong?

image

I would get the MIDI routing correct first. That is getting the MIDI from my code into your DAW or tone generator so that you can here the random notes playing. Not having a PC then I can't tell you how to do this. I believe there is a version for Garage Band for the PC that is free you might want to use that as a target if you have nothing else.

I don't know if this is right or wrong it depends on what you get from that keyboard you have. The big problem is that you have no way of knowing what you are getting because you have no test equipment.

Again the code will depend on what you are receiving. Have you asked your friend what type of keyboard he is using and what code goes with his interface?

He has a Casio keyboard. He has 32 keys where mine is 37. Im also pretty sure he will have less pins than me.

If i were to get equipment what would i get?

ohk. I see what your saying

And what do you have?

That should not make a difference to the number of wires. If it does it will only be 1 extra wire.

An oscilloscope, then you need a month or two to learn how to use it.