SparkFun MIDI Shield Error - Incomplete MIDI message?

I've got a SparkFun MIDI Shield attached to my Arduino Uno. I'm getting no MIDI sounds out of the shield and am using the Hairless MIDI Serial program to try to debug the problem.

The error is:

Warning: got a status byte when we were expecting 1 more data bytes, sending possibly incomplete MIDI message 0xc0

FWIW, I'm connecting to the PC using a MIDI to USB adapter.

Here is my code. Any help would be tremendously appreciated!

/*
MIDI On/Off Messages
By Amanda Ghassaei
July 2012
http://www.instructables.com/id/Send-and-Receive-MIDI-with-Arduino/

  • This program is free software; you can redistribute it and/or modify
  • it under the terms of the GNU General Public License as published by
  • the Free Software Foundation; either version 3 of the License, or
  • (at your option) any later version.

*/

int velocity = 100;//velocity of MIDI notes, must be between 0 and 127
//higher velocity usually makes MIDI instruments louder

int noteON = 144;//144 = 10010000 in binary, note on command
int noteOFF = 128;//128 = 10000000 in binary, note off command

void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
}

void loop() {
for (int note=68;note<83;note++) {
MIDImessage(noteON, note, velocity);//turn note on
delay(300);//hold note for 300ms
MIDImessage(noteOFF, note, velocity);//turn note off
delay(200);//wait 200ms until triggering next note
}
}

//send MIDI message
void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
Serial.write(command);//send note on or note off command
Serial.write(MIDInote);//send pitch data
Serial.write(MIDIvelocity);//send velocity data
}

I replaced the SparkFun MIDI Shield with a new one today and I'm still getting the same error. I'm totally stumped here.

I've got a SparkFun MIDI Shield attached to my Arduino Uno.

Link please.

I'm getting no MIDI sounds out of the shield

You would not expect to get sound out of a MIDI shield.

am using the Hairless MIDI Serial program to try to debug the problem.

But hairless uses a much faster baud rate than the standard MIDI baud rate that code is using.

Now please read this How to use this forum
It will tell you how to ask a question and how to post code correctly.

Please explain your setup in detail, I suspect you are not understanding what MIDI actually does.

EDIT :- My god i just read the dreaded word instructables in that code. Please note instructables are normally crap, never use them unless you can spot the errors made by the authors. Never use them to try and learn stuff.

Grumpy_Mike,

Thank you very much for taking the time to look at my post and offer suggestions. Sorry for the bad code formatting.

Here's a link to the Sparkfun MIDI Shield I'm referring to: SparkFun MIDI Shield - DEV-12898 - SparkFun Electronics

Yes, I understand that the MIDI Shield does not create sound - it's supposed to send MIDI data which are rendered into sound via some sort of synthesizer or program. Sorry for playing loose with the terminology.

So far, I've tried two different Sparkfun MIDI Shields and another USB MIDI Shield and all three result in the same error:

Warning: got a status byte when we were expecting 1 more data bytes, sending possibly incomplete MIDI message 0xc0

Honestly, I don't need to use the code that I posted previously, I just need a working example of code which will produce valid MIDI data without any input. Just one constant note would be fine at this point.

Maybe the problem is due to a faulty Arduino? Yes, it's a Genuino.

Here the full code that I'm using:

#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>

/*
MIDI On/Off Messages
By Amanda Ghassaei
July 2012
http://www.instructables.com/id/Send-and-Receive-MIDI-with-Arduino/

 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.

*/
 MIDI_CREATE_DEFAULT_INSTANCE();
 
 int velocity = 100;//velocity of MIDI notes, must be between 0 and 127
 //higher velocity usually makes MIDI instruments louder
 
 int noteON = 144;//144 = 10010000 in binary, note on command
 int noteOFF = 128;//128 = 10000000 in binary, note off command

void setup() { 
  //  Set MIDI baud rate:
  Serial.begin(31250);
  MIDI.begin();
}

void loop() {
  for (int note=68;note<83;note++) {  
    MIDImessage(noteON, note, velocity);//turn note on
    delay(300);//hold note for 300ms
    MIDImessage(noteOFF, note, velocity);//turn note off
    delay(200);//wait 200ms until triggering next note
  }
}

//send MIDI message
void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
  Serial.write(command);//send note on or note off command 
  Serial.write(MIDInote);//send pitch data
  Serial.write(MIDIvelocity);//send velocity data
}

Thanks for the link, now I know what you are dealing with.

Maybe the problem is due to a faulty Arduino?

Very very unlikely.

There looks nothing wrong with that code. However try this code which I have used on many occasions myself, it just fires off random notes.

