Today I will make a detailed comparison between our Music Player Shield in 1Sheeld, and SparkFun Mp3 Player Shield.
I will cover the getting started points for each one, till you can play and pause music using both of them, and I’ve summarized the points of comparison between both shields in the table below:
P.O.C
SparkFun Mp3 Player shield
1Sheeld Music Player shield
Length of code
233 lines
124 lines
Code memory size
16KB
7KB
No. of libraries
4
1
Max no. of tracks
9
As many as your smartphone can handle
File names
DOS 8.3 format (track001~track009)
Any file name
Files must be in root
Yes
No
Call a certain track
Yes
No
Complexity
Many functions built to make certain operation
obj.isPlaying()
obj.stopTrack()
obj.playTrack()
the object is taken from the library after initializing it.
If you want to make more actions you have to build it’s own function
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.
There are 4 libraries used to operate the Mp3 Player shield:
1- SPI : This library is already found in your IDE and used for the communication between SDcard and the Arduino.
2- SdFat : This library used to be able to deal with files in Fat format in the SD card.
3- SdFatUtil : This is an extra library added to the SdFat library.
4- SFEMP3Shield : This library simplifies the task of interfacing with the VS1053 and using the MP3 Player Shield.
Download SFEMP3Shield Arduino library, it is written by Bill Porter and it’s an amazing library for that shield and combined with the SdFat library which also included in the Github folder.
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.
Code: –
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.
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
MP3 Shield Trigger
by: Jim Lindblom
SparkFun Electronics
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: */
if(MP3player.isPlaying())
MP3player.stopTrack();
/* Use the playTrack function to play a numbered track: */
uint8_tresult=MP3player.playTrack(lastTrigger);
// 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
{
// 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.
if(digitalRead(stopPin)==LOW)
{
lastTrigger=0;// Reset lastTrigger
// If another track is playing, stop it.
if(MP3player.isPlaying())
MP3player.stopTrack();
}
}
// initSD() initializes the SD card and checks for an error.
voidinitSD()
{
//Initialize the SdCard.
if(!sd.begin(SD_SEL,SPI_HALF_SPEED))
sd.initErrorHalt();
if(!sd.chdir("/"))
sd.errorHalt("sd.chdir");
}
// 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.
voidinitMP3Player()
{
uint8_tresult=MP3player.begin();// init the mp3 player shield
if(result!=0)// check result, see readme for error codes.
{
// Error checking can go here!
}
MP3player.setVolume(volume,volume);
MP3player.setMonoMode(monoMode);
}
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.
code:-
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.
Arduino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
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.
OPTIONAL:
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.
*/
#define CUSTOM_SETTINGS
#define INCLUDE_MUSIC_PLAYER_SHIELD
/* Include 1Sheeld library. */
#include <OneSheeld.h>
/* A name for the button on pin 12. */
intbuttonPin1=12;
/* A name for the button on pin 11. */
intbuttonPin2=11;
/* A name for the button on pin 10. */
intbuttonPin3=10;
voidsetup()
{
/* Start communication. */
OneSheeld.begin();
/* Set the two buttons pins as input. */
pinMode(buttonPin1,INPUT_PULLUP);
pinMode(buttonPin2,INPUT_PULLUP);
pinMode(buttonPin3,INPUT_PULLUP);
}
voidloop()
{
/* Always check button 1 state. */
if(digitalRead(buttonPin1)==HIGH)
{
/* Turn on the music. */
MusicPlayer.play();
/* Wait for 300 ms. */
OneSheeld.delay(300);
}
/* Always check button 1 state. */
if(digitalRead(buttonPin2)==HIGH)
{
/* Turn on the music. */
MusicPlayer.next();
/* Wait for 300 ms. */
OneSheeld.delay(300);
}
/* Always check button 2 state. */
if(digitalRead(buttonPin3)==HIGH)
{
/* Turn off the music. */
MusicPlayer.pause();
/* Wait for 300 ms. */
OneSheeld.delay(300);
}
}
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.
Arduino Security Camera Have you ever wanted to check your home in real time? Afraid that maybe someone has stormed in, don’t remember if you shut the door or not or maybe wanna check if your Hyper-energetic dog has broken any of your dishes AGAIN!! 🙂 Then this is the perfect place for you cause today …
Arduino makers …. you can connect your Arduino to MQTT brokers(servers) and launch your IoT with Arduino IoT Shield! It’s the 1Sheeld IoT shield that will do the job for you. It’s one of the most important but recent Arduino shields in 1Sheeld. Simply, it turns your Arduino into MQTT client where you can publish and …
Monitor my home environmental parameters remotely is one of the most desirable things I have ever wanted to make. It’s not about purchasing such a system that can get the job done for me. But, passion to create it myself. So, today, I am going to connect the popular DHT sensor to an online MQTT …
“Oh God! … It seems like I have forgotten the door lock open, again” … the normal saying whenever I am in hurry to go out! Have you encountered this problem before? It always confuses me since I may even think that I have left the door lock opened, and once I go back, …
Here I am with another IoT-based home automation project; Arduino IoT Fan Control. Every day, I get back from work tired and feeling hot. No air conditioner here and the fan takes much time to start cooling the room, sadly! So, I was thinking why not controlling the fan from outside my home with my …
Have you ever forgotten to turn your home lights off when you got outside? Sadly, it happens to me all the time. And this causes confusion once I get my bills! Furthermore, here is one secret about me; I am a lazy man. I always want to control my room lamp from my sweet bed. …