Receiving a MIDI message

I have the following MIDI breakout board




I am finding it hard to even verify if it is working with my Arduinos, I'd prefer to test on a MEGA 2560, but just because the following code was for an UNO, I fully mounted it on the UNO:

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

// -----------------------------------------------------------------------------

// This example shows the old way of checking for input messages.
// It's simpler to use the callbacks now, check out the dedicated example.

#define LED 13                   // LED pin on Arduino Uno

// -----------------------------------------------------------------------------

void BlinkLed(byte num)         // Basic blink function
{
    for (byte i=0;i<num;i++)
    {
        digitalWrite(LED,HIGH);
        delay(50);
        digitalWrite(LED,LOW);
        delay(50);
    }
}

// -----------------------------------------------------------------------------

void setup()
{
    pinMode(LED, OUTPUT);
    MIDI.begin();           // Launch MIDI, by default listening to channel 1.
}

void loop()
{
    if (MIDI.read())                // Is there a MIDI message incoming ?
    {
        switch(MIDI.getType())      // Get the type of the message we caught
        {
            case midi::ProgramChange:       // If it is a Program Change,
                BlinkLed(MIDI.getData1());  // blink the LED a number of times
                                            // correponding to the program number
                                            // (0 to 127, it can last a while..)
                break;
            // See the online reference for other message types
            default:
                break;
        }
    }
}

That is simply the MIDI.h Basic "Input" program.

I do not see the bulit in LED respond to MIDI when I upload this program and connect my Keyboard which is definitely sending MIDI on MIDI port 1, to the IN port of the breakout board. As I said, Fully Mounted as a shield, as well as mounted with the correct wires in the correct sockets, and I have tried with a MEGA 2560 and UNO, and still no response. TX from shield to RX on Arduinos and RX from shield to TX on Arduinos, 5v to 5v and GND to GND.

Is there something I could be missing?

The TX light on the Arduinos actually flashes when I create any MIDI event with my keyboard. If I reverse the TX and RX wires then nothing happens.

What kind of messages is it sending? Are you sure they're Program Change messages?

The messages I was sending when testing as I described were note messages.

Are they supposed to be Program change messages? Ah, I see it now!

How can I change the input messages expected to Note messages?

It's a strange setup to test Input, but I now understand.

I would really like to change the method of testing to Note Input, instead of Program Change.

I was not sending Program Change messages, but when I tried sending Program Change messages, it now works fine.

Thanks for the help.

A message for the author or person who selects which programs get to ship with Arduino programs, Program Select is a strange idea, as the user has a full set of keys in front of them, and can easily press any key! A MIDI Key ON/OFF would be much easier to use in a Basic example. The keys in a MIDI setup equate to 0 - 127.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.