Arduino I2C MIDI Interface – Part 3

This project builds on part 2 and takes the generic I2C MIDI interface and turns an Arduino into an I2C MIDI to serial MIDI relay.

Note, in part 4, I show how one I2C MIDI controller can send to two I2C MIDI peripherals.

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 tutorials for the main concepts used in this project:

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

Parts list

  • 2x Arduino Uno, Nano, or similar
  • 2x Arduino MIDI Interfaces
  • MIDI source (e.g. MIDI controller, computer or keyboard)
  • MIDI sound module (e.g. synth module or computer)

The Circuit

ArduinoI2CMIDIRelay_bb

Once again the two Arduinos need to have their I2C bus linked up as follows:

  • A4 to A4 or alternatively SDA to SDA
  • A5 to A5 or alternatively SCL to SCL
  • GND to GND

Both Arduino’s need a MIDI interface on the serial port.  For the Arduino to receive the input from the MIDI source (keyboard, computer, MIDI controller) it needs connecting to the RX pin to form a Serial MIDI IN.  For the Arduino driving the MIDI sound module (synth, computer) it needs connecting to the TX pin to form a Serial MIDI OUT.

The Serial MIDI IN Arduino will act as the I2C CONTROLLER and I2C MIDI OUT.  The Serial MIDI OUT Arduino will act as the I2C PERIPHERAL and I2C MIDI IN. The relay is acting in one direction only.

Both Arduino’s need power, e.g. over their USB connection.

IMG_5686

The Code

First the reminder – this is very experimental!  It is just a “bit of fun” and I’m still deciding if it has any use or not.  But do let me know if you think of something useful to do with it!

Building on the example code provided in my I2C MIDI Transport library, I’ve added a new example: I2CtoSerialMIDIRelay.

This code uses conditional compilation to decide which of the two boards it is:

#define SERIAL2I2C 1 // Serial MIDI IN to I2C MIDI OUT
//#define I2C2SERIAL 2 // I2C MIDI IN to Serial MIDI OUT

It initialises the I2C and (default) serial MIDI interfaces and then uses the same code as the “dual merger” example to relay from one to the other.  Again conditional compilation is used to set the correct direction.

I’ve ensured that the automated software THRU function is disabled so the only relaying going on is what is explicitly set up in my code.

Here is the code for the Serial MIDI IN to I2C MIDI OUT function.

void loop() {
  if (MIDI.read())
  {
    I2CMIDI.send(MIDI.getType(),
    MIDI.getData1(),
    MIDI.getData2(),
    MIDI.getChannel());
  }
}

The other direction is simply the reverse.

Find it on GitHub here.

Closing Thoughts

Once again, all this comes with the proviso that it is very experimental, but I’m quite pleased with the performance of it so far.  I am not a pianist or keyboardist by any stretch of the imagination, but I was struggling to spot any latency issues between playing notes on my USB keyboard and having them drive my MT-32 sound module.

Not bad when you consider it is going through a technology stack something like the following:

  • USB keyboard microcontroller turning keypresses into USB MIDI.
  • USB to serial microcontroller (my Hobbytronics module) turning USB MIDI into serial MIDI.
  • Arduino turning serial MIDI into I2C.
  • Arduino turning I2C into serial MIDI.
  • MT-32 receiving serial MIDI and producing sounds.

I’m starting to chew over how I could use I2C between a group of Arduinos for distributed polyphony, with a single outward-facing MIDI interface.  It could be the kind of thing that would allow me to update the links within the string section of my Lo-Fi Orchestra for example.  And possibly do the same for my Arduino tones.

In short, I’m starting to see some possibilities if I can gain any assurance that it is reliable enough.

Kevin

Leave a comment