Home > News & Updates > Electronics News Updates > MIDI to USB Adapter with Teensy

MIDI to USB Adapter with Teensy

Summary of MIDI to USB Adapter with Teensy


This article details the creation of a custom MIDI-to-USB adapter using a Teensy LC microcontroller to replace a faulty commercial adapter. The author leverages the Teensyduino library for seamless Arduino-based programming and USB MIDI functionality. The project focuses on a simple hardware circuit involving an optocoupler to ensure reliable signal isolation between the MIDI DIN connector and the microcontroller, solving issues where pedal events were incorrectly interpreted as note events by cheaper adapters.

Parts used in the MIDI to USB Adapter:

  • Teensy LC microcontroller
  • HCPL-2531 optocoupler
  • MIDI DIN connector
  • 220 ohm resistor
  • 4k7 ohm pullup resistor
  • USB cable
  • Breadboard and wires

Among my recent electronics purchase spree was the amazing Teensy LC from PJRC. It has a nice ARM Cortex-M0+ processor, real hardware USB, and what’s the nicest part, an Arduino add-on called Teensyduino which enables easy programming with Arduino, but with support for many of the hardware features.

Now I started playing piano a while ago, and just a few weeks ago bought a Pianoteq license to send notes via MIDI to my computer, and render high quality piano sound to speakers. However, it turns out my $8 USB-MIDI adapter from DealExtreme had a less than perfect implementation, essentially changing pedal events into “note on” events!

Thankfully, I had a MIDI connector and a high-speed optocoupler at hand, and with these I could implement a MIDI in rather easily. After some investigation with Arduino Uno, it seemed quite simple to receive the serial MIDI bytes and dump them over Arduino serial (I’ll write another post about this later).

However, Arduino cannot become a USB MIDI device very easily, so here comes the really nice part: Teensy LC can, and the Teensyduino add-on included a working USB MIDI and also serial MIDI libraries!

The Hardware

The Wikipedia page for MIDI essentially shows the required circuitry for receiving MIDI data – wire the DIN cable pins 4 and 5 through the receiving side of optocoupler and put a 200 ohm resistor in series with it. A diode is also suggested for reverse current (ESD) protection, but I skipped that. You can start with a LED instead of optocoupler to see it lights up if you’re unsure you have pins 4 and 5 the right way. Or just put the LED (with a resistor) on the other side of the optocoupler first.

The HCPL-2531 I had at hand requires an additional VCC connection on the sending side. After some experimentation, a 4k7 ohm pullup resistor between VCC and VO1 (NPN-transistor base?) gave the cleanest signal out. The wiring diagram (thanks Diptrace!) is shown below:

As you can see, only a Teensy LC, the optocoupler, two resistors (220 ohm for the MIDI side, 4k7 for the Teensy side transistor load resistor) and some wire is needed. Talk about simple! Below you can see a pictorial representation of the above diagram:

So essentially the circuit has (HCPL 2531 part on the left for reference):

  • Teensy LC “G” and “3V” pins wired to GND and VCC rails of the breadboard
  • Optocoupler pin 8 (VCC) to VCC rail
  • Optocoupler pin 7 (VO1) to VCC via 4k7 ohm resistor
  • Optocoupler pin 7 (VO1) also wired to Teensy LC pin “0” (serial RX)
  • Optocoupler pin 5 (GND) to GND rail
  • Optocoupler pin 1 (ANODE1) to PIN4 (I think) of the MIDI DIN connector
  • Optocoupler pin 2 (CATHODE1) to PIN5 (I think) of the MIDI DIN connector via 220 ohm resistor
  • USB cable to computer

That’s really it! Depending on the exact type and model of the optocoupler, the wiring may be a bit different, but not much. If you have a different model and are not sure how the pins work, I suggest first making some tests with LED’s on both sides and a multimeter (or oscilloscope preferably) to see how the signal is transmitting over the optocoupler.

Read more: MIDI to USB Adapter with Teensy

Quick Solutions to Questions related to MIDI to USB Adapter:

  • Why did the author replace the existing USB-MIDI adapter?
    The previous $8 adapter had a poor implementation that changed pedal events into note on events.
  • What processor does the Teensy LC use?
    The Teensy LC features an ARM Cortex-M0+ processor.
  • How can the Teensy LC be programmed easily?
    The Teensyduino add-on enables easy programming with Arduino while supporting many hardware features.
  • What is the required wiring for the MIDI DIN connector pins?
    Pins 4 and 5 of the DIN cable should be wired through the receiving side of the optocoupler with a 200 ohm resistor in series.
  • What resistor value is needed for the optocoupler's VCC connection?
    A 4k7 ohm pullup resistor between VCC and VO1 provided the cleanest signal for the HCPL-2531.
  • Which pin on the Teensy LC receives the serial data?
    Optocoupler pin 7 (VO1) is wired to Teensy LC pin 0, which serves as the serial RX input.
  • Is a diode necessary for reverse current protection in this circuit?
    The author skipped the suggested diode for ESD protection but notes it was originally suggested.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top