Arduino “Make Your Uno” Synth – 5 – MIDI IN

Having now tried a number of stand-alone projects, I thought it was time to get the Synth Shield hooked up to something else.  And for music, that means MIDI!  This project looks at building and using a serial (“traditional”) MIDI IN circuit for the Synth Shield.

The full index of projects and my personal build notes can be found here: Arduino “Make Your Uno” Synth.

This post contains the following experiments:

  • Building a breadboard MIDI IN circuit
  • Building MIDI IN circuit with the Make Your Uno practice PCB
  • Creating a MIDI monitor.
  • Creating a MIDI Arduino tone() module.

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

  • Arduino “Make Your Uno” Kit
    • Uno
    • Synth Shield
    • Debug circuit
    • Unpopulated practice PCB (optional)
  • USB-C programming lead
  • Means of sending serial MIDI data to the Synth Shield
  • Optional: Ready-Made MIDI Module
  • Or: home-made Arduino MIDI Interface
  • Or: components to build a MIDI IN interface (see below)

Experiment 1 – Breadboard MIDI IN Circuit

Components to build a home-made MIDI IN circuit for the Synth Shield:

  • H11L1 opto-isolator
  • 6-way DIP socket (optional)
  • 1x 220Ω resistor
  • 1x 1kΩ resistor (*)
  • 1x 1N914 or 1N4148 signal diode
  • 1x 100nF capacitor (*)
  • 1x 5-pin 180 DIN socket
  • Connecting wires

(*) These components can be found in the spare parts for the Make Your Uno kit.

Note: the kit also includes a spare 1N4007 diode, but apparently this is a “slow, higher power” diode compared to the 1N4148/1N914 “fast, low power, signal” diode so I don’t actually know if you could use it instead.  The diode is there to protect the optoisolator in case of a MIDI lead being plugged in the wrong way round.  It allows current to flow backwards through the circuit without presenting a high reverse voltage to the LED in the optoisolator.  So with my limited knowledge of electronics it feels like the 1N4007 could do that too – but would it respond fast enough to protect the optoisolator?  I have no idea!  The problem is you’d never know it wasn’t working until it was needed and then didn’t as the circuit will function as a MIDI IN, given a good MIDI lead and good MIDI transmitting circuit at the other end, even with no diode.  I strongly recommend getting a 1N914 or 1N4148 rather than experimenting at this point 🙂

This circuit can be built on solderless breadboard, protoboard, stripboard, or even the Make Your Uno practice PCB!  I’ll come back to that last idea in a moment.

MakeYourUno-MIDIIN_schem

This is a very common design for a MIDI IN circuit and based on a number of circuits I’ve built in the past.  Typically, for use with a 5V logic Arduino, a 6N138 optoisolator would be suggested and a H11L1 suggested for use with 3V3 circuits.  But for reasons that might become clearer in a bit, I wanted to try to use the 6-pin H11L1 rather than the 8-pin 6N138 here too.

The circuit is essentially the same as other H11L1 circuits I’ve used, but I wasn’t sure what value resistor to use for the RX pull-up to 5V. I went with 1kΩ as it gives a similar current limit for 5V operation as the 470Ω of the previous circuit did for 3V3 – approx 5mA.  As I say many times on my blog, I’m not really an electronics person, so if you know better feel free to let me know in the comments!

This circuit can be put together fairly simply using solderless breadboard but it would translate over to protoboard or stripboard in a relatively straightforward manner.

Seeing as I always have to look it up on my MIDI Connections Cheat Sheet (and even then occasionally still get it wrong!) here are two common style pcb/chassis mount MIDI sockets with pins 4 and 5 labelled.

IMG_6769

IMPORTANT NOTE: It isn’t possible to upload a sketch to the Arduino with the MIDI interface connected to RX.  You’ll have to disconnect that to upload and then reconnect it again once done.

Experiment 2 – Make Your Uno MIDI Interface

As I didn’t use my Make You Uno soldering practice PCB (no comments on me needing soldering practice please…), I thought it might be fun to see how a MIDI IN circuit might work using that as the base.

Note that whilst all of these projects are categorised as “beginner”, this one is more advanced and will need a bit of thinking through!

Components Required:

  • All the components required for the MIDI IN circuit in the previous experiment
  • Make Your Uno practice PCB
  • MIDI 5 pin 180 DIN socket
  • 2x 6-way sets of pin headers
    • These are optional but recommended – jumper wires can be soldered directly to the PCB instead if required.
  • Connecting leads suitable for your Uno

This is why I wanted the circuit to use the 6-pin H11L1 – so I could make it fit onto this board!

The actual circuit is the same as the previous experiment, but now it is all being fitted onto the Make Your Uno practice PCB.  Here are the steps I took to make it.

1. Take the practice PCB and solder on the 220Ω resistor, diode, and 1kΩ resistor as shown on the diagram.  DO NOT snip off the legs these will be bent over underneath to make the connecting wires.

MakeYourUno-MIDIIN-PassivesIMG_6770

2. Connect the bottom wire from the diode to the top of the 220Ω resistor.

IMG_6771

3. Solder on two rows of 6-way header pins.  This is optional, but highly recommended as it gives us something to solder the other wires to!  Note: we don’t have to solder all pins, just the two extreme top/bottom on both sides, and an additional pin in the middle somewhere on the right (from the top) for the GND (see the diagrams above again).IMG_6772

