The definitive MIDI controller | This is not rocket science


So you think you need Bluetooth audio…

You know the feeling, there’s this little project itching in the back of your mind, and as you procrastinate upon it, you realize just one part is missing.

It needs Bluetooth. The audio kind. It should play music from your phone. But you really don’t want to delve into antenna design and protocols just now… And it should sound good. Like, really good. How to go about that?

For me, the answer was in my pocket! I had been using one of these TaoTronics audio dongles for a while and the sound quality is great. So maybe I could just figure out which chip it is using, get one, and embed one into my project?

It’s a very simple device though. You press the “play” button for a second or two, the power comes on. You long press the play button again and it powers off. There’s a volume control, a microphone, and the play button… USB charging, and a battery… No need to make it complicated.

I don’t want to do this the hard way. I don’t want to deal with another complex IC and crazy datasheets.

How about I just use the dongle itself, without any modifications? It does everything I need. I could just take the sound out of it with a cable, the way it’s supposed to be used. But I don’t want a separate dongle, really. And I don’t want to keep on charging the battery constantly. Maybe I could hide it, just put one of those directly into my project! The size is right…

But I don’t need a battery at all. I’m going to have a proper power supply. And I can do better than whatever headphone amp is in that thing. I don’t need the buttons either, if it’s always on.

Time to crack it open and see what’s inside! (After ordering a second one for continued personal use – these are lovely devices.)

Long story short, after a little bit of probing, I could figure out how the battery and power button are wired. When power comes on, the dongle starts blinking two leds. I could “press” the power button with a transistor, and probe those leds to detect when the chip is alive to let go of the “button”. It did not take much time at all to write a piece of code on an NXP KL02z to control the dongle. A simple state machine would do.

It turns out that the chip in there has a rather neat, high quality differential audio output. It was AC-coupled to the internal headphone amp, so I replaced that with my own preamp circuit+antialiasing filter (just in case.)

It’s a bit of a crude hack. I removed the battery and power it with a regulator with roughly the right voltage. The board is literally just soldered on. OK, the audio DC bypass caps are a bit exaggerated perhaps, but it adds to the sound.

But it does the trick, and it does it marvellously!

Eurorack DSP development platform

We wanted to start making DSP-based modules for the Eurorack modular synthesizer format. The problem was just that there is no easy way to get started; there are no evaluation boards on the market made for this purpose, so you always need something custom for every project. So I decided to make one.

Eurorack is a relatively simple platform: it provides you with dual power supplies (+/-12V), a standard signal level of about 10V p-p, and control voltages roughly in range 0-5V. Pitch control is in 1V/octave; one volt increase in a pitch control voltage should double the pitch of a controlled oscillator.

You want to write DSP code, so you need a DSP processor. Everything is ARM these days, and with the good experiences with the KL26, we decided to try the Kinetis MK22F series. This one has hardware floating point support (single precision) and set of integer DSP instructions: it can do integer MACs in 1 clock, with a 64-bit accumulator! At 120 MHz!

The board would also need some way to get audio in and out of the processor, and the standard way to do that is to use an audio codec connected over an I2S bus. After some searching I found the AK4558 stereo codec, which has some very intriguing capabilities. It allows you to select between different antialiasing filters, some with very short group delay! The codec can also run at 192 kHz sample rates, which, combined with low-latency filters, means that the total latency for passing audio through the CPU is very low. It’s not zero, so if you mix the processed output with the input, it will still result in phase interference, but it looked very promising for short delaylines.

What else do we need? Not much, really. I wanted to have a module that could be used for development, or plugged in to an Eurorack module frontpanel for placing it in a rack.

The finished development board looks like this. On the bottom there’s a standard Eurorack power connector, and on the top two rows of pins for connecting to a front panel (or plugging in other things.)

Voltage conversions have to be provided off the board: gate signals have to be adapted to (and from) 3.3V range, and adding more CV output signals needs an external DAC. But those can be added on the front panel boards.

You can think of it as an “Arduino for Eurorack DSP code”. Development takes place in the Kinetis Design Studio, which also provides full debugging capabilities. All code is written in C++ (unless you insist on Assembly…)

And here’s how it looks like when plugged in to a frontpanel!

USBmidi2 4×4 teaser

Here’s a snap of the USBmidi2 4×4 fit on a lasercut half-rack proto panel (can you find it?):

USBmidi2 4x4 halfrack

