Simple MIDI Serial Monitor – Part 3

This is a follow-up to the following posts:

This post takes one of my Arduino MIDI Proto Shields and adds some jumpers to switch between hardware serial and two configurations of software serial for use with the above.

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

The Circuit

The MIDI IN and OUT circuits can be connected to one of the following sets of IO pins using the jumpers:

  • Hardware UART: RX pin 0, TX pin 1
  • Software Serial: RX pin 2, TX pin 3
  • Software Serial: RX pin 10, TX pin 11

There are optional additional links that can be made to wire in the two TRS sockets to allow the shield to support either MIDI DIN or TRS connections. These links are probably best made on the underside of the PCB.

Build Notes

If TRS sockets are required to be added, then the proto shield PCB will need trimming down in size as shown here: Arduino Stackable TRS MIDI Interface.

Build the proto PCB as described here: Arduino MIDI Proto Shield – Part 2 but do not solder the MIDI DIN sockets or Arduino headers.

At this point the jumper pin headers and TRS sockets can be added. The RX links are shown in green and the TX links in white. Note how the bottom of each set of three pin headers are joined on the underside of the pcb.

Note that the TRS sockets (if used) cannot be linked to the DIN sockets until the DIN sockets have been soldered on. Also recall that only the MIDI OUT socket is connected to GND.

The Arduino headers are the last things to be soldered.

The Code

This can use the code from Simple MIDI Serial Monitor (not part 2). In fact as part of this build, I’ve updated it slightly for extra debug messages and to support SysEx messages.

For more general use in other projects, the following is the key code required to have this work. If SWTEST is defined then MIDI will be configured on one of the SoftwareSerial links. If SWTEST is commented out, then MIDI will use the hardware serial port as usual.

#include <MIDI.h>

// Comment out to remove test code and put MIDI on default Serial port
#define SWTEST

#ifdef SWTEST
// MIDI on the SoftwareSerial port
#include <SoftwareSerial.h>
#define SS_RX  2  // or 10
#define SS_TX  3  // or 11
using Transport = MIDI_NAMESPACE::SerialMIDI<SoftwareSerial>;
SoftwareSerial sSerial = SoftwareSerial(SS_RX, SS_TX);
Transport serialMIDI(sSerial);
MIDI_NAMESPACE::MidiInterface<Transport> MIDI((Transport&)serialMIDI);
#else
// MIDI on the default (hardware) serial port
MIDI_CREATE_DEFAULT_INSTANCE();
#endif

#define MIDI_CHANNEL 1

void setup() {
#ifdef SWTEST
  Serial.begin(9600);
#endif
  MIDI.begin(MIDI_CHANNEL);
}

void loop() {
  if (MIDI.read()) {
#ifdef SWTEST
    Serial.print("MIDI debug message");
#endif
    // Unconditional MIDI handling
  }
}

Find it on GitHub here.

Closing Thoughts

This is another of those “why haven’t I done this before” builds! This should be really useful moving forward.

There is nothing particularly special about this build – it could easily be reproduced on stripboard or an Arduino proto shield, but I’ve chosen to use one of my Arduino MIDI Proto Shields for a neater result.

Kevin

Leave a comment