/* Midi note fire - Mike Cook March 2012
 *
 * ----------------- 
 * send MIDI serial data, automatically for a test
 * 
###############################################################################################

HARDWARE NOTE:
The MIDI Socket is connected to arduino TX through a PNP transistor to invert the MIDI signal.
A common anode RGB LED is pulled down through pins 9, 10, 11

################################################################################################
*/
// Arduino pin assignments
#define midiChannel (byte)0

// Start of code
void setup() {
 //  Setup serial
   Serial.begin(9600);    // Debug speed
   programChange(0xc0, 14);  // Change MIDI voice

}

//********************* MAIN LOOP ***********************************

void loop() {
  int val;
  val = random(20,100);
    noteSend(0x90, val, 127);
    delay(200);
    noteSend(0x80, val, 127);
   delay(800);
    } // end loop function
    
//********************* Functions *********************************** 


//  plays a MIDI note
 void noteSend(char cmd, char data1, char data2) {
  cmd = cmd | char(midiChannel);  // merge channel number
  Serial.write(cmd);
  Serial.write(data1);
  Serial.write(data2);
}
//  change the voice
 void programChange(char cmd, char data1) {
  cmd = cmd | char(midiChannel);  // merge channel number
  Serial.write(cmd);
  Serial.write(data1);
}

//  change the bank
void bankChange(char cmd, char data1) {
  Serial.write(0xB0 | char(midiChannel));  // control change
  Serial.write(cmd);
  Serial.write(data1);
}

What I suspect is wrong is the setup on your computer system.
You say:-

and all three result in the same error:

Warning: got a status byte when we were expecting 1 more data bytes, sending possibly incomplete MIDI message 0xc0

Now what produces this message? It is not the Arduino so it must be something else.

You need to describe your setup past the Arduino much better than you have done because it is my guess that is where the problem is.

Thanks again, Grumpy_Mike. I've uploaded your code to the Arduino and have adjusted the HairlessMIDI Baud Rate to 57600. I now get the following errors/notices:

Serial In: Ch 1: Pitch bend %2

Warning: got a status byte when we were expecting 1 more data bytes, sending possibly incomplete MIDI message 0xe0

I've attached a screenshot.

Grumpy_Mike:
What I suspect is wrong is the setup on your computer system.
You say:-Now what produces this message? It is not the Arduino so it must be something else.

The Sparkfun MIDI Shield has MIDI output ports which I'm connecting to my PC via a MIDI to USB 2.0 cable. The output is being read by Hairless MIDI.

Grumpy_Mike:
You need to describe your setup past the Arduino much better than you have done because it is my guess that is where the problem is.

Is there any other information that I'm not providing? I'm also using Windows 7 and Arduino v1.6.6.

the output is being read by Hairless MIDI.

Hairless is a serial / MIDI bridge it is not designed to do what you are doing with it. This is why you can not get anything to work. You do not / can not use Hairless with a MIDI shield.

If you want to monitor the MIDI being sent then you need a MIDI monitor, often going by that name. It will depend on what your computer is as to what works.

Alternatively just feed the USB MIDI HID signal into your program that accepts MIDI.


If you want to use Hairless then disconnect your MIDI shield and connect the Arduino directly to your computer with the USB lead. Then change the baud rate in your Arduino code from 31250 baud to 115200 baud.

Grumpy_Mike:
Hairless is a serial / MIDI bridge it is not designed to do what you are doing with it. This is why you can not get anything to work. You do not / can not use Hairless with a MIDI shield.
If you want to monitor the MIDI being sent then you need a MIDI monitor, often going by that name. It will depend on what your computer is as to what works.

Thank you very much for saving me hours of wrestling with Hairless MIDI and trying to make it work!

I've now downloaded MIDI-OX but it does not appear to be detecting any activity coming from the MIDI Shield. I've attached a screenshot.

Grumpy_Mike:
Alternatively just feed the USB MIDI HID signal into your program that accepts MIDI.

That's where the problem started - it's not detecting any MIDI data coming in - even though it does detect the adapter.

I'm stumped. Any idea where I should look for the problem?

Well it looks like you have a PC and I use Macs so I don't know what MIDI-OX should do or how you set it up. I would look for a PC version of a MIDI monitor to see if it can pick up any signals. However we have ruled out any problems with your Arduino or your MIDI shield and as I said it is down to your MIDI setup.

Okay, well thanks for helping me as much as you could, Grumpy_Mike. I very much appreciate your time and knowledge.

I'm going to try replacing the MIDI to USB cable and hope for the best. I can't imagine why programs on my PC cannot detect the MIDI data which is supposedly being sent.

It is a PC, there are lots of thing that can go wrong with the setup.

For what it's worth, my project now works with a MIDI card that outputs data via a USB cable, rather than MIDI ports. The code just doesn't output data using the Sparkfun MIDI shield. I have no idea as to why not.
I'll have to contact Sparkfun directly to see if they offer support for when when their products don't work.