USBmidi2 4×4 halfrack

The rack PC mount was another small side project. I have had that Nord Modular for some 13 years. Now finally I got its editor running in the place where it belongs, right next to the synth! The PC and screen are from ebay, with the PC hiding behind the display. The mount for buttons and the PC was manufactured Protocase. Some wires are still sticking out, the buttons are not hooked up yet.

USBmidi2 4×4 coming soon!

Second iteration: USBmidi2

usbmidi2 full frontal

usbmidi2 full frontal

* Download datasheet *

USBmidi2 is a USB MidiStreaming class-compliant device, in double. It connects your computer, over MIDI, to another computer.

USBmidi2 is also a component that you can embed in your own musical instruments. Add a USB MIDI device port to your project, along with the three standard MIDI jacks!

To skip to the end of the story, I built a few of them to share.

Drop me an email if you are interested in acquiring one at a reasonable price.

USBmidi 1x1Sold out!
USBmidi 4x4Almost there!

I got a few requests for a MIDI interface for the Raspberry Pi, so that the Pi could be used as a component in a hardware synth module. The point was that most MIDI interfaces only have a single USB device port for connecting to a computer, and that one is taken when you plug it to your Pi. Yet a synth should behave like a USB MIDI device itself, so there should be a second port for a laptop.

So two computers, talking to each other over MIDI over USB, both acting as USB hosts… no problem! Stijn had told me about these really really nice Kinetis KL26 microcontrollers with plenty of UARTs and a built-in USB interface. One USB interface, per chip.

The only MCU with two USB interfaces that could possibly fit this purpose was the NXP LPC43xx series that I used in the signal analyzer. But the LPC is massive – TQFP144 – while the KL26 is small and flexible. So it was clear: there should be two KL26’s, with one USB port each, connected together. And the overall design seems simple enough, this way:

usbmidi2 design

The board appears as two MIDI ports on both computers. First port goes directly to the other USB host. The second one is connected to the MIDI jacks, and data is interleaved from both computers.

usbmidi2 connections

You can see the MIDI in/thru/out ports and the slave USB connector in the picture of the front of the device, at the top of this page. The backside has just the USB jack for the Pi, and looks like this:

usbmidi2 left profile

First batch of usbmidi2. Fresh hand-made boards, mmm! :)

First batch of usbmidi2. Fresh hand-made boards, mmm! :)

This is how it works in practice:

usbmidi2 connected to a Raspberry Pi

usbmidi2 connected to a Raspberry Pi; the board is intended to be mounted behind a panel, so that the Pi fits inside the same enclosure.

I’m also working on the expanded version; since you read all the way down here, here’s a teaser ;-)
usbmidi2 4x4 front viewusbmidi 4×4 – not announced yet!

Mounting dimensions: See datasheet.

Further technical details: TBD

Source distribution:

KL26ZxxxVFM4 pinout

The KL26Z feels overall like a very nice MCU; the collection of features and the pin mapping that it provides works very well for me. The chip does USB natively, it has three serial ports, two SPI, two I2C, I2S, plenty of muxed ADC channels, and a DAC… The evaluation board is a scam, but can be converted into a cheap debugger with USBDM. And Erich Styger has made some really impressive work writing Processor Expert modules that also work with this chip. And the chip itself is tiny. I think I’ve found my new favorite microcontroller.

The datasheet and manuals are a mess. So I combined the pin layout, spread over three pages, on a single printable page. Click the picture below for a print-size version.

KL26ZxxxVFM4 Cheatsheet

ATtiny85 breakout boards

The ATtiny85 is one of the smallest microcontrollers in the AVR ATtiny series. In a SO-8 package it’s the size of a small opamp, perfect for tight boards. It’s not much of a beast though, with effectively only 5 free I/O pins, but surprisingly often that’s just enough.

Tiny MCUs like this come especially handy for prototyping, where you might just want to try something that needs a couple of control voltages, and the bulky Arduino is already hooked up to some other ongoing project. So I drew up some breakout boards and ordered them from DirtyPCBs. Leds and buttons come handy too, so I added one of each…

Since most forces will be exerted on the ISP connector and the button, I placed those in the middle of the pins. The ISP connector has the standard pin layout, and any AVR ISP programmer will work. Most components are 0603, only the 10uF cap has a bigger footprint.

If you like the boards, order the PCBs from DirtyPCBs!


The schematic is like this:

