Simple MIDI Serial Monitor

This blog is full of MIDI projects, but I’ve just realised that I’ve never really done a “MIDI Data Dumper” type project, so building on my Simple MIDI Monitor and using the many MIDI transport options from Arduino Multi MIDI Merge, here is a serial MIDI data dumper.

  • In Part 2 I show how to do the same but with MIDI callback functions and also how to get a serial output from devices where you only have one hardware serial port (like the Uno or Nano).
  • In Part 3 I build a useful debug MIDI monitoring PCB using one of my Arduino MIDI Proto Shields.

SimpleMIDISerialMonitor

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

These are the key Arduino tutorials for the main concepts used in this project:

If you are new to Arduino, see the Getting Started pages.

Parts list

  • Pro Micro or Arduino Leonardo (ATmega32U4 based Arduino)
  • MIDI Interface (e.g. one of the Ready-Made MIDI Modules)
  • Jumper wires

The Circuit

One of the issues with attempting to do a serial port based MIDI data dumper is that if we are using an Arduino Uno or Nano then the serial port can’t be used for data and MIDI at the same time.

Here are several configurations that might work instead.

Arduino MIDI Merge 6

This one uses a Pro Micro which has a native serial link over the built-in USB port in addition to a hardware serial port.  It is also possible to use a Software Serial link.

Arduino MIDI Merge 5

Another option might be to use a USB Host Shield to provide a USB MIDI connection with an Arduino Uno.  Or once again a Software Serial link could be used.

There are many options, but the assumption is that the “first” serial port (i.e. whatever “Serial” on the Arduino is connected to) is used for the dumped MIDI diagnostic information.

The Code

I’m using many libraries and the many configuration options that were used with the Arduino Multi MIDI Merge but not that only a few have been tested!  So refer back to that post for details of where to obtain the various libraries, but for the most basic operation, just the Arduino MIDI Library is required.

All of the following are options for the MIDI interface:

// Uncomment which of these should be used for the MIDI INPUT.
//
// Different boards will support different interfaces, for example:
//   Uno/Nano: SW_SERIAL, SW_SERIAL2, USB_HOST (with additional shield).
//   Leonardo: USB_DEVICE, HW_SERIAL2, SW_SERIAL, SW_SERIAL2, USB_HOST (with additional shield).
//   Mega: HW_SERIAL2, HW_SERIAL3, HW_SERIAL4, SW_SERIAL, SW_SERIAL2, USB_HOST (with additional shield).
//
// Note: In all cases Serial - the first hardware serial port
// is used for the data output to the serial port.
//
#define MIDI_HW_SERIAL2 1
//#define MIDI_HW_SERIAL3 2
//#define MIDI_HW_SERIAL4 3
//#define MIDI_SW_SERIAL 4
//#define MIDI_SW_SERIAL2 5
//#define MIDI_USB_HOST 6
//#define MIDI_USB_DEVICE 7

If Software Serial is chosen then by default it will use D2/D3 (SW_SERIAL) or D10/D11 (SW_SERIAL2).  There are some limitations depending on the board being used – see the comments in the code for details.

The main detection code is pretty universal and independent of the MIDI INPUT device being used. In essence, it just calls the appropriate MIDI.read() function and, assuming it isn’t a MIDI system exclusive message, which are filtered out, it calls a function to decode and print out MIDI messages to the serial port.

I’m just using a relatively simple formatting for messages, but if you take a look at the printMIDIMsg function you should be able to tailor it to whatever you wish.  You can see a sample output at the start of this post.

The only quirk is that I filter out all ActiveSensing messages otherwise they tend to swap the display if present.  If there are other messages you want to avoid, then you can add more to the first switch statement in the print routine, which just returns without printing anything.

Warning: Although I’ve left many options in the code, I’ve only really tested it with a Pro Micro using MIDI_HW_SERIAL2 as the INPUT.  I think the rest should work fine, but it is quite possible there might be errors crept in.  Just drop me a note in the comments (or otherwise) if you find an issue.

Find it on GitHub here.

Closing Thoughts

I’m not quite sure why it took me so long to make one of these – I guess part of the reason is that in most “normal” use I’m using the serial port for MIDI and not dumping out data!

It might be quite a nice thing to build a “MIDI data dumper” into a stand-alone unit, perhaps using the TFT MIDI Display or something similar.

In Part 2 there is a more generic implementation using MIDI callback functions and also some details of options for when you only have a single hardware serial port and you want to be using that for your MIDI link!

Kevin

Leave a comment