Skip to content

Example MIDI DIN2USB does not work with Leonardo #22

@steinundfloete

Description

@steinundfloete

I did test example MIDI_DIN2USB from USB-MIDI library v1.12 with Arduino Pro Micro (Leonardo)

Sending control change B0,07,7f from PC to Arduino USB MIDI.
logging of the (modified) sketch printed out the correct bytes were received from Arduino USB,
but they were not forwarded to my MIDI device.

  • Testing with other library works (connecting MIDI DIN to USB MIDI bidirectional w. SysEx, So the hardware seems ok.

For testing, i was just connecting MIDI DIN out -> MIDI DIN in on my Arduino board.
(The way then would be PC -> Arduino USB -> Arduino DIN out -> Arduino DIN in -> Arduino USB -> PC)

I sended again from PC -> USB
3 times nothing was received from serial MIDI.
When sending the same control change to USB the 4th time, it got fancy:
Suddenly data was received from Serial MIDI but not the original data, (see logging below)
It was forwarded to USB and on the PC but it received b0,00,00 like hell
It did not stop to send it again and again, I had to unplug the usb cable to stop it.

All best
Uli Schmidt

here the sketch and logging:

#define VERBOSE

#include <USB-MIDI.h>
USING_NAMESPACE_MIDI;

typedef USBMIDI_NAMESPACE::usbMidiTransport __umt;
typedef MIDI_NAMESPACE::MidiInterface<__umt> __ss;
__umt usbMIDI(0);  // cableNr
__ss MIDICoreUSB((__umt&)usbMIDI);

typedef Message<MIDI_NAMESPACE::DefaultSettings::SysExMaxSize> MidiMessage;

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDICoreSerial);


void setup() {
#ifdef VERBOSE
  Serial.begin(115200);
#endif

  MIDICoreUSB.setHandleMessage(onUsbMessage);
  MIDICoreSerial.setHandleMessage(onSerialMessage);

  MIDICoreUSB.begin(MIDI_CHANNEL_OMNI);
  MIDICoreSerial.begin(MIDI_CHANNEL_OMNI);

  //  MIDICoreUSB.turnThruOff();
  //  MIDICoreSerial.turnThruOff();

}

void loop() {
  MIDICoreUSB.read();
  MIDICoreSerial.read();
}

// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void onUsbMessage(const MidiMessage& message) {
  MIDICoreSerial.send(message);
#ifdef VERBOSE
  printMsg("usb ", message);
#endif
}

void onSerialMessage(const MidiMessage& message) {
  MIDICoreUSB.send(message);

#ifdef VERBOSE
  printMsg("ser ", message);
#endif
}

#ifdef VERBOSE
void printMsg(const char* from, const MidiMessage& message) {
  Serial.print(from);
  Serial.print(message.type, HEX);

  switch (message.type & 0xf0) {
    case 0xf0:  // sysex
      Serial.print(" SysEx size=");
      Serial.println(message.getSysExSize());
      return;
    case 0xc0:  // ProgramChange - 1 byte messages
    case 0xd0:  // AfterTouchChannel
      Serial.print(" ");
      Serial.print(message.data1, HEX);
      break;
    case 0x80:  // NoteOff - 2 byte messages
    case 0x90:  // NoteOn
    case 0xa0:  // AfterTouchPoly
    case 0xb0:  // ControlChange
    case 0xe0:  // PitchBend
      Serial.print(" ");
      Serial.print(message.data1, HEX);
      Serial.print(" ");
      Serial.print(message.data2, HEX);
      break;
    default:
      break;
  }
  Serial.print(" len=");
  Serial.print(message.length);
  Serial.print(" valid=");
  Serial.print(message.valid);
  Serial.print(" channel=");
  Serial.println(message.channel, HEX);

}
#endif

01:18:10.615 -> usb B0 7 7F
01:18:12.436 -> usb B0 7 7F
01:18:14.015 -> usb B0 7 7F
01:18:14.015 -> ser B0 B0 B0
01:18:14.015 -> ser B0 30 30
01:18:14.015 -> ser B0 30 30
01:18:14.015 -> ser B0 30 30
01:18:14.015 -> ser B0 30 30
01:18:14.015 -> ser B0 30 30
01:18:14.015 -> ser B0 30 30
01:18:14.015 -> ser B0 30 30
......................... goes on forever!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions