Arduino to MIDI implemented !


I have finally reached one of the objectives I have had for a long time since I have started this blog: converting physical signals captured by Arduino into MIDI messages that I could use in some program on my laptop (like Resolume for VJing).

First of all I would like to tell you what DID NOT work for me.

I have seen on many blogs that what usually people do is a operating system-level trick: they install a serial to midi driver that reads the serial port and generates midi messages as it was a midi device connected to the system.
This is the way it is actually done by many midi devices manifacturers, and actually the trick just consists in downloading and installing one of their drivers.
The most famous one is the Roland serial midi driver, which is seems not available on some operating systems (e.g. Windows 7). A much more interesting driver is offered by Yamaha on this site, but I have tried it and it wouldn’t install either.

So in the end I thought: why don’t I just create a Java application myself that reads the serial port and routes the MIDI messages to some midi device?

The first problem was finding a reasonable solution for reading serial ports in Java.
You would think “hey! this is pre-history of computer science!”, or at least this is what I thought, but being Java anti-low-level-stuff it doesn’t have a “normal” way for doing it.
There is a standard API, the Java Communications API, that was once created by SUN and then discontinued. Actually the standard implementation, which used to work also on Windows, is now only available for some Unixes. Fortunately some guys created the RTXT library which is an alternative implementation of the same API, and which offers support for all operating systems. So I have adopted this last one and made it sniff my Arduino messages.

Then I had to implement a protocol to send midi messages from Arduino. I could have used the MIDI itself, but it was then difficult to separate messages one from another as there is no standard separator, so I just made an extremely simple protocol myself.

The protocol follows these rules:

  • one message per line (i.e. packets are separated by a carriage return)
  • Control changes are represented as: cc ch 10 ctrl 12 val 130 (where ch stands for channel, ctrl stands for control and val for value)
  • Notes ON are represented as: non ch 10 key 12 vel 120
  • Notes OFF are represented as: noff ch 10 key 14 vel 120
  • Aftertouches are represented as: at ch 10 key 14 tch 100

Then I created an utility that interprets these packets and sends them back to some MIDI interface you may have on your computer.
If the objective is to use these messages in some program, like in my case, then you would also need some MIDI “router” that receives messages and sends them back to another interface. For this objective I have used the LoopBe1 free tool, which works on my Windows 7 64 bits (i.e. it is updated). For other operating systems I am sure there are similar alternatives.

The result is some code for both Java and Arduino.

Let’s see the example for Arduino first:

void setup() {

void loop() {
float sensorValue = analogRead(0);
int intValue = (sensorValue / 1023) * 127;
String value = intValue;
Serial.println("cc ch 10 ctrl 12 val "+value);

As you may see, it is just a simple example that reads the value of pin 0 and sends it as a control change on channel 10, control number 12. The value is normalised to 0-127 (as the MIDI standard requires) and then put into the string.

More interesting may be the Java code, which can be seen here.

I have also resumed the functionalities in the wiki page.

In order to make it simple to use I have created a GUI for it. It lets you choose the midi output, the serial port and then it has just a start/stop button to activate/deactivate it.

In order to work, the proper native library of RTXT must be put into the Libraries folder when compiling it from Eclipse (see the original instructions here). The current native library is for Windows 64 bits.
If you have any problem don’t hesitate to contact me.

So, the proof of the concept is completed, now there are thousands of ideas that come to my mind on how to improve/generalise this.

Here you can see a demonstration that I am not lying:

Any comment is welcome !



  1. Update:
    I have just found a little program that does more or less the same but with a standard MIDI protocol:

    Please also take a look at the possibility of programming and Arduino UNO as a MIDI device thanks to MOCO firmware:
    which allow using the standard Arduino MIDI library

    finally there is a board which natively supports MIDI: Teensy, see

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s