3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.


Antique Light Bulb Organ - MIDI/OSC Controlled

Step 11Software - Microcontroller firmware

Although the Atmega324p isn't probably the most widely used microcontroller (uC), most of this code will work just fine on the more popular atmega168 series that is used on arduinos.  The only major modification would be the implementation of a software UART for the MIDI port since the 168 series only has one UART.  However, that feature could easily be left out, as I have to admit, I've never plugged a device in directly through MIDI ever since I finished testing that it worked.

The firmware on the uC is setup to handle either input from the MIDI port, the USB port, or both simultaneously.  Switching between modes determines the routing of the messages.  In addition, the home note can be set either remotely or locally using the front pushbutton switch.  When the switch is pressed, the next note pressed and released on the keyboard will set the first light bulb to be that note.  This obviously isn't a necessity, however, I find people are a little less mystified as to what the lights are doing if they see the light bulbs light up in sequence from left to right.  When the root note of the key your playing in is the first light bulb, the lights tend to jump around a little less erratically, depending on what you're playing of course.  The nice thing is that since this can be controlled remotely, it's easy to set the key of your song so that it automatically updates every time you switch tracks (see the last section on the max4live object using ableton).

When the mode of the unit is switched, the front led lights up a different color, indicating whether the local user has control or whether it is remotely controlled.  This goes in the pretty much useless but looks cool category.

The majority of the software is setup to handle the incoming messages (midi/usb).  The external crystal drives the uC at 18.423MHz, in order to get 0% error at 115200 baud rate.  Aside from going line by line through the code there's not much more to talk about, feel free to ask any questions you have, the codes provided below.  The zip file has the entire project inlcluding the avrstudio file (avrstudio5, I recently upgraded and converted all my old projects, you should too! its so much better than avrstudio4!).  I left out the individual UART files since they are readily available elsewhere.

Some helpful points when writing for midi.  You'll need a UART clock of 31250 baud, which means, for a 0% error, you need a crystal with an integer multiple of that.  That works out okay though, since the built in 8Mhz works fine, or 16Mhz, etc.  However, a problem arises when combining MIDI UART on the same chip as RS232 UART.  The "standard" baud rates, 9600, 112500 etc, don't work well with 8Mhz crystals.  So, what to do....well there's two choices IMHO.

1.  Use the built-in crystal or similiar frequency (8Mhz...or 16Mhz, 20Mhz etc) and use baud-rate aliasing to correct for the usb.

2.  Accept error on one of your lines.  Personally, I don't like this option, I know a lot of people run things at 9600 baud with 16Mhz crystals, but I don't like to.

So, here's a bunch of links to aliasing the baud rate using the FT232R driver.  I have done this on a PC and a MAC, it works great, and allows you to send data at much much higher transmission rates than RS232 was meant for.  For example, instead of peaking at 225kbps, you can go all the way up to 3Mbps (although most atmegas can only do 2Mbps).

How to do it on OSX (follow the steps very carefully, it does actually work, I promise)
And, on a PC
Great article on aliasing the baud rate for using xbee controllers for midi (PC only)

Also, you're going to want to reference this page if you're writing any code for dealing with MIDI messages
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
5
Followers
1
Author:capricorn1(capricorn one)