Nov.18

To convert MIDI files into Arduino sketches

The intention of this experiment to play MIDI tones by using Arduino. This is very easy with some resistors and one speaker.

The components which used are:

1. Arduino UNO

2. Three 470 Ohm Resistors

3. one speaker/buzzer

 

First thing we need to take some midi sound files .eg: http://www.midiworld.com/download/3826  This is James Bond movie tone.Next thing we need to convert it into Arduino Sketch. For that we need one special software called Miditones. Download latest MidiTones .exe file. This is a command line utility. create one folder and copy-paste Miditones.exe and .midi file which we downloaded earlier .

Nextstep is to convert MIDI file to Sketch.Run the below command from DOS prompt. CD to the new directory.

 

lmiditonesV1.6.exe -t3 Movie_Themes_-_James_Bond

 

Note that we need to give MIDI file name without .midi extension. the above command will generate Movie_Themes_-_James_Bond.c file on the same directory. Open this file on any texteditor, that will be our Arduino Sketch.

 

Next part is to install Playtune library to Arduino IDE. For that create a directory “Playtunes” under “C:\Program Files (x86)\Arduino\libraries“. Then download “Playtune.cpp & Playtune.h” and paste it into Playtunes directory.Now your IDE is able to process playtune library.

 

Next step is to wire the circuit. connect 470 Ohm resistors to 10,11 & 12 pins of Arduino and the other end of resistor connect together . Take one wire from GND , connect to one speaker lead and the other lead connect to resistor .I am not going to show the circuit as this is very simple to wire.

 

Next part is coding. Open Arduino IDE and paste below code.

 

 

#include <Playtune.h>

 

//copy paste content of converted midi file here.ie: Movie_Themes_-_James_Bond.c

 

Playtune pt;

void setup() {
pt.tune_initchan (10);
pt.tune_initchan (11);
pt.tune_initchan (12);
}

void loop () {
pt.tune_playscore (score); /* start playing */
while (pt.tune_playing) ; /* wait here until playing stops */
}

 

replace the second line with output of .c file from miditones and upload to Arduino. That’s it.

 

Share this Story:
  • facebook
  • twitter
  • gplus

About bentech4u

Comments(16)

  1. xargs
    1799 days ago

    Nice to see this. Very useful. All the info in one place

  2. Dedicated server
    1309 days ago

    Is it possible to play midi files with the arduino and a speaker? If so, how would I go about doing it?

  3. bentech4u
    1308 days ago

    HI,

    yes it’s possible and connection method also i mentioned above.


    connect 470 Ohm resistors to 10,11 & 12 pins of Arduino….

  4. Luis
    1272 days ago

    i already cd to my folder and try to use the command but it says that “lmiditonesV1.6.exe”
    isn’t an internal or external command….what should i do?

  5. Jacob Jarick
    1167 days ago

    Hello, thanks for the guide.

    To ensure this works with Arduino 1.6.X edit playtune.cpp
    change:
    #include

    to :
    #include “arduino.h”

  6. bentech4u
    1162 days ago

    HI

    thanks for your update

  7. bentech4u
    1162 days ago

    @Luis

    please check the programe name you entered

  8. TheUltimateAbsol
    1151 days ago

    I got this error:
    MIDI:7: error: variable ‘score’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’

  9. kjoelby
    1151 days ago

    Sweet, nice simplified instructions, thanks for posting this!
    Author Len Shustek’s github page has compatible vs for Arduino IDE 1.6:
    https://github.com/LenShustek/arduino-playtune

  10. bentech4u
    1150 days ago

    HI kjoelby

    Thanks for your update.

    Regards,
    Ben

  11. Smithc775
    913 days ago

    Totally pent subject matter, appreciate it for selective information. kddcbbbdgecaddbg

  12. Braiden
    830 days ago

    @bentech4u
    I followed the link you gave @TheUltimateAbsol, and I still can’t figure out how to get it to compile. Please update your guide or leave a reply

  13. Teleputer
    724 days ago

    Your Technically a System Engineer but your Systematically a technical Engineer =)

  14. praveen kumar r
    671 days ago

    Can you please guide how to create midi file of my custom mp3 file.I have tried with lot of tools.Can you suggest me few more?

    • david
      306 days ago

      hi, there is no actual way to do that since a midi file are just note and a mp3 file is audio, i would recommend you check out musescore.com , there is a huge collection of midis

Leave a Reply to david Cancel reply