Serial to Midi converter!
So I’ve just finished writing an application in Processing which converts midi data coming in over USB to “real” midi data which can then be routed to wherever you want.
But, why should you care? Well, because now you can make and use an ArduinoBoy with no soldering at all! In the picture to the right, you can see the wires coming from the Gameboy link cable into my breadboard, with jumper wires linking this to my Arduino. You could just as easily put the wires straight into your Arduino, though. Then, a couple of quick changes to the ArduinoBoy code to force it into “LSDJ Master Sync” mode (all at the top of the main file, and with very friendly names) and you’re set. Plug everything in, launch my serial2midi app, and bingo!
Heres a vid of it in action:
Here are the downloads (including source) for the serial2midi app…
(Only tested under OSX)
And finally, some more images:
UPDATE:
There are some things which I forgot to mention when I originally posted this. Midi over USB is not as fast as using real Midi. If you’re using LSDJ master sync mode on an ArduinoBoy for example, on my computer I start to get some noticeable latency around the 130bpm mark. Having said that, if this were being used only to route note data, there should be no problem at all.
Another thing I forgot to mention is that this version of the app is running at a fixed baud rate of 38400. Soon I’ll make it selectable, as faster baud rates should give lower latencies. Still, the latencies you get with this thing are not as low as you would get over real Midi – but I think for ease of use (ie no need to build any Midi circuitry) this is still a pretty handy app.


