Problems Sending MIDI commands using MIDIUSB and Arduino Due

I am using an Arduino DUE with the aim of utilizing the Native USB capacity of the board for MIDI communication over USB. I can receive MIDI events via USB from external programs like MIDI-OX and Cubase without problems but when I send MIDI commands OUT from my sketch only the first command is initially sent and displayed within e.g. MIDI-OX and then nothing seems to be sent to MIDI-OX until I close the Serial Monitor and reopen it again. Once the Serial Monitor is reopened, the commands that were not displayed are quickly displayed before it stops at the first new MIDI command of the new Sketch - this can be repeated again and again.

Since I am repeating the sending of MIDI commands within the loop() I can see that my sketch is running fine via the print statements to the Serial Monitor, but as stated earlier. only the first message is displayed in MIDI-OX until I close and open the Serial Monitor again.

Here’s the simple example code I’m using:

/*
 * MIDIUSB_test.ino
 *
 * Created: 4/6/2015 10:47:08 AM
 * Author: gurbrinder grewal
 * Modified by Arduino LLC (2015)
 */ 

#include "MIDIUSB.h"

// First parameter is the event type (0x09 = note on, 0x08 = note off).
// Second parameter is note-on/note-off, combined with the channel.
// Channel can be anything between 0-15. Typically reported to the user as 1-16.
// Third parameter is the note number (48 = middle C).
// Fourth parameter is the velocity (64 = normal, 127 = fastest).

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

void noteOff(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOff);
}

// First parameter is the event type (0x0B = control change).
// Second parameter is the event type, combined with the channel.
// Third parameter is the control number number (0-119).
// Fourth parameter is the control value (0-127).

void controlChange(byte channel, byte control, byte value) {
  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
  MidiUSB.sendMIDI(event);
}


void setup() {
  Serial.begin(115200);
  while (!Serial);
}

void loop() {
  Serial.println(F("Sending note on"));
  Serial.flush();
  noteOn(1, 48, 64);   // channel, pitch, velocity
  MidiUSB.flush();
  delay(200);
  Serial.println(F("Sending note off"));
  Serial.flush();
  noteOff(1, 48, 64);  // channel, pitch, velocity
  MidiUSB.flush();
  delay(200);
  Serial.println(F("Sending control Change"));
  Serial.flush();
  controlChange(1, 10, 65); // channel, control, value
  MidiUSB.flush();
  delay(200);
}

I have applied extensive flush() commands, without any difference or improvements. I have included a screenshot of MIDI-OX where the red arrow indicates the fist MIDI command that is displayed when the sketch is running and even though the sketch is running and printing statements to the Serial Monitor those commands are not “pushed” to the MIDI-OX program unless I close the Serial Monitor and open it again - the group marked by the red X.

I am using version 1.0.3 of the MIDIUSB Library. The Arduino IDE is 1.8.7 and I’m running Windows 10. I am using a genuine Arduino DUE board.

Any tips, tricks or hints are most welcome!

Regards,
Mats

MIDI-OX1.JPG

Anyone? Anyone have a Arduino Due, a Midi monitor and can try the code to see if it works or not?

Thanks in advance :)

It would be greatly appreciated if anyone could try the example code I provided and see if there’s a bug or something when sending midi commands over native USB on the Arduino Due.

Thanks!

I'm still trying to find my midi software.

In the meantime, once you've loaded the program on to the DUE, try closing down the IDE and connecting to the DUE with an alternate terminal app (such as Termite or similar and see if the problems persist. Reset the DUE once you connect via termite.

Appreciate it and thanks for the tip of not running the IDE, I will test it as soon as I get a chance.

Cheers!

I removed all the Serial.Print statements, compiled and uploaded the example sketch, closed the IDE and connected the DUE only via the the Native USB port and still the same behavior. One Midi message is sent then nothing until I disconnect the Due (USB port) from the computer, upon which the MIDI commands are immediately displayed in MIDI-OX. Could it be the messages are not "individually terminated" and buffered or something?

Well the code as shown works on the Leonardo and the Zero, but I can't get it working on the Due.

However I have never used the Native port on the Due and I notice I don't get any LEDs lit up when I connect to it, so maybe that port dosn't work on my Due.

Grumpy_Mike:
Well the code as shown works on the Leonardo and the Zero, but I can’t get it working on the Due.

However I have never used the Native port on the Due and I notice I don’t get any LEDs lit up when I connect to it, so maybe that port dosn’t work on my Due.

I noticed the same on my Due, the RX/TX leds for the Native USB do not blink, but data is being sent, just not correctly when it relates to MIDI. May I ask if you got anything on the receiving end and do you get the remaining MIDI commands “flushed” within your MIDI monitor once you disconnect the Native USB port from the Due?

