Home » Projects » Stepper Motor Music [on hold]

Stepper Motor Music [on hold]

Time to report in with a fun little project (sort of). I saw this some time ago:

It’s very cool, and I enjoyed it immensely so because I am not very musically inclined, however much I’d like to be. There is almost a…genre of this kind of music, and it’s a lot of fun to listen and watch:

It should be noted the creator of the first video also wrote the score. This seems a great hassle to me, so I wanted this to be able to be supplied an already created score. There isn’t a whole lot of detail about the project, so I set out to recreate the project, which I thought would be a fun project to occupy me for a few days this summer, a week tops. For the record I started this about a month ago, and it still remains unfinished :[ due to a combination of some missing resources, and time (seriously, I was looking forward to playing so many videogame melodies). It’s sadly gathering dust right now and I’ve to pack it away for the moment, but before I do, I’m going to write down all my thoughts about it, so that I, and even anybody else, can hopefully finish it.

2014-07-25 22.23.26(the current state of the project)

So let’s get into it:

What you’ll need:

– Stepper motors, this is your “instrument”. The ones pictured above are SM42BYG011 and two SY35ST28. Simply because I had them on hand.

– Drivers. The ones used above are all DRV8825’s (http://www.pololu.com/product/2133). The datasheet also suggests putting some decoupling capacitors across the power source (at least 47uF)

– An MCU of your choice. The creator of the video from which I am drawing inspiration from is using an Arduino, but I decided to use an MSP430 launchpad, simply to double this as an exercise for learning how to program MSP430s, and that I had one lying around.

How it works:

– MIDI: (ripped straight from wikipedia) short for Musical Instrument Digital Interface, is a technical standard that describes a protocol, digital interfaceand connectors and allows a wide variety of electronic musical instruments, computers and other related devices to connect and communicate with one another.[1]

A MIDI device is essentially what we’re creating. We’re going to start with a .mid file containing music that we’d like to play, and decode it’s information to get which note to play, for how long, and which channel (instrument, steppers in this case). Another reason this project looked so attractive is because I knew this to be done already, thanks to miditones created by Len Shustek: https://code.google.com/p/miditones/. His code takes a .mid file, and generates an array of integers that will specify the start of a particular note on any one of up to 8 channels, the end of that note, and any delays that needs to be implemented inbetween. The specifiers are explained in the source code. Here’s what I get when I run it on Daft Punk’s Get Lucky (gotten from here http://www.free-midi.org/song/daft_punk-get_lucky_ft_pharrell_williams.html):

char score[] = {
0,50, 0x90,31, 1,194, 0x80, 0x90,31, 1,244, 0x80, 0x90,31, 1,244, 0x80, 0x90,31, 1,244,
0x80, 0x90,50, 0x91,66, 0x92,62, 0x93,59, 0x94,35, 0x95,35, 0,26, 0x80, 0,98, 0x90,50, 0,26, ...

So this says to 1) delay for 50ms 2) start playing note 31* on channel 0 3) delay for 194ms 4) stop playing on channel 0…and so on. As the most musically challenged person the planet, it couldn’t be clearer if it was spelled out for me.

*Various charts of how midi notes are commonly corresponded to musical frequencies are available, ex: http://www.phys.unsw.edu.au/jw/notes.html

– The steppers: if you have no knowledge of stepper motor operation…well it actually won’t hurt you very much if you do buy the driver listed above, or a similar one (but you should still take a moment to read up on it, it’s fascinating). What you need to know is that stepper motors move in series of “steps”. This mechanical motion is audible, so you can “play music” by making the motor move a certain number of steps per second. For example, if I excite the motor 261-262 times per second, I am approximately playing middle C. The driver make this simple because there is only one connection between the stepper and driver that you need to worry about, and that is the “step” input. This input on the driver accepts a series of pulses, and will increment the stepper one step per pulse.

General program flow:

Well, obviously this part isn’t working, or I’d be posting about a completed project right now…I thought it would be straightforward (and maybe it actually is, but I’ll discuss the problem in a moment).

– A main loop keeps a pointer to the current “action” specified by the output array of miditones, and controls several flags that sets whether the system is currently playing music and/or delaying, and changes the notes directed to each channel.

– An ISR (or several) is used for timing so that delays can be implemented properly, as well as sending pulses to the steppers.

Issues:

So why aren’t I done?

Actually, I might be. So one obstacle I’m running into is that I don’t have enough physical channels to play all the music I want to. miditones analyzes the .mid files and outputs information on up to 8 channels, but I only have 3 steppers. Have I tried playing with only 3 channels? Yes, and it definitely sounds incomplete, and very disappointing. If I could just borrow some steppers, maybe this project can come out of project purgatory.

With that said, if anybody should like to try to complete this project, leave a comment or send me an email and I’ll send the source code.

Leave a Reply

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

WordPress.com Logo

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

Facebook photo

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

Connecting to %s