The first one is SparkFun Mp3 Player Shield, it depends on the VS1053B MP3 audio decoder which is an IC to decode audio files.
You can buy the shield from here but it comes without pin headers, so I recommend to get the needed ones from here.
After getting them, now we are ready to start the tutorial.
Step 1: Adjust the shield
As the shield does not come with the pin headers, I assume to give the ability for makers to put it in PCBs, we have to get male-female pin headers and solder them to the shield using a soldering iron and solder.
Voila! That’s how it looks after soldering it.
Step 2: Mount the Mp3 Player shield on your Arduino board
In my case I am using an Arduino UNO board.
Step 3: Get an SD card
Get a micro SD card of any size and format it into FAT16 or FAT32. The default state of an SD card is to be formatted to one of them, but I recommend formatting it just in case.
Step 4: Add mp3 files
Now it’s time to add some mp3 files to the SD card, but you have to consider the following:
1- The added files must be added to the root of the SD card not in any sub folder.
2- Only 9 tracks can be added and with a dedicated names in the DOS format of 8.3; 8 for the characters and 3 for the extension. So you have to rename your tracks from track001.mp3 to track009.mp3. Although this is an extra step, it allows you to play a certain file with its name.
3- The mp3 files must be compressed into a certain bitrate which describes your audio file resolution.
Check the datasheet (beginning in section 8 on page 26), to make sure your audio files are supported.
SdFat library is the library responsible for dealing with fat files in the SD card.
After downloading the library, unzip the whole folder then you will find two folders having both the libraries, SFEMP3Shield and SdFat. Copy both folders into your Arduino libraries directory then close the Arduino IDE and reopen it again.
Step 6: Write the code
Write the code then upload it to your board, but you have to check the library first if you are not using the Arduino UNO board to check if the library is compatible with your board and if yes, you have to change some parameters in it and you can find all of that in the library documentation here.
If you faced any trouble with the code, you can visit Bill’s webpage which offers a lot of troubleshooting hints.
You have to initialize two functions one to initialize the SD card and the other to initialize the Music player
and then call them in your void setup after taking an object from both SdFat and SFEMP3Shield libraries
Then you have to check the order of the pressed switch and for every order play the corresponding track to it after stopping the whole music player and if you pressed the last ordered switch it will stop the music player.
MP3 Shield Trigger
by: Jim Lindblom
date: September 23, 2013
This is an example MP3 trigger sketch for the SparkFun MP3 Shield.
Pins 0, 1, 5, 10, A0, A1, A2, A3, and A4 are setup to trigger tracks
"track001.mp3", "track002.mp3", etc. on an SD card loaded into
the shield. Whenever any of those pins are shorted to ground,
their respective track will start playing.
When a new pin is triggered, any track currently playing will
stop, and the new one will start.
A5 is setup to globally STOP playing a track when triggered.
If you need more triggers, the shield's jumpers on pins 3 and 4
(MIDI-IN and GPIO1) can be cut open and used as additional
trigger pins. Also, because pins 0 and 1 are used as triggers
Serial is not available for debugging. Disable those as
triggers if you want to use serial.
Much of this code was grabbed from the FilePlayer example
included with the SFEMP3Shield library. Major thanks to Bill
Porter and Michael Flaga, again, for this amazing library!
lastTrigger=i+1;// Update lastTrigger variable to current trigger
/* If another track is playing, stop it: */
/* Use the playTrack function to play a numbered track: */
// An alternative here would be to use the
// playMP3(fileName) function, as long as you mapped
// the file names to trigger pins.
if(result==0)// playTrack() returns 0 on success
else// Otherwise there's an error, check the code
// Print error code somehow, someway
// After looping through and checking trigger pins, check to
// see if the stopPin (A5) is triggered.
lastTrigger=0;// Reset lastTrigger
// If another track is playing, stop it.
// initSD() initializes the SD card and checks for an error.
//Initialize the SdCard.
// initMP3Player() sets up all of the initialization for the
// MP3 Player Shield. It runs the begin() function, checks
// for errors, applies a patch if found, and sets the volume/
// stero mode.
uint8_tresult=MP3player.begin();// init the mp3 player shield
if(result!=0)// check result, see readme for error codes.
// Error checking can go here!
And as you see in the code which is written by Jim Lindblom, we are using 10 pins as 10 Push buttons (0,1,5,10, A0~A4) for playing the nine tracks in the SD card and the push button on A5 to stop the music player.
Since these are the only available pins for programming in the Arduino Uno, as the shield has reserved all the rest of the 10 pins, whether in the communication with the SD card or with the speaker, or even with the Arduino as you see in below picture.
Step 7: Setup the hardware
Connect the circuit as shown in the picture below. I’m not using any resistors as I am using the internal pull-up resistance in the code, so the push buttons are connected directly to the ground.
2- 1Sheeld Music Player Shield
Now, moving on to our super Arduino shield: 1Sheeld, accessing the music player shield.
For anyone who does not know about 1Sheeld, it is a board that connects your smartphones sensors and peripherals to the Arduino, allowing your smartphone to control Arduino and Arduino to control anything on your phone.
The most important thing in 1Sheeld, is that you can make a lot of amazing things with only 1 line of code!
So, here we are going to control the music player shield in your smartphone and we will show you how you can play music with only 1 command and how to stop it with another one.
The code here is using 3 push buttons one to play and the second to play the next track and the third one to stop the music player and to get more experienced with the music player shield you can check the shield documentation here.
You only need to initialize the communication in the void setup then you can play a track or the next one or stop it
with only 1 line of code for each operation.
Music Player Shield Example
This example shows an application on 1Sheeld's music player shield.
By using this example, you can play and pause music from
your smartphone or playing the next track using 3 hardware push buttons.
To reduce the library compiled size and limit its memory usage, you
can specify which shields you want to include in your sketch by
defining CUSTOM_SETTINGS and the shields respective INCLUDE_ define.
/* Include 1Sheeld library. */
/* A name for the button on pin 12. */
/* A name for the button on pin 11. */
/* A name for the button on pin 10. */
/* Start communication. */
/* Set the two buttons pins as input. */
/* Always check button 1 state. */
/* Turn on the music. */
/* Wait for 300 ms. */
/* Always check button 1 state. */
/* Turn on the music. */
/* Wait for 300 ms. */
/* Always check button 2 state. */
/* Turn off the music. */
/* Wait for 300 ms. */
After writing the code, make sure to set 1Sheeld UART switch to the upload mode before you upload your code on Arduino.
After uploading the code, the 1Sheeld is not ready to work until you switch it back to the operating-mode.
Operating mode is turned on when the UART switch is pushed towards 1Sheeld logo.
Step 6: Use the 1Sheeld application
Open 1Sheeld application on your Android phone or iOS device.
The application will first scan over bluetooth for your 1Sheeld, it will take a few seconds and the phone will find it.
Once it appears on your screen as 1Sheeld #xxxx, you will be required to enter the pairing code (the default pairing code is 1234) and connect to 1Sheeld via bluetooth.
Step 7: Access the shields
Select the shields you would like to use in your Arduino sketch (project) and press on the multiple shields icon at the top right of the app.
In this case, use Music Player shield.
Step 8: Add music to the application
Add as many mp3 files as you want!
Step 9: Setup the hardware
As we are using the internal pull-up in the code so we are connecting the push buttons to the ground.
Ever wanted to control things only with voice commands, like controlling your room lights or a robot kit? Then you are in the right place! I’m going to make a detailed comparison between our Voice Recognition Shield and the famous EasyVR3 Voice Recognition Shield. I will cover the getting started points for each one till you …
Most of us used to play video games using joystick either on PlayStation or PC. When I started tinkering with Arduino, when I built a robot or a vehicle, I also wanted to control it with a similar joystick, so I got the Sparkfun joystick shield. Today I will make a detailed comparison between our …
The newer version of 1Sheeld (1Sheeld+) built to support both iOS and Android devices,but not just that …! There’s another secret feature supported to solve the problem of using extra shield/board over 1Sheeld+, and this shield/board have the same way of communication used by 1Sheeld+ (The hardware UART serial pins pin0&pin1) with your Arduino. Exactly …
Ever wanted to talk to your Arduino project? Recently I watched this video of a Harry Potter magic wand that you can command to turn on lights and order food! Disclaimer: I’m not a Harry Potter fan, not a fan of Star Trek or Star Wars either! Total Game of Thrones nerd though, check out …
Too many times in the past I wanted to save my sensors’ readings in a file for future analysis, and I didn’t find an easy way till the data logger shields came up. One of the most reliable shields in the market is the Sparkfun data logger shield, and today I will make a detailed …
Making a tracking system is something that most of us wanted to have in our projects, and with all that modern technology offering us, it can be made very simply with our beloved board “Arduino” and a GPS shield. Today I will make a detailed comparison between our 1Sheeld GPS shield and the SparkFun GPS …