Go Down

Topic: Hairless MIDI: Arduino starts working only after several received commands (Read 422 times) previous topic - next topic

ltschu

Hi, I want to receive MIDI data from Hairless MIDI with my Arduino. After enabling the "Serial<->MIDI Bridge On" in Hairless, when I send a MIDI program change, the Arduino receives data (RX flashing), but somehow, the Arduino seems to start interpreting the received data only after it has received 60 program change commands. Here's my code:
Code: [Select]

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

#define LED 13                   

void setup()
{
    pinMode(LED, OUTPUT); 
    MIDI.begin();           
    Serial.begin(115200); 
}

void loop()
{
    if (MIDI.read())               
    {
        digitalWrite(LED,HIGH);
        delay(50);
        digitalWrite(LED,LOW);
    }
}

The LED flashes the first time with the 61. program change command received. When I disable and activate "Serial<->MIDI Bridge On" in Hairless again, it takes again 60 program change commands after the code works properly.
If I send control changes instead of program changes, the LED does not flash with the first 40 commands and then starts to work as expected.

What do I need to change to get it working from the first MIDI command received?

I also find it strange that the Arduino starts to mirror the received MIDI commands after having received 60 program changes or 40 control changes. Is that normal behavior?

Thanks for your help.


Grumpy_Mike

Try actually reading the data from the MIDI rather than let it fester in the buffer.

Quote
Is that normal behavior?
I have never seen it do this and I have used it many times.

ltschu

Thank you Grumpy_Mike. I've modified the code to do something with the incoming data. Is this what you ment with "Try actually reading the data from the MIDI"?
Code: [Select]
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
#define LED 13   
           
void setup() {
    pinMode(LED, OUTPUT); 
    MIDI.begin(MIDI_CHANNEL_OMNI);           
    Serial.begin(115200); 
}

void loop() {
    if (MIDI.read()){
        switch(MIDI.getType()){
            case midi::ProgramChange:
                MIDI.sendControlChange(1,1,1);
                break;
            default:
                MIDI.sendControlChange(1,2,1);
                break;
        }
    }
}

The result is still the same: Arduino doesn't send any response to the first 60 incoming program change commands. From the 61. incoming command, it sends first an exact copy of the received program change (I don't know why) and the CC(1,1,1) as expected from the code.

ltschu

It's acutally the 59. command which is first one processed by the arduino. Screenshot from the Hairless Status Window attached.

Go Up