4. Connect the top and bottom of the 1kΩ resistor to the nearest top/bottom pin headers.  Connect the bottom of the 220Ω resistor to the nearest bottom pin header.IMG_67745. Place the H11L1 opto-isolator in place carefully noting the orientation – the “dot” (pin 1 – green arrow) off to the left as shown below.  Solder down the one unused pin (pin 3 – yellow arrow) to allow the device to be correctly positioned.  The other pins will be soldered as we connect wires to them.

MakeYourUno-MIDIIN-H11L1

6. Connect the top of the diode to pin 2 (centre) of the H11L1 and the top of the 220Ω resistor (which is already connected to the bottom of the diode) to pin 1 (top) of the H11L1.

IMG_6776

7. Use a piece of insulated wire to connect the top of the diode to the top of the left hand (from the front, right hand from the back) header pins.  This has to be an insulated wire as it has to cross the previous connections we’ve just made.

IMG_6777

8. Place one of the 100nF capacitors from the spare parts in the kit across the top of the optoisolator as shown in the diagram below.  If you are using a smaller disc ceramic capacitor then you can probably get it into the two adjacent holes to pins 5 and 6 of the optoisolator directly. It has to go between VCC (red) and GND (black) as shown in the circuit diagrams.

MakeYourUno-MIDIIN-CapacitorIMG_6778

9. Bend the legs of the capacitor back under the board to connect with the correct pins of the optoisolator as shown below.IMG_6779

10. Add a connecting wire between the top of the 1kΩ resistor and pin 4 of the optoisolator (shown below in brown).IMG_6780

11. Add a connecting wire between the GND pin on the right hand set of header pins (left hand as seen from the back) and pin 5 of the optoisolator (shown below in black).IMG_6781

12. Add a connecting wire between the bottom of the right hand set of header pins (left hand as seen from the back) and pin 6 of the optoisolator (shown below in red).  IMG_6783

And that’s it!  The MIDI socket needs to connect on the left hand side (as seen from above) and the Arduino needs to hook up on the right.

At this point it is worth checking for shorts with a multimeter – particularly making sure there is no connectivity between 5V and GND.  It is also worth a detailed visual inspection and checking continuity between key points e.g. the pins of the optoisolator and the various header pins around the board. Refer back to the circuit diagram as a reference.

If the unused pin headers have not been soldered down, they can be pulled out now if required.

If you’re happy with everything, then try applying 5V and GND. If all seems ok then it’s time to start experimenting!

IMG_6789

Experiment 3 – MIDI Monitor

Parts list:

  • Arduino Uno and MIDI interface (see above)
  • Arduino Make You Uno debug circuit
  • OR: LED and suitable resistor (e.g. yellow LED and 1kΩ resistor – there are spares of these in the kit)

Technically the additional LED is not required as the code will use the built-in LED on the Arduino.  But as the Synth Shield is installed, that LED is somewhat hidden, so it can be useful to break out another LED onto pin 13 via a resistor as follows.  Note that the longer lead (anode) of the LED goes to pin 13 and the shorter lead (cathode) goes, via the resistor, to GND.

MakeYourUno-MIDIMonitor_bb

This experiment doesn’t use any of the functionality of the Synth Shield for now (the pots or audio output).

A simple way to add this is to use the Make Your Uno debug circuit which came as part of the kit.  Note that I’ve used header sockets rather than pins on the jumper wires I soldered onto my circuit just to make it easier to use with my Synth Shield.

Alternatively, I could have used one of the LEDs and 1KΩ resistors that came as spares with the kit.

IMG_6788

The code uses the Arduino MIDI Library which is available via the Arduino library manager or directly from GitHub here: https://github.com/FortySevenEffects/arduino_midi_library.

Once the library is installed and set up the basic idea of the code is as follows:

loop:
  IF MIDI data has been received:
    Check MIDI message if required and do one of the following:
      Turn the LED on (e.g. for a NoteOn message)
      Turn the LED off (e.g. for a NoteOff message)
      Ignore the message (e.g. ActiveSensing messages)
    Otherwise:
      Flash the LED for a short while

This allows me to filter out certain messages (such as the regular “Active Sensing” message my Roland UM-ONE will always send); to act on specific messages – I turn the LED on for NoteOn and off for NoteOff; otherwise just signal some activity by flashing the LED for a short period of time.  This has to be short enough to not delay the sensing too much, but long enough to allow us to actually see it light up.

All of this can be changed in the code in the main loop.

Download the code from GitHub here.

Remember that the MIDI interface should be disconnected from RX to upload the sketch.

Experiment 4 – MIDI Tone Module

The final experiment in this set takes the ideas used so far to play tones in response to MIDI notes.  This uses the same basic code as the MIDI monitor, but instead of flashing an LED it uses the MIDI pitch information to look up a frequency to use for the Arduino tone function that we’ve used before.

Make Your Uno - MIDI IN Keyboard

MIDI NoteOff messages are used to turn off the tones again.  The only thing to watch out for is to check that we only turn off the tone that is currently playing.  The synth is monophonic – it can only play one tone at a time – but most MIDI keyboards will be polyphonic, so they can overlap notes.  If any NoteOff message turns off the tones, then any overlapping notes will result in tones being cut short!

There more details about how it works here: Arduino MIDI Tone Module.

Download the code from GitHub here.

Closing Thoughts

As soon as I first saw the Make Your Uno kit I thought it was a shame that the solder practice PCB didn’t actually do anything!  And MIDI seemed like a natural add-on for a microcontroller synth.

I’m really pleased with how this turned out.  I’d like to find a way to mount it all in the case somehow, but that might be pushing things a little too far!

Kevin

Leave a comment