Sponsored by

Navigate

Check these out

Tag: pro micro

This article will detail how to build a USB MIDI adapter (one-directional: you connect the adapter with USB cable to your computer, and it receives notes and pedal data from your keyboard’s MIDI OUT and transmits them to your computer) with ATmega32u4, 6N137 optocoupler, a few resistors and spare MIDI connector or cable. Read on for details!

Preamble

Last year I wrote how you can turn Teensy LC into an inexpensive USB MIDI adapter. I used it to replace a non-working Chinese MIDI-USB adapter that did not send controller messages (i.e. piano pedal) properly to PC.

However, since the Teensy still costs $12, and you have to get some additional components, it doesn’t make sense to use it in a dedicated MIDI adapter, since you can get a working USB MIDI adapter for around $15 from Thomann and probably many other places.

But how about other boards? After making my Teensy LC adapter, I actually tinkered with Adafruit Pro Trinket, and got that working as well (the standard Trinket does not have hardware UART so V-USB and software UART is somewhat risky). But there is even a better board for this: The ATmega32u4 board I previously showed how it can be made into USB HID mouse. Let’s see how to turn it into a USB MIDI adapter!

Required hardware

To build this, you will need roughly $5.40 worth of components:

SparkFun Pro Micro (clones with ATmega32u4 can be had for $3.50 from AliExpress, eBay, etc.)

6N137 optocoupler, which can be had for ~$0.30 a piece (I suggest sourcing a couple in case you burn one by accident)

330 ohm and 2 kohm resistors ($0.10) and 1N4148 diode if you want to be safe

MIDI connector or alternatively you can just cut a short cheap MIDI cable and wire it to your project, let’s say $1.50

I have spent a fair amount of time with 8-bit AVR microcontrollers and one of the cooler things has been the V-USB library which implements low-speed USB with clever (and very time-critical) bit-banging. The popularity of my USB tutorials is a testament to its usefulness, and I’ve gotten lots of mileage out of that.

There are, however, some limitations to software USB with such a low spec microcontroller. USB communication hogs up the MCU completely during USB communication, which means you lose dozens of microseconds in random (or in many cases 8 ms) intervals. This rules out things like software UART at reasonable speeds (which I discovered when trying to implement MIDI on Adafruit Trinket). And more powerful ATmega328-based dev boards like Pro Trinket start to get quite large.

Not so with this tiny beauty shown in the image. It’s a ATmega32U4 based board, where the U4 means it has hardware USB support. The form factor is extremely compact 12 pin header length, which leaves 5 rows free on the smallest prototyping breadboards. That means you can have a DIP8 component with a few resistors on the same breadboard (such as a 6N137 optocoupler which is nice for MIDI… ;).

And the best part is, that because the chip is flashed with same firmware used in Arduino Leonardo (and a largely matching pinout), you can use Arduino for programming, and avrdude supports it out of the box.

Actually, scratch the above statement. The best part is the price. The board is based on Sparkfun Pro Micro 16 MHz, but it’s actually a Chinese clone, which you can get for $4 via DealExtreme and from quite many places in AliExpress: Just search for ATmega32U4 and they will come up. This means you can just order five and solder them into whatever project you’ll make permanently. And unlike Arduino Micro (for which clones exist as well), this has the micro-USB port already in place.

Using Pro Micro without Arduino IDE

Now you can just follow SparkFun’s instructions on how to use that thing on Arduino (short version: select Leonardo as board type, and look up the schematic if you are unsure which pins are connected to LEDs, etc.). But if you’re like me and want to get to raw metal, avr-gcc and avrdude is the way to go. Here’s a simple blinky demo:Continue reading USB Mouse with ATmega32U4 Pro Micro Clone and LUFA