I have the "MIDI monitor app" on the other end, running on a Mac. I didn't even get as far as you with the Due. I could not get the MIDI monitor to even see the MIDI device, which I could do with Zero.

I will try it later using external power.

Hi
Sorry about the delay in getting back to you.
I found an ant infestation int my Dads' DVD and BluRay library.
I had to check and clean approximately 200 DVDs and BluRays.
About 50 of them had ants and ant eggs inside. Messy and time consuming.

I've managed to find my Midi stuff.

Instead of using MidiOx (which I can't locate at the moment) I'm using Reaper. It worked first time. I added a vst instrument (cockos Reasynth) and am listening to a really repetitive one note pulse.

What I did find was that I had to have the sketch running before starting up Reaper.
Initially, I went into Preferences (Options->Preferences) and From the MIDI devices list, double clicked on Arduino DUE and selected Enable Input and Enable control messages

Once that was done, I added a new VSTi instrument and set the input for that instrument as Input MIDI->Arduino Due->All Channels.

Resetting the DUE means that I have to re-start Reaper to recognise the midi device (although I no longer need to add the Arduino to Preferences)

I also added a new track and mapped its input to the Due. I was then able to record the output from the Due with no issues.
My terminal window is open, and I'm running Windows 7

Later today, I'll try Midi OX and see what happens, But I think what you may need to do is start Midi OX After the sketch is loaded and running. (just a theory, no proof acquired yet :wink: )

Is there any particular reason you need to use MidiOx? most hosts should be able to see the Arduino as a Midi device. Or are you primarily using it as diagnostics at the moment?

OK on your ant's nest. Makes my small spider that seems to be living between the display and the display cover on my DAB radio I found last night small stuff.

I think what you may need to do is start Midi OX After the sketch is loaded and running.

Well I am not using MIDI OX because I am on a Mac. I am using MIDI Monitor, and yes I did try quitting and restarting it with the Due plugged in and running. Yes I am using this for testing because it will tell me what messages are being sent.

am listening to a really repetitive one note pulse.

Add a bit of variety with the random number function:-

void loop() {
  int val;
  val = random(20,100);
    noteSend(0x90, val, 127);
    delay(200);
    noteSend(0x80, val, 127);
   delay(800);
    } // end loop function

Yu will have to change the note send functions to match the libiary you are using but you get the idea.

@mlordin:

I've downloaded and installed MidiOx and that worked straight off.
As with Reaper, If I reset or re-download the sketch to the DUE, I have to re-start MidiOX before it sees the device again.
But data is being sent while the serial monitor is up just fine.


I can only offer three suggestions.

  1. Update your systems' USB drivers
  2. Try installing a curent DAW of some description (Reaper, Cakewalk..). They often have updated midi drivers which overwrite the windows ones. That could be a contributing factor
  3. Look at running MidiOX in compatibility mode (i dunno, it could be an issue)

Grumpy_Mike:
OK on your ant's nest. Makes my small spider that seems to be living between the display and the display cover on my DAB radio I found last night small stuff.
Well I am not using MIDI OX because I am on a Mac. I am using MIDI Monitor, and yes I did try quitting and restarting it with the Due plugged in and running. Yes I am using this for testing because it will tell me what messages are being sent.
Add a bit of variety with the random number function:-

@Grumpy_Mike: Are you confusing me with the OP by any chance?

My reason for asking about MidiOx is because it has not been updated since around 2010 or so. I think the last update was done when Vista was still a thing, and Windows 7 had just been released.
From what I can remember, windows 8 users had to run the utility in compatibility mode. I've not played with Midi for a little while now, (I used to use MidiOX MidiYoke to route Midi between apps, many, many years ago) so I don't know if there are any issues between MidiOx and Windows 10.

As to both of your comments re LEDs, My DUE TX LED for the programming port blinks on sending to the termninal, but the other TX LED does not (even though data is being sent to Reaper just fine).

@Grumpy_Mike: Are you confusing me with the OP by any chance?

Yes sorry.

Just tried the original code on my Due using the native port and an external power supply in the jack. I have got it to work correctly on my Mac.

Grumpy_Mike: Just tried the original code on my Due using the native port and an external power supply in the jack. I have got it to work correctly on my Mac.

Thank you all for all the useful information - I will try the "tips and tricks" provided in the posts above shortly and keep you posted.

Cheers!

Hi - finally progress!

But first what didn't work... running Midi-OX in various compatibility modes didn't improve anything unfortunately. However, since I have Cubase 9.5 I created a MIDI track and noticed that the MIDI event indicator reacted when I pressed the buttons on my Arduino Due. I inserted a MIDI monitor plug-in on the MIDI track and to my surprise I noticed that the correct midi events were actually received for the track within Cubase.

Great news and want to thank all those of you who spent time supporting me with testing, tips and ideas etc - much appreciated!

Cheers!