Saturday, May 11, 2013

Connect Samsung Galaxy S4 to Teensy via MIDI

I like the idea of connecting and controlling circuits from a touch screen device. It seems like a great combination of DIY technology and modern smartphone technology. 

This post describes a basic setup that has been tested and working and is ideal for connecting an Android phone to Touch Daw to OTG Cable to MIDI interface to Teensy.

The MIDI interface is hacked to allow direct connections to data send / receive, 5V and ground, which are needed to power and communicate with the Teensy.

Using the Touch DAW application, MIDI data such as notes, pitch bend, continuous controllers can be used to send data to the Teensy. The Teensy can then be used to control a circuit of some sort.

In order to connect the smartphone to Teensy, you will need:
• An Android phone that can run Touchdaw and can act as a host USB device
• An OTG USB cable (i.e. male micro USB to female USB A)
• A class-compliant MIDI interface, even a cheap one should be fine
• A Teensy microcontroller

MIDI Interface Hacking

This is a cheap USB MIDI interface with one input to one output. It costs $6 with shipping. It is a class-compliant device. This means that the USB MIDI interface does not require any drivers when used with music software on a Windows or Mac computer i.e. it will show up as a MIDI device with an input and an output.

This is the inside of the USB MIDI interface. There are two chips - an optoisolator and a larger microprocessor. It is the larger processor that is of interest. This is an MFM0860 chip, which is a common generic USB MIDI converter. There are four pins that are needed: ground, 5V, RX and TX. 

The RX pin should be used for sending MIDI data to the Android device from the Teensy, for controlling an Android MIDI app from a circuit or a Teensy. The TX should be used for sending MIDI data from the Android device to the Teensy, for controlling circuits from an Android MIDI app. The ground and 5V pins should be connected to the Teensy for power.

• Pin 1 of the MFM0860 is 5V
• Pin 4 of the MFM0860 is ground
• Pin 5 of the MFM0860 is RX (i.e. receive data from elsewhere)
• Pin 5 of the MFM0860 is TX (i.e. send data to elsewhere)

Each pin can easily be soldered to. In this example, only the 5V, ground and TX pins are used, because TouchDaw will be used to send data from the Android to the outside world.

Connecting to Teensy
The Teensy 2.0 has a UART that is separate from the USB connection, which can come in handy. The UART is a serial connection that has an RX and a TX pin.

Digital pin 7 of the Teensy is RX and digital pin 8 of the Teensy is the TX pin. 5V and ground need to be connected to the Teensy. In this example, only the TX connection from the USB MIDI interface is connected to the RX connection of the UART on the Teensy.

The blue wire is the ground, the red wire is the 5V and the white wire is the TX coming from the MIDI interface to the RX input on the Teensy.

Teensy CodingThe Teensy code is relatively straightforward, but keep in mind that:
• The code needs to facilitate the use of the Teensy UART to accept incoming data
• The code needs to facilitate MIDI protocol for incoming data
• The code needs to make use of received status bytes, as some Android apps may format data in that way

A skeleton code that contains blank function for: NoteOn, NoteOff, ContinuousController and PitchBend across all channels can be found here:

Use With TouchDaw

Setup in TouchDaw is easy:
• Connect the Teensy to the MIDI Interface
• Connect the MIDI Interface to the OTG cable; Connect the OTG Cable.
• Launch TouchDaw on the Android
• Go to the Main Menu; Go to Setup; Go to MIDI Utilities
• Go to MIDI Connection, and choose USB > USB MIDI Interface