MIDI Library Callbacks not working

I have the following piece of code, but the 2 callback functions are never actually called.
I'm using hairless midi-serial bridge, loopmidi, and ableton live.

#include <MIDI.h>
#include <LiquidCrystal.h>
const int rs = 53, en = 51, d4 = 49, d5 = 47, d6 = 45, d7 = 43;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

MIDI_CREATE_DEFAULT_INSTANCE();

void handleNoteOn(byte channel, byte pitch, byte velocity)
{
  lcd.print(pitch);
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
  lcd.print(pitch);
}

void setup()
{
  Serial.begin(115200);
  lcd.begin(16, 2);
  MIDI.setHandleNoteOn(handleNoteOn);  // Put only the name of the function
  MIDI.setHandleNoteOff(handleNoteOff);
  MIDI.begin(MIDI_CHANNEL_OMNI);
}

void loop()
{
  MIDI.read();
}

MIDI.begin overrides the baud rate set by Serial.begin. The proper way to set the baud rate is:

MIDI library baud rate setting:

---



```
#include <MIDI.h>

struct MySettings : public midi::DefaultSettings {
  static const long BaudRate = 115200;
};

MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, MySettings)

void setupcolor=#000000[/color] {
  MIDI.begincolor=#000000[/color];
}

void loopcolor=#000000[/color] {
  // put your main code here, to run repeatedly:
}
```

|

It still doesn't seem to work.

#include <MIDI.h>

struct MySettings : public midi::DefaultSettings {
  static const long BaudRate = 115200;
};

MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, MySettings)

void setup() {
  MIDI.begin();
  MIDI.setHandleNoteOn(handleNoteOn); 
  MIDI.setHandleNoteOff(handleNoteOff);
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
}

void handleNoteOn(byte channel, byte pitch, byte velocity)
{
  digitalWrite(13, HIGH);
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
  digitalWrite(13, LOW);
}

The RX led blinks on the Arduino when midi is sent to it.

I tried the following:
Looking if the midi-serial bridge actually works: Yup
Ruling out the LCD by turning pin13 on or off when the 2 callback functions are called, nothing happens.
Setting the midi library to listen on all channels(MIDI.begin(MIDI_CHANNEL_OMNI); )
Using another program instead of Ableton Live, still didn't work.

The loop function probably needs something like this.

void loop() {
    MIDI.read();
}

For a working example see the following.

Neither the example or the code I posted previously with the added "MIDI.read();" work.

#include <MIDI.h>

struct MySettings : public midi::DefaultSettings {
  static const long BaudRate = 115200;
};

MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial, MIDI, MySettings)

void setup() {
  MIDI.begin(MIDI_CHANNEL_OMNI);
  MIDI.setHandleNoteOn(handleNoteOn); 
  MIDI.setHandleNoteOff(handleNoteOff);
  pinMode(13, OUTPUT);
}

void loop() {
  MIDI.read();
}

void handleNoteOn(byte channel, byte pitch, byte velocity)
{
  digitalWrite(13, HIGH);
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
  digitalWrite(13, LOW);
}

Found the error:

Basically, the midi library refuses to call the callback function until ~10 notes are sent to it. Don't ask me why. I just connected a midi controller to it, and started pushing buttons randomly and a few seconds later it started working. So I loaded up the code from my last post, and sure enough, after sending a few midi notes to the arduino it starts working.

03vmate:
Found the error:

Basically, the midi library refuses to call the callback function until ~10 notes are sent to it. Don't ask me why. I just connected a midi controller to it, and started pushing buttons randomly and a few seconds later it started working. So I loaded up the code from my last post, and sure enough, after sending a few midi notes to the arduino it starts working.

That can't be right. Last time I used it, it registered notes from the moment I started sending.

I do not think the library is at fault either.