Only one of the two resistors “RESET H” or “RESET L” should be placed; “H” pulls reset up to VCC, “L” down to GND. I used 10k for these. R1-R3 can be smaller, such as 1k ohm; these resistors are in place so that the ISP connector can work correctly when the board is connected to the prototype breadboard.

My breadboard prototypes invariably turn into these messy knots of wire… here the ATtiny85 drives an ENC28J60 ethernet controller (and some extra stuff):


Testing the tiny switching regulators

The post for my tiny switching regulators wouldn’t be complete without some measurements. It’s easy to make a fake device that simply “does something” and still in the end doesn’t work like it’s supposed to. So here are some pictures of the regulator under load.

3.3V switching regulator under load 1

The input of the regulator is connected to a 9V power supply. The output goes into the blue/black box, which is my constant current load (more on these devices in a later post!), set to sink 800 mA. The voltage it’s showing is unfortunately too low; it’s measured at the end of all the wires, and thus includes wire losses. But the current is exact to the last digit. The regulator gives out 3.3V, and thus the total power consumed by the load is 3.3V * 0.8A = 2.64W.

According to its meters, the power supply is giving out 9V * 0.34A = 3.06W of power. notice that its current output is much less than 800 mA, so we’re indeed looking at a switching regulator. If we were measuring a linear 3.3V regulator, the power supply would have to also provide the full 800 mA, totaling 7.2W, and requiring a decent heat sink!

The efficiency of the switching regulator at this load is 2.64W / 3.06W = 86%. Nothing special there, at lower loads it improves a little bit, getting closer to 90%.

3.3V switching regulator under load 2

Here’s how the power output looks like on the oscilloscope. The ripple is at 13.6mV small enough to be difficult to measure on the Rigol oscilloscope, I couldn’t even get it to trigger correctly! The average voltage is very close to 3.3V.

The most important property of the regulator is of course its low heat dissipation, thanks to the high efficiency. The power was on for several minutes, and the regulator remained only slightly warm to touch. The power diode was the warmest individual spot. That concludes this wholly unscientific study. :-)

Tiny 3.3V switching regulator boards

The protosynth front panel is shaping up nicely, and I’ve been looking for ways to make the design more modular and reusable. I tried first a fully modular design made of small sub-boards (with some 4 knobs or a couple of buttons+leds each) hooked to a master controller board, but it felt too fragile and would have required a lot of tricky wiring to finish. So instead of making the whole panel modular, I’m now going for a more conservative design consisting of just one large board, yet there’s still some room for reuse…

The logic level of the front panel board will be 3.3V, just like the rest of the processors on the synth. But since the front panel is at the end of a longish cable, and because it’ll likely boast plentiful leds that actually consume a measurable amount of power, I’d rather make use of the main 9V power input and regulate it down to the correct level separately. Having a dedicated regulator for the front panel board and its logic chips will hopefully result in less noise making its way to the DSPs and codecs on the main board.

There could easily be some 20-40 leds total on the panel, in addition to one or more microcontrollers, tens of potentiometers and encoders, and a bunch of logic ICs to probe all the controls. A linear regulator might be able to deal with this just fine, but since the panel will be quite crowded (the knobs are large), there won’t be much space for a heat sink. The voltage drop across the regulator would be some 5.7V, and thus the total power consumption for the regulator alone can be in the range of several watts. That’s a lot of heat…

So this time a linear regulator most likely won’t do, and switching regulators are the way to go. And for sure this won’t be the only time that they are useful. It would be very convenient to have a tiny regulator component that you could just drop in when needed, without having to worry every time about excess heat or careful routing.

I drew these tiny switching regulator boards loosely based on the LM22675 reference design. The result is a small “chip”, roughly 25x20mm in size, with the corner pins 900 mil apart. It leaves plenty of space even on a breadboard. And it’s light enough to be mounted by just soldering the pins to the main board.

3.3V regulator

The regulator is spec’d for 1.0 A, but since I used some leftover diodes, the practical maximum current output is some 0.8A at 3.3V. And the thing won’t even heat up noticeably above ambient temperature with such a load! The efficiency is a nice 90%.

The pinout is extermely simple: input, output, and enable. And the enable pin can be left floating, as it has an internal pull-up. Pulling it down will immediately cut the power.

The boards are intended to be soldered directly on top of a main board. The pins will separate the two boards by a bit more than a millimeter, so some small smd components, such as the 0603 SMD capacitors and resistor I mostly use, will easily fit in between them.

