NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Receiving MIDI Signals

January 01, 2011
by gomusicstl
gomusicstl's Avatar

I just got my NerdKit the other day and worked through the first few projects, and a couple of my own... very interesting and informative so far-- I'm hooked!

That said, I decided to get in over my head quickly. Can anyone point me in the right direction as to how to make the MCU receive MIDI information?

I understand that MIDI information is sent serially in 3-byte chunks: a status byte and then two data bytes. How do I get my MCU to receive those bytes with an interrupt? How could I say, write their component bits to the LCD? For the time being, I would be thrilled if I could press a key on MIDI keyboard and make an LED light up on the breadboard.

Any thoughts? I'm relearning C, too, so really any information at all will be helpful, especially if explained in one-syllable words.

Thanks in advance! Joel @ GoMusicSTL

January 02, 2011
by Rick_S
Rick_S's Avatar

The easiest way I could think of would be to get one of THE MIDI BREAKOUT BOARDS from sparkfun. The programming would be up to you, but if you are familiar with C (I assume you are since you said you are "relearning" it), you should be able to look at the provided arduino sketch on their website to get a good idea of how to make it all work.

I think this would be a neat project and have thought of messing around with MIDI myself for a while. My thoughts were along the line of creating a player piano. Let us know how it goes!!

Rick

January 02, 2011
by gomusicstl
gomusicstl's Avatar

Thanks for the info, Rick. I had looked at several of the Arduino boards, and they had piqued my interest, but I haven't picked any up yet.

I think I have the circuit design aspect under control. It's the programming that's a bit over my head at this point... using the MCU's UART to receive external information from a MIDI device is what I'm struggling with-- it's totally new to me. If I'm correct, I need to write a program that:

1) sets up the UART on the MCU (matching the MIDI data rate, setting the baud, etc., are things I don't quite understand yet)

2) sets an input pin to receive info from the MIDI device for the UART to handle

3) use a loop (or interrupt?) to collect bits continually in series from the MIDI device

4) have the MCU act on that info

5) reset the variable holding the MIDI bits and start collecting again

Is this anything like the right idea?

How far are you along on the player piano, Rick? Sounds like a great project! I was at a Steinway store around Christmas and they wanted $30k for a cheapy MIDI player piano... sounds like you stand to save a bundle if you can make it work.

j

January 02, 2011
by Rick_S
Rick_S's Avatar

I haven't even started the project... It's just one of those many ideas for projects that I've had.

January 15, 2011
by keithka
keithka's Avatar

Joel - I think you have the right general idea, but step 3 is a bit easier than you made it sound. Part of the UART's job is to buffer up some number of bytes as they come in from the MIDI cable, so your code in the MCU can grab it in chunks as it's convenient. You don't have to write a loop that runs a just the right speed to catch each bit. It'd be pretty hard to make that loop work for something like MIDI that's synchronous and doesn't have any notion of retrying if a message doesn't get delivered.

As an aside, I write software for a living today, and I got my first real coding job 18 years ago mostly because I showed up for the interview with a working MIDI sequencer on a floppy. I was too cheap to buy CakeWalk, and it wasn't exactly what I wanted anyway. Good times with MIDI...

January 15, 2011
by gomusicstl
gomusicstl's Avatar

Thanks for the information! It syncs up with other things I've read. That said, I've since gotten the thing to receive bytes, but my MIDI (FL Studio MIDI OUT from a Tascam 122 interface and a Korg MicroX), both send me nothing but byte 240, the MIDI 'System Exclusive' message. Any idea why that seems to be the only thing I'm getting? Alternatively, is there a way to convert the output of something like FL Studio to general MIDI note on and note off messages?

Thanks!

j

January 15, 2011
by keithka
keithka's Avatar

SysEx only, huh? Weird. I wonder if the MIDI sources you mentioned are fancier than what you want, and maybe a plain vanilla keyboard would send more normal MIDI messages. I almost said to hit garage sales or Craigslist, but it looks like you have your own music store, so finding another keyboard shouldn't be a problem.

The most frequent variation from the official MIDI spec that I experienced way back in the day was that almost nothing sent the note off message (was it 0x90?), they just sent a note on (maybe 0x80 - did I mention this was a long time ago <g>) with a velocity of zero. I wonder if sending nothing but SysEx is some USB->MIDI translation oddity.

January 15, 2011
by Hexorg
Hexorg's Avatar

I never dealt with MIDI protocol, but I found here that after transmitting SysEx, it transmits the message itself. What kind of message are you getting?

May 03, 2012
by HexManiac
HexManiac's Avatar

Midi command and data bytes can be distinguished by checking the msb: 1 = command, 0 = data.

Post a Reply

Please log in to post a reply.

Did you know that the sparks present in motors can be dangerous for your microcontroller and other electronics? Learn more...