Store MIDI files on an SD Card and utilize an SD shield connected to your Arduino to play these songs on a MIDI device.
This project illustrates the creation of an Arduino-based MIDI player. The Arduino is linked to a DS1307 Data Logger Shield equipped with an SD Card reader. It generates a MIDI stream from a MIDI file stored on the SD card within the Data Logger Shield. You can then connect this MIDI stream to any MIDI synthesizer or device capable of playing the music.
– DS1307 Data Logger Shield
– Printed Circuit Board (PCB) Mounted MIDI Female DIN5 Jack
– MC74HC14A Hex Schmitt-Trigger Inverter
– Two 220 Ohm Resistors
– Push Button
– MIDI Cable
Step 1: DS1307 Data Logger Shield
This Arduino shield is readily available from various sources, including Amazon, eBay, and AliExpress.
An informative overview of version 2 of this shield can be found on Adafruit’s website:
The shield used in this project is version 1 and differs from the one described by Adafruit. However, it’s important to note that all the provided code and examples are compatible with version 1.
The DS1307 serves as a Real Time Clock chip, ensuring precise timekeeping. It can operate with a battery backup, preventing time loss even when power to surrounding circuits is turned off.
In this project, the data logger shield is equipped with both a DS1307 and an SD card reader. The primary purpose of this shield is to log data from sensors with an accurate timestamp attached to each reading. This information is stored on an SD card and can be retrieved for analysis at any time.
For this specific project, we are only utilizing the SD card reader and not the DS1307 capabilities (apologies for any confusion).
Here are some noteworthy features of the shield:
1. The shield includes a prototyping area, which can be handy for future expansion.
2. The Arduino headers are accessible on the shield, allowing you to connect wires by soldering them to the holes adjacent to the header.
3. The shield features two built-in LEDs with accompanying resistors, making it convenient for your circuit to connect to them via the designated wiring points.
4. Please be aware that the Chip Select (CS) for the SD card reader is linked to Arduino pin 10 for this particular shield.
5. The Arduino communicates with the SD card using the SPI interface, and the pin assignments are illustrated in the provided picture.
Before connecting the shield, it’s essential to confirm that the SD card is operational by following these steps:
1. Format an SD card on your computer, ensuring it is formatted as FAT32 (or FAT16 if you prefer older standards).
2. Copy a few files to the SD card, but be mindful that due to the reader’s limitations, file names cannot exceed 8 characters, and file extensions should have a maximum of 3 characters (keeping in mind the old MS-DOS format).
3. The Arduino IDE typically comes with the SD library preinstalled. You can check for it under File → Examples → SD. If it’s not available, you can install the library.
4. Attach the shield to your Arduino and insert the SD card. Upload the “listfiles” program and run it. If everything is functioning correctly, the serial monitor should display a list of all the files on the SD card.
Step 2: MC74HC14A Hex Schmitt-Trigger Inverter
Step 3: The Circuit
Take a look at the circuit’s schematic.
The schematic doesn’t depict the essential 5V power and ground connections required for the MC74HC14 chip. These connections should be established by linking 5V to pin 14 and connecting Ground to pin 7.
The shield includes two LEDs and corresponding resistors. To utilize these components, connect Arduino Pin 5 to L1 and Pin 6 to L2 using the through holes on the shield.
The MIDI stream is transmitted from the TX pin of the Arduino, which is typically linked to pin 1 on an Arduino board by default. In the program, MIDI commands are sent using the Serial.write command to pin 1 and subsequently to the MIDI output circuit.
Step 4: Wire Up the Shield
The circuit, as illustrated, is connected within the prototype section of the shield. This may demand precision, but it can be achieved. You can view images of the fully assembled shield for reference.
Alternatively, you have the option to build the circuit on a solderless breadboard. For detailed guidance on this method, you can consult an article available at www.midi.org.
Step 5: Add Libraries
To ensure the code functions properly, it’s necessary to install the following libraries:
1. SdFat (a library for SD Card access)
2. MD_MIDIFile (a library for playing MIDI files from the SD Card)
You can easily install these libraries by navigating to Tools → Manage Libraries.
For comprehensive documentation on the MIDI library, you can refer to the following two links:
1. GitHub repository: https://github.com/MajicDesigns/MD_MIDIFile
2. Online documentation: https://majicdesigns.github.io/MD_MIDIFile/
Additionally, the GitHub repository contains various example files that provide a clear understanding of how the library operates. It also includes some sample MIDI files for reference.
Step 6: Play MIDI File
To play a MIDI file, follow these steps:
1. Load a MIDI file onto the properly formatted SD card. The file name must not exceed eight characters, followed by the “.mid” extension.
2. Open the “MinimalMidiPlayer” sketch in the Arduino IDE.
3. Inside the Arduino sketch, modify the declaration line [const char *loopfile = “LOOPDEMO.MID”] to specify the file located on the SD card.
4. Ensure that SD_SELECT is set to 10.
5. Upload the sketch to the Arduino.
6. Disconnect the Arduino from its power source.
7. Insert the SD card into the reader.
8. Connect the MIDI output jack to a synthesizer or MIDI player using a MIDI cable.
9. Power the Arduino by connecting it to an external power source. Avoid using the USB connector for power, as it may not supply enough power for both the shield and Arduino. Instead, use a power source connected to the DC in jack on the Arduino.
10. Press the button on the shield, and the song will start playing. Success!
Step 7: Play Multiple MIDI Files
To enhance the capabilities of this basic MIDI player, you can now play multiple songs from the SD Card. Follow these instructions:
1. Load several MIDI files onto the SD Card. Ensure that all files are placed in the root directory; files in subfolders won’t be playable. File names should not exceed eight characters and must be followed by the “.mid” extension.
2. Open the “MultiTrackMidiPlayer” sketch in the Arduino IDE. You can adjust the delay (located around line 82) to set the length of pauses between songs to your preference.
3. Confirm that the value of SD_SELECT is set to 10.
4. Upload the sketch to your Arduino.
5. Disconnect the Arduino from its power source.
6. Insert the SD card into the card reader.
7. Connect the MIDI output jack to a synthesizer or MIDI player using a MIDI cable.
8. Power the Arduino by connecting it to a power source. Avoid using the USB connector for power, as it may not provide sufficient power for both the shield and the Arduino. Instead, use a power source connected to the DC in jack on the Arduino.
9. Press the button on the shield, and the songs will play sequentially until all the songs have been played. Success!