Sunday, January 3, 2016

MIDIfication

My projects are regularly based on the Teensy and Arduino/Genuino development platforms. While the former natively supports MIDI over USB, I often have the need for DIN support. The following instructions connect DIN input and outputs to you Teensy (all) and Arduino (Zero, Uno, Due, Mega, Leonardo, Yun, Nano, Micro, Mini) boards.

The circuit in general is very simple and can be soldered by beginners as well. For testing purposes, a prototyping board can also be used:




MIDI Out

Connecting a DIN output to the Teensy is straight forward. Although the Teensy runs at 3.3V, while the MIDI standard specifies 5V operation, virtually all MIDI devices function with a 3.3V connection without any problem. To have DIN MIDI output, connect pin 2 of the output DIN to ground (Teensy pin GND), pin 4 through a 220 Ohm resistor to 3.3V (on the Teensy), and pin 5 gets connected to the Teensy's TX (Teensy pin 1):

  • MIDI OUT pin 2 - Teensy GND
  • MIDI OUT pin 4 - 220 Ohm resistor - Teensy 3.3V
  • MIDI OUT pin 5 - Teensy pin 1 (TX)


MIDI In

The DIN input is a bit more elaborate. Here, we isolate our circuit from the circuit of the MIDI partner (which itself will be isolated from all input, that is why our output can be so simple). We do this with an opto-isolator, and a good one for this purpose is the 6N137 for its sharp transient signals and 3.3V suitability. Also it is cheap and available from numerous manufacturers.  Pin 4 of the input DIN is connected through a 220 Ohm resistor to pin 2 of the 6N137 (the spot marks pin 1, we use the one directly next to that), and DIN pin 5 goes to 6N137 pin 3. Similarly, pin 5 on the 6N137 is connected to the GND pin on the Teensy. Pin 6 goes to RX (pin 0) on the Teensy, and 8 on the 6N137 goes to 3.3V as well as RX (the latter through a 5.6 kOhm resistor). If you want to be extra secure, you can stabilise the 6N137s power lines by putting a 100n capacitor (ceramic is fine) between them (pin 5 and pin 8) as close to the chip as possible. To further protect your circuit from reverse polarity (someone swapping + and - on the MIDI cable), add a 1N4148 diode between pin 2 and 3 of the 6N137. While the orientation of all resistors and capacitors used here does not matter, the diode has to be put in a specific direction: the side with the solid black line points to pin 2:

  • MIDI IN pin 4 - 220 Ohm resistor - 6N137 pin 2
  • MIDI IN pin 5 - 6N137 pin 3
  • 6N137 pin 2 - 1N4148 diode - 6N137 pin 3 (the black bar on the diode points to pin 2)
  • 6N137 pin 5 - Teensy GND
  • 6N137 pin 6 - Teensy pin 0 (RX)
  • 6N137 pin 8 - Teensy 3.3V
  • 6N137 pin 8 - 5.6K resistor - Teensy pin 0 (RX)
  • 6N137 pin 5 - 100nF capacitor - 6N137 pin 8

Software

The standard Arduino MIDI library can be used to access the DINs. Actually, please use the standard MIDI library. The one that comes with the Teensyduino environment is based on a much older version and will not function correctly with my code (it is initialised differently).

If you start from scratch on a Mac (it is basically the same in Windows, but I happen to have a Mac):
  • Get the Arduino IDE from here and install it
  • Get the MIDI library from here and install it (described here)
  • Get the software you want to install from my GiHub repository
  • Open the firmware in the Arduino IDE and edit the features listed in the beginning of the file
  • Use the USB cable to connect the Arduino to your computer
  • Choose your Arduino board and its connected USB port in the Tools menu of the IDE
  • Press the Upload button
  • VoilĂ 

Prototyping

In the above picture, the connections are as following (always from left to right): top left - DIN input pins 5, 4; bottom left - DIN output pins 2, 4, 5; bottom right - Teensy pins 1, 0. Also don't forget to connect + to 3.3V on the Teensy, and - to GND. For the interested among you, the schematics are the following:









No comments: