Skip to content

Commit 45b7d0c

Browse files
committed
Initial commit
0 parents  commit 45b7d0c

File tree

10 files changed

+1085
-0
lines changed

10 files changed

+1085
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
Binary file not shown.

ISSUE_TEMPLATE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### Subject of the issue
2+
Describe your issue here.
3+
4+
### Your workbench
5+
* What platform are you using?
6+
* What version of the device are you using? Is there a firmware version?
7+
* How is the device wired to your platform?
8+
* How is everything being powered?
9+
* Are there any additional details that may help us help you?
10+
11+
### Steps to reproduce
12+
Tell us how to reproduce this issue. Please post stripped down example code demonstrating your issue to a gist.
13+
14+
### Expected behaviour
15+
Tell us what should happen
16+
17+
### Actual behaviour
18+
Tell us what happens instead

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
SparkFun WT2003S MP3 Decoder Arduino Library
2+
========================================
3+
4+
![SparkFun WT2003S MP3 Decoder](https://cdn.sparkfun.com/assets/parts/1/3/0/7/7/14810-MP3_Breakout_WT2003S-01.jpg)
5+
6+
[*SparkFun WT2003S MP3 Decoder (SPX-14810)*](https://www.sparkfun.com/products/14810)
7+
8+
This library provides full access to the functions of the WT2003S MP3 decoder through a serial connection and a "busy" pin. This library is very simple to use with either a hardware or software serial port. The simple dependencies (HardwareSerial and SoftwareSerial) make it suitable for use on any Arduino-compatible platform.
9+
10+
The WT2003S combines two functions needed to play .mp3 files into one package and adds a simple serial control interface. Normally to play a .mp3 file one would need to choose a decoder IC AND provide a method for storing and selecting the files. The WT2003S removes that complexity by combining an SD card interface and .mp3 decoder. Now in order to play a song all you need to do is save it to an SD card, plug it into the WT2003S breakout, and send a few commands over serial. This allows you to easily integrate sound into any Arduino project.
11+
12+
This library is intended for use with the [WT2003S MP3 Decoder Breakout board](https://www.sparkfun.com/products/14810), as opposed to another option employing the WT2003S -- the [Qwiic MP3 Trigger](https://www.sparkfun.com/products/14808). In case you are wondering which to use here is a little breakdown: If you want direct access to the WT2003S IC for complete control *and* you have a spare serial port (Hardware or Software) in your project then the Breakout board is good for you. If your project is running low on pins and you already use the I2C bus, or you want to trigger .mp3s without even using an external microcontroller then the Qwiic MP3 Trigger is right for you!
13+
14+
Repository Contents
15+
-------------------
16+
17+
* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
18+
* **/src** - Source files for the library (.cpp, .h).
19+
* **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
20+
* **library.properties** - General library properties for the Arduino package manager.
21+
22+
Documentation
23+
--------------
24+
25+
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
26+
27+
Products that use this Library
28+
---------------------------------
29+
30+
* [SPX-14810](https://www.sparkfun.com/products/14810) - SparkX version
31+
32+
Version History
33+
---------------
34+
* [V 1.0.0](https://github.com/sparkfun/SparkFun_WT2003S_MP3_Decoder_Arduino_Library/releases/tag/1.0.0) - Initial release
35+
36+
37+
License Information
38+
-------------------
39+
40+
This product is _**open source**_!
41+
42+
The **code** is released under the GPL v3 license. See the included LICENSE.md for more information.
43+
44+
Distributed as-is; no warranty is given.
45+
46+
- Your friends at SparkFun.
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
/*
2+
WT2003 S Example1_Terminal_MP3_Player
3+
4+
This example makes an MP3 player that can be controlled from the terminal window on a computer.
5+
It exposes the full set of commands that are available for the WT2003S
6+
7+
Using the WT2003S MP3 Decoder IC on the SparkFun breakout board with Arduino Uno
8+
By: Owen Lyke, Tina Tenbergen
9+
SparkFun Electronics
10+
Date: July 5th 2018, Aug 9 2018
11+
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
12+
13+
Feel like supporting our work? Buy a board from SparkFun!
14+
https://www.sparkfun.com/products/14810
15+
16+
Hardware Connections:
17+
WT2003S Breakout Pin ---> Arduino Pin
18+
-------------------------------------
19+
TXO ---> 2
20+
RXI ---> 3
21+
5V ---> 5V
22+
GND ---> GND
23+
BUSY ---> 7 (Optional)
24+
25+
Don't forget to load some MP3s on your sdCard and plug it in too!
26+
*/
27+
28+
#include "SparkFun_WT2003S_MP3_Decoder.h" // Click here to get the library: http://librarymanager/All#SparkFun_WT2003S
29+
30+
// Defining some status codes from the WT2003S
31+
#define STATUS_PLAY 0x01
32+
#define STATUS_STOP 0x02
33+
#define STATUS_PAUSE 0x03
34+
35+
#define songNameGetDelay 500 // ms
36+
37+
SoftwareSerial mp3_sws(2,3); // Use software serial so that the Arduino hardware serial can be used for control commands
38+
39+
WT2003S MP3; // Create an object of the WT2003S class called MP3
40+
41+
void setup() {
42+
Serial.begin(9600);
43+
while(!Serial){};
44+
MP3.begin(mp3_sws); // Beginning the MP3 player requires a serial port (either hardware or software!!!)
45+
46+
Serial.println("MP3 Breakout - Example1 Serial Control");
47+
Serial.println();
48+
49+
printMenu();
50+
51+
Serial.print("Number of tracks on SD card: ");
52+
Serial.println(MP3.getSongCount());
53+
54+
if(MP3.getSongCount() == 0)
55+
{
56+
Serial.println("Oh no! No songs found... try adding songs or plugging in the sd card then try again");
57+
while(1); // Hold here
58+
}
59+
60+
MP3.setVolume(4);
61+
}
62+
63+
void loop() {
64+
if(Serial.available())
65+
{
66+
char cmd = Serial.read();
67+
if(cmd == '+')
68+
{
69+
Serial.print("Volume up: ");
70+
uint8_t volume = MP3.getVolume();
71+
MP3.setVolume(++volume);
72+
Serial.print(volume);
73+
Serial.println("/31");
74+
}
75+
else if(cmd == '-')
76+
{
77+
Serial.print("Volume down: ");
78+
uint8_t volume = MP3.getVolume();
79+
if(--volume > 31)
80+
{
81+
volume = 0;
82+
}
83+
MP3.setVolume(volume);
84+
Serial.print(volume);
85+
Serial.println("/31");
86+
}
87+
else if(cmd == 'n')
88+
{
89+
Serial.println("Next track:");
90+
MP3.playNext();
91+
delay(songNameGetDelay); // It takes a moment for the device to start playing the next song
92+
MP3.getSongName();
93+
Serial.print("Playing: ");
94+
Serial.write(MP3.songName, 8);
95+
Serial.println();
96+
}
97+
else if(cmd == 'l')
98+
{
99+
Serial.println("Last track:");
100+
MP3.playPrevious();
101+
delay(songNameGetDelay); // It takes a moment for the device to know the next song name
102+
MP3.getSongName();
103+
Serial.print("Playing: ");
104+
Serial.write(MP3.songName, 8);
105+
Serial.println();
106+
}
107+
else if(cmd == 'p')
108+
{
109+
uint8_t status = MP3.getPlayStatus();
110+
if(status == STATUS_PLAY)
111+
{
112+
Serial.println("Paused: ('p' to resume)");
113+
MP3.pause(); // Should pause when currently playing
114+
}
115+
else if(status == STATUS_PAUSE)
116+
{
117+
MP3.pause(); // Should play when already paused
118+
delay(songNameGetDelay); // It takes a moment for the device to know the next song name
119+
Serial.print("Resuming: ");
120+
MP3.getSongName();
121+
Serial.write(MP3.songName, 8);
122+
Serial.println();
123+
}
124+
else if(status == STATUS_STOP)
125+
{
126+
MP3.pause(); // Plays from beginning of current track
127+
delay(songNameGetDelay); // It takes a moment for the device to know the next song name
128+
MP3.getSongName();
129+
Serial.print("Playing: ");
130+
Serial.write(MP3.songName, 8);
131+
Serial.println();
132+
}
133+
}
134+
else if(cmd == 's')
135+
{
136+
Serial.println("Stopping: ('p' to play)");
137+
MP3.stopPlaying();
138+
}
139+
else if(cmd == '?')
140+
{
141+
uint8_t status = MP3.getPlayStatus();
142+
if(status == STATUS_PLAY)
143+
{
144+
delay(songNameGetDelay);
145+
MP3.getSongName();
146+
Serial.print("Playing: ");
147+
Serial.write(MP3.songName, 8);
148+
Serial.println();
149+
}
150+
else if(status == STATUS_STOP)
151+
{
152+
Serial.println("MP3 player is stopped");
153+
}
154+
else
155+
{
156+
Serial.println("MP3 player is paused");
157+
}
158+
}
159+
else if(cmd == 'w')
160+
{
161+
Serial.println("Set play mode to 'SingleNoLoop'");
162+
MP3.setPlaymodeSingleNoLoop();
163+
}
164+
else if(cmd == 'x')
165+
{
166+
Serial.println("Set play mode to 'SingleLoop'");
167+
MP3.setPlaymodeSingleLoop();
168+
}
169+
else if(cmd == 'y')
170+
{
171+
Serial.println("Set play mode to 'AllLoop'");
172+
MP3.setPlaymodeAllLoop();
173+
}
174+
else if(cmd == 'z')
175+
{
176+
Serial.println("Set play mode to 'Random'");
177+
MP3.setPlaymodeRandom();
178+
}
179+
else if((cmd <= '9') && (cmd >= '1'))
180+
{
181+
uint8_t numSongs = MP3.getSongCount();
182+
if(numSongs >= (cmd - '0'))
183+
{
184+
MP3.playTrackNumber(cmd - '0');
185+
Serial.print("Playing track #");
186+
Serial.print(cmd - '0');
187+
Serial.print(" (in copy-to-sd order)");
188+
delay(songNameGetDelay); // Give it time to switch songs
189+
MP3.getSongName();
190+
Serial.print(": ");
191+
Serial.write(MP3.songName, 8);
192+
Serial.println();
193+
}
194+
else
195+
{
196+
Serial.print("Error: There are only ");
197+
Serial.print(numSongs);
198+
Serial.println(" songs on the SD card.");
199+
Serial.print("You asked to play song # ");
200+
Serial.print(cmd - '0');
201+
Serial.println(".");
202+
}
203+
}
204+
else
205+
{
206+
printMenu();
207+
}
208+
}
209+
}
210+
211+
void printMenu( void )
212+
{
213+
Serial.println("MP3 Command List:");
214+
Serial.println("-----------------");
215+
Serial.println("'+' or '-' : raise/lower volume");
216+
Serial.println("'n' or 'l' : next/last song");
217+
Serial.println("'p' : play or pause");
218+
Serial.println("'s' : stop playing");
219+
Serial.println("'?' : what is playing?");
220+
Serial.println("'w' : set playmode single no loop");
221+
Serial.println("'x' : set playmode single loop");
222+
Serial.println("'y' : set playmode all loop");
223+
Serial.println("'z' : set playmode random");
224+
Serial.println("'X' : play the file that was copied to the SD card as the Xth file - you just type the number you want - (x in [1,9])");
225+
Serial.println(" (Yes, this really does go by copy order.)");
226+
Serial.println();
227+
Serial.println("Any other key to show this menu");
228+
Serial.println();
229+
}
230+

0 commit comments

Comments
 (0)