Arduino Midi Piano issues

Hey all,

I've been working on a 61 key midi keyboard and I've run into an issue, whenever I press a key on the keyboard which is hooked up to my Arduino Uno using the 64 Button Shield, The software that I'm using (Hairless MIDI<->Serial Bridge) gives me an error saying:

Error: got an unexpected data byte 0x72.
Error: got an unexpected data byte 0x75.
Error: got an unexpected data byte 0x74.
Error: got an unexpected data byte 0x74.
Error: got an unexpected data byte 0x6f.
Error: got an unexpected data byte 0x6e.
Error: got an unexpected data byte 0x3a.
Error: got an unexpected data byte 0x20.
Error: got an unexpected data byte 0x31.
Error: got an unexpected data byte 0x34.
Error: got an unexpected data byte 0x34.
Error: got an unexpected data byte 0x37.
Error: got an unexpected data byte 0x32.
Error: got an unexpected data byte 0x31.
Error: got an unexpected data byte 0x32.
Error: got an unexpected data byte 0x37.
Error: got an unexpected data byte 0x42.
Error: got an unexpected data byte 0x75.
Error: got an unexpected data byte 0x74.
Error: got an unexpected data byte 0x74.
Error: got an unexpected data byte 0x6f.
Error: got an unexpected data byte 0x6e.
Error: got an unexpected data byte 0x3a.
Error: got an unexpected data byte 0x20.
Error: got an unexpected data byte 0x31.
Error: got an unexpected data byte 0x32.
Error: got an unexpected data byte 0x38.
Error: got an unexpected data byte 0x37.
Error: got an unexpected data byte 0x32.
Error: got an unexpected data byte 0x31.
Error: got an unexpected data byte 0x32.
Error: got an unexpected data byte 0x37.

Here's the code for the Arduino:

volatile uint8_t   Button    = 0;                      // Required for 64 Button Shield (SPI Only)


void setup()
{
  
  Serial.begin(38400);                              
  
  delay(1000);
  attachInterrupt(0, SPI64B, FALLING);                 // Required for 64 Button Shield (SPI Only)

}



void loop()
{
  
  if(Button > 0)                              // If Button is > 0, then it was pressed or released (SPI only)
  {
    Serial.print("Button: ");
    if(Button > 128)                          
    {
     Button = Button - 128;
     MIDI_TX(144,Button+28,127);              // NOTE ON
    }else
    {
     MIDI_TX(128,Button+28,127);              // NOTE OFF
    }
    Button = 0;
  }
  
}



void SPI64B()
{
  Button = 0;
  
  volatile uint8_t  val  = 0;
  volatile uint8_t  clk  = 0;
  
  #define  DataInPin   3
  #define  ClkPin      4

  clk = digitalRead(ClkPin);
  while(clk == LOW)
  {
    clk = digitalRead(ClkPin);
  }

  for(volatile int i =0; i<8;i++)
  {   
    val = digitalRead(DataInPin);
    clk = digitalRead(ClkPin); 
    
    while(clk == HIGH)
    {
      clk = digitalRead(ClkPin);
    }

    if(val == HIGH)
    {
      Button = Button +1;
    }
    
    if(i != 7)
    {
      Button = Button << 1;
    }
    else
    {
      break;
    }

    clk = digitalRead(ClkPin);
    
    while(clk == LOW)
    {
      clk = digitalRead(ClkPin);
    }

  }
}    


void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) 
{
  Serial.print(MESSAGE);
  Serial.print(PITCH);
  Serial.print(VELOCITY);
}

Does anyone have any ideas why this doesn't work? Any thoughts would be highly appreciated!

void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) 
{
  Serial.print(MESSAGE);
  Serial.print(PITCH);
  Serial.print(VELOCITY);
}

That's wrong because it is converting them into printable strings. For example when testing I got:

14460127128

They are one-byte messages, so change it to:

void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY) 
{
  Serial.write(MESSAGE);
  Serial.write(PITCH);
  Serial.write(VELOCITY);
}

Also:

    Serial.print("Button: ");

It will give an error when it sees that. Leave the debugging out.

Thankyouthankyouthankyou! I’ll try it now!

Woo! It works, ish. Using Synthesia or Midiplayer, the keys aren't in order. Middle C is G2# and so on. Any ideas why that is?

Sounds like 28 isn’t the right thing to add.

Ugh, missed another obvious error. I need an excuse to ask this question: What should I be adding? I blame my hangover.

I don't know what numbers you are getting back from your button shield, but you have to make them line up.

http://www.midimountain.com/midi/midi_note_numbers.html

Every key seems to be 6 keys ahead of itself. I'll see if I can figure this out when my hangover goes away.

Change:

     MIDI_TX(144,Button+28,127);              // NOTE ON

to:

     MIDI_TX(144,Button+22,127);              // NOTE ON

Or if that makes it worse, go the other way.

Sadly, that didn't make much of a difference. Each key is now 7 keys away.

need a good midi and drum coding which i can use to create drum and control the hit of the piezo