MIDI library is not compatible with MIDIUSB library

Hello everyone, hope you are all well

I'm trying to interface hardware midi with PC. I built 5 din receiving circuit and verified that it works with MIDI library Callback example. Then I checked that Native USB is able to send MIDI over USB with MIDIUSB_write example. But when I''m trying to combine the two - it stops working, doesn't even seem to go in the corresponding Handle functions according to serial messages I put (they work fine with examples). Surely I'm not the first one to do that thing, how do I approach it?

MIDI_DIN2USB example spits out nothing. Only noteOn and noteOff from USBMIDI added at the time. Board is DUE

Thanks for the help

#include <MIDI.h>
#include "MIDIUSB.h"

MIDI_CREATE_DEFAULT_INSTANCE();

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

// This function will be automatically called when a NoteOn is received.
// It must be a void-returning function with the correct parameters,
// see documentation here:
// https://github.com/FortySevenEffects/arduino_midi_library/wiki/Using-Callbacks

void handleNoteOn(byte channel, byte pitch, byte velocity)
{
  // Do whatever you want when a note is pressed.
  
  Serial.print("On  ");
  /*Serial.print(channel);
  Serial.print("  ");
  Serial.print(pitch);
  Serial.print("  ");
  Serial.println(velocity);*/
  
 
  noteOnU(channel, pitch, velocity);   // Channel 0, middle C, normal velocity
  MidiUSB.flush();
  // Try to keep your callbacks short (no delays ect)
  // otherwise it would slow down the loop() and have a bad impact
  // on real-time performance.
}

void handleNoteOff(byte channel, byte pitch, byte velocity)
{
  Serial.print("Off  ");
  Serial.print(channel);
  Serial.print("  ");
  Serial.print(pitch);
  Serial.print("  ");
  Serial.println(velocity);
  noteOffU(channel, pitch, velocity);  // Channel 0, middle C, normal velocity
  MidiUSB.flush();
  // Do something when the note is released.
  // Note that NoteOn messages with 0 velocity are interpreted as NoteOffs.
}
void handleControlChange (byte number, byte value, byte channel){
  Serial.print("CC  ");
  Serial.print(number);
  Serial.print("  ");
  Serial.print(value);
  Serial.print("  ");
  Serial.println(channel);
}

// -----------------------------------------------------------------------------
void handlePitchBend(byte channel, int pitch){
  
  Serial.print("Pitch  ");
  Serial.print(channel);
  Serial.print("  ");
  Serial.println(pitch);
}

void noteOnU(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOnU = {0x09, 0x90 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOnU);
}

void noteOffU(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOffU = {0x08, 0x80 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOffU);
}
void setup()
{
  // Connect the handleNoteOn function to the library,
  // so it is called upon reception of a NoteOn.
  Serial.begin(115200);
  Serial.println("go");
  MIDI.setHandleNoteOn(handleNoteOn);  // Put only the name of the function

  // Do the same for NoteOffs
  MIDI.setHandleNoteOff(handleNoteOff);
  MIDI.setHandlePitchBend(handlePitchBend);
  MIDI.setHandleControlChange(handleControlChange);

  // Initiate MIDI communications, listen to all channels
  MIDI.begin(MIDI_CHANNEL_OMNI);
  Serial.println("gogo");
}

void loop()
{
  // Call MIDI.read the fastest you can for real-time performance.
  
  Serial.println("handling");
  MIDI.read();

  // There is no need to check if there are messages incoming
  // if they are bound to a Callback function.
  // The attached method will be called automatically
  // when the corresponding message has been received.
}

Hello mirasderbissalin

If you use hardware serial communication on arduino (so you can upload code to arduino via ide)..theres no Midi USB comunication available on arduino.
You will need a firmware like hiduino for MIDI usb comunication.
For people which prefers hiduino (they want a usb midi device) would be a problem uploading sketches to arduino (think you will need to quit hiduino firmware and then you must to come back to arduino firmware)

I must confess for me this was not a problem but i recomend this video for the whole process and then you can upload sketches to arduino easily and you will got a usb MIDI device too.

Another suggestion its to use Control Surface library. Its newer.

If you dont like hiduino theres another solutions for usb midi comunication like loopbe,hairless etc

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