Here is the pinout:


And finally, the schematic.

3.3V switching regulator schematic

I’ve built a few extra ones, send me email if you find interest in them.

USB MIDI interface

The RPC is a MIDI controller and implements the age-old 1980s serial MIDI bus, and the Protosynth must be capable of interfacing with it. But in general use a USB device port is much more practical than the three ubiquitous MIDI ports; it allows connecting the synth directly to a laptop or other computer at any time. And USB host ports are starting to become popular in sequencers also. So that means I need an interface module that has both, and that can talk to the main synthesizer board over two serial buses. The mainboard processor must take care of interleaving the commands received over the two buses.

Standard MIDI ports are no problem, I had the basic circuitry working with the RPC and could simply lift it from there. The synth’s LPC1678 microcontroller has several UARTs, and it’s very easy to configure them according to the MIDI standard. USB was going to take some more work though. I didn’t have enough space on the DSP mainboard to make use of the LPC’s built-in USB controller, so I decided to keep it that way and went for an off-board solution. My approach was to build an external board that could speak MIDI over USB, and pass the data stream over an UART to the mainboard.

Here’s the general idea:
DSPMIDI block diagram

Luckily USB-capable microcontrollers are a dime a dozen these days, so it’s only a matter of choosing a suitable one for the purpose. A little bit of searching found me MocoLUFA, which is a complete implementation of a standard MIDI USB device for the ATmega, created by morecat_lab. The ATmega8u2 it was intended to be used with looked very nice, and its bigger brother ATmega32u2, while pin compatible, would have plenty of capacity for future expansions if necessary. The Arduino Uno is one example of the use of these chips; the Arduino team very successfully replaced the previous FTDI USB controller with an ATmega8u2 to reduce the cost of their boards. With inspiration from the Uno schematic and from the ATmega32u2 datasheet, I drew up the first version of the MIDI board.

DSPMIDI rev1 assembled

The design was straight-forward. I used the 4N28 optocoupler and through-hole components for the MIDI side because I had those at hand. Except for the bypass capacitors. I have a lot of 0603 size 0.1uF caps now! :-) In the default configuration (F1 unpopulated in rev2 schematic) the device is self-powered: it will NOT draw its power off the USB bus. That means the it will disconnect from the computer when the it is powered off, as expected for a stand-alone device. It requires an external 3.3V power supply, and the signal voltage for all communication to and from the mainboard is 3.3V. The MIDI DIN5 connectors are very close to each other in the first revision of the board; while there are some DIN jacks that should fit, I dragged them a little bit apart for the second revision. Almost all of the GPIO pins on the ATmega are wired to am extra pin header next to it. Four are connected to SMD LEDs.

The ATmega8u2 does not have a dedicated VBUS pin for detecting whether it is connected to a USB host or not, and the MocoLUFA software can be configured to use some other GPIO pin for this purpose. In the end I left VBUS unconnected, because I wasn’t sure if the ATmega could handle overvoltage on the pins. The data sheet indicates this should be avoided. The USB firmware still works, albeit not completely according to the standard.

The two serial buses connecting the interfaces to the mainboard run at different bitrates. The real MIDI interface must be configured at 31250 bps. The USB interface doesn’t seem to have any such limitation, so I set it to 125 kbps. Just because it was a nice round number with the ATmega running by a 8 MHz clock. I’m not yet sure what kind of flow control the USB bus is capable of…

For programming the ATmega you will need an AVR programmer that can be hooked to the 6-pin ICSP port. I used a 5V Arduino Mega 2560 with the ArduinoISP firmware installed on it. The supply voltage of the Arduino is not an issue as long as you keep the MIDI board otherwise completely disconnected during programming. The MIDI ports are designed for a 3.3V power supply, so if they are powered by 5V they may fry any connected MIDI devices! During programming the board will draw power through the ISP port.

Here is the schematic, click for a larger image:
DSPMIDI rev2 schematic

And the board layout:
DSPMIDI rev2 layout

I will add the gerber files and BOM here later. Drop me an email if you’re interested in them or the Eagle source files (see bottom of page for the address). I have several rev1 PCBs left, and will most likely solder together at least a few more if all goes well. There are many possible interesting configurations of the board. For example, if the ATmega32u2 is sufficient for your application all by itself, the MIDI ports could be connected directly to it… How about a stand-alone arpeggiator board?