hmm…. idk. latency? how could i solve that?
@rey
there’s no real way to get around it. using a max patch instead of processing could help, or perhaps a higher baud rate. in this im using 9600 but im thinking using a baud rate of 119200 (or whatever the highest one is) would solve a lot of problems. having said that, midi only runs at 36-thousand-ish, so i think baud rate is probably not the problem.
using real midi for the arduinoboy would fix everything!
hey – quick question, is it possible to use your midi converter to control arduino over MIDI? i.e. connect a synth to a computer through USB and route that data internally (OS X) over to the arduino board to control in real time some digital I/O?
thnaks for your time
@venya
not at the moment, as i had some problems with getting the midi signals in. i’ve just started playing with Max MSP, though, so perhaps i can make a patch in that which would be a better solution to this.
how important is this for you? if its just curiosity on your part, then i wont bother too much… but if you have a project which relies upon it, then i’ll try my best to either fix this up or make a max patch
hey man – thanks for getting back to me. The project I am working on is for an upcoming performance I am involved in, where we are building a light organ. This will be quite a large scale mechanism built out of clear acrylic pipes. Each pipe will have a set of LED’s at the bottom – and at the front of this will be a midi keyboard (plugged into a sampler with a load of organ sounds). I want to make it so that when the performer plays a note on the keyboard a corresponding light will come on. This way the organ will appear to be a light organ. There will be 14 pipes in the organ. What I need to be able to do is to take a midi input into my computer and send it along to the arduino board to control in real time the lights. Looking at the arduino site it mentions how to interface arduino with max msp and gives all the appropriate midi libraries necessary. I would really appreciate any help with this since my background is much more live video and this is all new and exciting territory.
thanks
@venya
I’ve built a Max patch quickly, it will send messages such as “60 on” when a middle C (midi note 60) goes on, and then “60 off” when it goes off. I’ve not had a chance to test it, so it may or may not work – but I’m putting it here to let you try. If it doesn’t work, then when I get a chance to play with it some more I’ll try to fix it. You will need the Max 5 runtime stuff to use it. Download it here:
http://www.combatdave.com/code/midi2serial.mxf
hey man
thank you very much for this – it looks great. I have plugged everything into my laptop and am now trying to get the signal going into the arduino board, the midi2serial patch can recognise my midi controller (in this case an AKAI MPD24) however I am not sure what to do next in terms of getting this converted midi data into the arduino board, do I need to upload some patch onto it to listen out for data coming in from the midi2serial? where do I define what midi message controls which I/O? thanks again for your time, i really appreciate all your help with this project – can’t wait to upload a video of the organ in action – as I have just received the clear acrylic pipes for it.
warm regards
venya
@venya
Hey again. I’ve just finished testing this, so if you download this, it should contain everything you need:
http://www.combatdave.com/code/midi2serial.zip
In it is an updated Max patch, and a sketch to run on your Arduino.
To make the max patch work properly, you need to work from the top down – that is, firstly select your midi in, then select your serial port, and then check the box.
In the Arduino sketch I’ve made, I’ve tried to make it fairly simple for you. There’s a “noteOn” function, and a “noteOff” function. Both of these get an int passed to them, which is the midi note number. At the moment I just turn pin 13 (the onboard LED) on or off to demonstrate it’s working – but these functions are where you hook in your code.
Let me know how you get on!
hey
thanks man – this all looks great, i have managed to get some form of communication happening between my computer and the board. whenever i trigger a midi note the RX led lights up – which i figure means it is getting the data.
here is the patch that you sent me for the arduino – (to edit the midi key data)
void noteOnEvent(int note =’80′)
{
// your code here
digitalWrite(13, HIGH);
}
void noteOffEvent(int note =’00′)
{
// your code here
digitalWrite(13, LOW);
}
from what i understand that should trigger the LED on pin 13 when i press the midi key #80 and turn it of when i let go of it –
am i doing something wrong?
update – when I load the max patch, and press any key on my midi device pin 13 lights up – so that definatly works! which is good news.
Just trying to configure the arduino sketch to be able to map different keys to the different pins, appologies for my novice skills: once i open the sketch in arduino do i need to press the play button? to make it run in real time – or do i need to upload the sketch onto the board?
thanks again for all your help
i have managed to change the arduino sketch and upload it onto the board, so that now pin 12 lights up when midi data is received – however i am still stuck in terms of filtering the data i.e. midi key 23 to trigger pin 12 and midi key 45 to trigger pin 11
regards
venya
@venya
Awesome, I’m glad you’ve got everything working. For getting the specific pins to light, theres a couple of ways you could do it. I remember you said there will be 14 pipes in the organ – I assume each one is going to be either on or off. Do you want to map 14 midi notes so that only 14 keys will light the pipes, or do you want to have multiple keys lighting the same pipes?
If you let me know I could probably modify the Arduino sketch for you to get it to work roughly how you want.
hey – the plan is now to have 12 pipes (1 octave) – each one being controlled by and individual digital I/O pin – so ideally i would have 12 midi keys controlling 12 individual pipes (i guess if I wanted to control 2 lights with 1 pin I could just wire up the electrics accordingly).
thanks again for doing this – you should come over and see the show when it is ready!
@venya
Having 12 seems to make more sense!
Say for example your output pins are pin numbers 2-13 (12 pins). You can turn the incoming note number into a pin number by doing:
int startPin = 2;
int numPipes = 12;
int pinNumber = startPin + (noteNumber % numPipes);
digitalWrite(pinNumber, HIGH);
// or
digitalWrite(pinNumber, LOW);
This will work for any octave, which is nice. Hope it helps a little!
Where will the show be? You should get some videos!
hey man – thanks for that, quick question: Do I need to declare the noteNumber?
something like this:
int noteNumber = 23; – or how do I define a range to cover all the notes:
at the moment my code looks like this: but all I can do with it is light up pin 13 from any midi notes i press:
iint inputLength = 0;
char input [10];
int channel = 1;
int startPin = 2;
int numPipes = 12;
int noteNumber = 0-144;
int pinNumber = startPin + (noteNumber % numPipes);
void setup()
{
Serial.begin(115200);
Serial.println(“Ready”);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
}
void loop()
{
updateSerial();
delay(10);
}
// these functions get called when a note is turned on or off. the parameter is the midi note id
void noteOnEvent(int)
{
// your code here
digitalWrite(pinNumber, HIGH);
}
void noteOffEvent(int)
{
// your code here
digitalWrite(pinNumber, LOW);
}
// You shouldn’t (hah) need to worry about anything below here
void updateSerial()
{
if (Serial.available())
{
char ch = Serial.read();
input[inputLength] = ch;
inputLength++;
boolean finished = false;
if (inputLength > 2)
{
if ((input[inputLength-2]==’o') && (input[inputLength-1]==’n'))
{
Serial.println(input);
finished = true;
int note = getNoteNumber();
noteOnEvent(note);
}
else if ((input[inputLength-3]==’o') && (input[inputLength-2]==’f') && (input[inputLength-1]==’f'))
{
Serial.println(input);
finished = true;
int note = getNoteNumber();
noteOffEvent(note);
}
}
if (finished)
{
for (int i=0; i<10; i++)
{
input[i] = ”;
}
inputLength = 0;
}
}
}
int getNoteNumber()
{
int number = 0;
for (int i=0; i<inputLength; i++)
{
char ch = input[i];
if (ch == ‘-’)
{
return number;
}
else
{
number *= 10;
number += (ch – ‘0′);
}
}
return -1;
}
the show is going to be at this venue I run with some friends called the Kazimier:
http://www.thekazimier.co.uk
on the 27th of Feb – hoping to have the organ built by early next week so will get videos as soon as I can.
Heh, not quite. Take the original source from the zip and change the noteOn and noteOff functions into this:
void noteOnEvent(int)
{
int startPin = 2;
int numPipes = 12;
int pinNumber = startPin + (noteNumber % numPipes);
digitalWrite(pinNumber, HIGH);
}
void noteOffEvent(int)
{
int startPin = 2;
int numPipes = 12;
int pinNumber = startPin + (noteNumber % numPipes);
digitalWrite(pinNumber, LOW);
}
I hope you’ll be giving me a little credit for helping you out
Looking forward to seeing the vid!
hey man – sorry to keep bugging you especially since you have helped me out so much already, I just keep hitting a brick wall with this: I have done what you suggested in the post above but when I try to upload the patch onto the arduino board I get the following error message:
In function ‘void noteOnEvent(int)’:
error: ‘noteNumber’ was not declared in this scope In function ‘void noteOffEvent(int)’:
So I have been trying to define the noteNumber like this:
void noteOnEvent(int)
{
int startPin = 2;
int numPipes = 12;
int noteNumber = 0; noteNumber<128;
int pinNumber = startPin + (noteNumber % numPipes);
digitalWrite(pinNumber, HIGH);
}
void noteOffEvent(int)
{
int startPin = 2;
int numPipes = 12;
int noteNumber = 0;
int pinNumber = startPin + (noteNumber % numPipes);
digitalWrite(pinNumber, LOW);
}
but that doesn’t seem to do much, am I right in thinking that I have to define it as a number range? which part of the code would I need to define it in?
I will definatly credit you for all your help – you should come see it in action as without your help the project wouldn’t really get of the ground!
The functions should be:
void noteOnEvent(int noteNumber)
{
int startPin = 2;
int numPipes = 12;
int noteNumber = 0; noteNumber<128;
int pinNumber = startPin + (noteNumber % numPipes);
digitalWrite(pinNumber, HIGH);
}
void noteOffEvent(int noteNumber)
{
int startPin = 2;
int numPipes = 12;
int noteNumber = 0;
int pinNumber = startPin + (noteNumber % numPipes);
digitalWrite(pinNumber, LOW);
}
Note the variable name in the parameter! I think with this everything should be fine.
You don’t have to define it as a number range. This line does some magical stuff:
int pinNumber = startPin + (noteNumber % numPipes);
I don’t know if you’re aware of the mathematical “modulus” function, but thats what the “%” sign is. It takes noteNumber (which will be any note number from your keyboard, say 0 – 140), and then makes it “wrap” around the value in numPipes. So, with noteNumber counting from 0, and numPipes being 12, the output would be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, etc. Add the startPin value (which is 2 in this case), and hopefully you can see how noteNumber is converted into a value in the range of 2-13!
Anyway, this should sort you out. I’d love to come see it, but its a bit of a trek from Iceland
It works now!!
thanks again – I had to change the code slightly to this:
void noteOnEvent(int noteNumber)
{
int startPin = 2;
int numPipes = 12;
int pinNumber = startPin + (noteNumber % numPipes);
digitalWrite(pinNumber, HIGH);
}
void noteOffEvent(int noteNumber)
{
int startPin = 2;
int numPipes = 12;
int pinNumber = startPin + (noteNumber % numPipes);
digitalWrite(pinNumber, LOW);
}
because the following line:
int noteNumber = 0; noteNumber<128;
was coming up with an error message:
In function ‘void noteOnEvent(int)’:
error: declaration of ‘int noteNumber’ shadows a parameter
man – I am so glad to see these little LED’s light up!
I was wondering what the % symbol meant! been trying to google it but as you can imagine not getting the right kind of results – your explanation clears everything up for me.
Didn’t realise you lived in Iceland – to be honest over here in Liverpool we’ve got a lot of snow and my house doesn’t really have much heating going on as it is very very big and very very old – pretty much living in a freezer at the moment!
will keep you posted on the progress.
@venya
I’m glad you’ve got it all working! This Kazimier place – is it in Liverpool? Would you consider helping a friend of mine out in exchange for the help I have given you with this stuff? He’s pretty good at what he does – I’ve played a few gigs he’s organised and they’ve always been awesome. He’s a bit stuck for a venue at the moment. It’s all chiptune stuff (check out the video in my blog for an example if you’re not familiar), and I love it.
Let me know if you think you could help out. The pictures of your venue look awesome, so it would be perfect for this kind of thing.
Cheers.
hey man
could you send me a link to his material? I didn’t really know much about this chiptune scene! we organise very highly curated events at the Kazimier with all the performances specifically developed for the night. We are in the process of getting a full license so that we can put on more gigs and range of events and it would be ace to try and get your friend on.
I’ll keep you posted on any progress
Hello,
Awesome work! I want to do something very similar, but im not sure how. I want to send 6 pot signals to processing to be converted into midi, to be used in Ableton Live. I have all the hardware done, but im not sure how to code it. Could you please point me in the right direction?
Thanks,
Nigel
Hi
I’m about to build an arduinoboy and I’m wondering how this one is different to the more wired up version by trash-80
In the youtube vid you said “theres my arduinoboy” and all I see is the breadboard with like 3 wires so its blowing my mind
I also read you have schematics for it up but I can’t find em
really interesting stuff btw
I’m trying to sync with either renoise or ableton
@Nigel
Roughly what you want to do is send some sort of message from your arduino over serial to your pc, where an app will turn the messages into midi.
The messages from the arduino might look like “pot1:243″, and would be sent whenever the arduino detects a change in the reading of a pot. The app on your pc would recieve these messages and parse them, so when it sees “pot1″ it knows to use midi channel 1 to send out the value.
This can be done in processing pretty easily, but also through max/msp and stuff.
@Blake
This one is different because it cuts out all the midi stuff, and there is no button to select a mode, no status led etc. All it is is the wires from the link cable going straight into the arduino – thats why it looks so simple.
I should have the full version built soon, though!
http://www.facebook.com/v/76299952304
Hey I got mine working!
I’m still getting crazy errors in your processing app
The compiled version didnt load in windows so I just kinda messed around with the source till it ran. It works fine but the log gives a long list of errors like this:
http://img26.imageshack.us/img26/2484/errorsh.png
Do you think you could test it in windows? Thanks
It also seems to really bog down my cpu
@Blake
Nice one! Cute cat, too!
I’m not really sure what to suggest, I’m sure I remember seeing all that kind of stuff before… but I forget the details. Also, I’m not certain how this will run on other computers let alone other OSes due to the hacking I had to do of the midi library… I don’t have any way to test on windows at the moment, either.
If my trial license for max/msp is still working, I’ll try to do something which might be a bit more reliable in that sometime maybe. I’ll probably be building my full arduinoboy soon, though…
Hi,
I was very excited to find your serial to midi converter!!! Nice one mate!!!
so when i open the app it does not show a window at all nor can I find it as a midi device, am I totally missing something?
Cheers
OSX 10.5.7
Ableton Live 7.0.16
Arduino
@Pooks
Pooks, I’m not sure what’s happening if there is no window showing. It was written in the Processing language, and as such needs the Java runtime stuff – if you don’t have that, then you will need to get it. If you *do* have it, and it still isn’t working, then I’m not sure what is wrong… You’re using an almost identical setup to me, so that’s the only thing I can think of it being.
??????? ??, ??? ?????. ?????? ?????? ??????????. ??????? ? ????????? ? ???? ??????? ?? ??????????
Hi again
Ive been writing up a tutorial on how to build your arduinoboy version in class everyday and was just asking permission to post it to 8bc. I credit you and trash-80 at the top. Also can I use some of the information about it like some of the pics or videos?
thanks again
@combatdave
Yes, I’m having exactly the same problem. No GUI when launched, and not showing up as a MIDI device anywhere. Attempting to compile from source yields:
“File /var/folders/rV/rV2IBf-92RWGkE+BYupKTU+++TI/-Tmp-/build7039242127149051810.tmp/GenericSerial2Midi.java is specified more than once”
Any thoughts?
Thanks
OS X 10.6.2
Processing 1.0.7
Java version 1.6.0_17
?????? ?????, ???? ?? ??????? ? ??? ???????.
?? ??????, ????????????? ?????? ???????.
??????? ???????, ???? ???? ?????????.
???????? ????? ???????????, ???? ???????????? ? ??????.
????? ? ???? ? ???????????, ???? ?????? ????????????? ?????.
???? ???? ????????? ?????????? ?? ??????? ???????, ???????????.