Skip to content

Commit 23df95a

Browse files
committed
Update examples to use v1.1 of the IC
1 parent 4a3d5fb commit 23df95a

File tree

2 files changed

+210
-24
lines changed

2 files changed

+210
-24
lines changed

examples/Example1_PlayFile/Example1_PlayFile.ino

Lines changed: 169 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
License: MIT. See license file for more information but you can
77
basically do whatever you want with this code.
88
9+
The MY1690 has a large number of features. This example presents the user
10+
with a serial menu to control the various aspects of the IC.
11+
912
Feel like supporting our work? Buy a board from SparkFun!
1013
https://www.sparkfun.com/products/18642
1114
@@ -18,13 +21,14 @@
1821
GND -> GND
1922
2023
Don't forget to load some MP3s on your sdCard and plug it in too!
24+
Note: Track must be named 0001.mp3 to myMP3.playTrackNumber(1)
2125
*/
2226

2327
#include "SparkFun_MY1690_MP3_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_MY1690
2428

2529
//For boards that support software serial
2630
#include "SoftwareSerial.h"
27-
SoftwareSerial serialMP3(5, 2); //RX on Arduino connected to TX on MY1690's, TX on Arduino connected to the MY1690's RX pin; format: SoftwareSerial mySerial(rx, tx)
31+
SoftwareSerial serialMP3(2, 3); //RX on Arduino connected to TX on MY1690's, TX on Arduino connected to the MY1690's RX pin
2832

2933
//For boards that have multiple hardware serial ports
3034
//HardwareSerial serialMP3(2); //Create serial port on ESP32: TX on 17, RX on 16
@@ -34,32 +38,190 @@ MY1690 myMP3;
3438
void setup()
3539
{
3640
Serial.begin(115200);
37-
Serial.println("MY1690 MP3 Example");
41+
Serial.println(F("MY1690 MP3 Example"));
3842

3943
serialMP3.begin(9600); //The MY1690 expects serial communication at 9600bps
40-
44+
4145
if (myMP3.begin(serialMP3) == false) // Beginning the MP3 player requires a serial port (either hardware or software)
4246
{
43-
Serial.println("Device not detected. Check wiring. Freezing.");
47+
Serial.println(F("Device not detected. Check wiring. Freezing."));
4448
while (1);
4549
}
4650

4751
int songCount = myMP3.getSongCount();
4852
if (songCount == 0)
4953
{
50-
Serial.println("Oh no! No songs found. Try adding songs or plugging in the sd card. Freezing.");
54+
Serial.println(F("Oh no! No songs found. Make sure the SD card is inserted and there are MP3s on it. Freezing."));
5155
while (1);
5256
}
5357

54-
Serial.print("Number of tracks on SD card: ");
58+
Serial.print(F("Number of tracks on SD card: "));
5559
Serial.println(songCount);
5660

57-
myMP3.setVolume(25); //Max of 30
61+
Serial.print(F("MY1690 Version: "));
62+
Serial.println(myMP3.getVersion());
5863

5964
myMP3.play(); //Will play the lowest numbered song in the folder
65+
66+
//It takes ~30ms for a track to start playing. If we check immediately, the track has not yet started.
67+
delay(50);
68+
69+
int playStatus = myMP3.getPlayStatus();
70+
// 0 = stop, 1 = play, 2 = pause, 3 = fast forward, 4 = rewind
71+
72+
Serial.print(F("playStatus: "));
73+
Serial.print(playStatus);
74+
if (playStatus == 1)
75+
Serial.println(F(" (playing)"));
76+
else if (playStatus == 0)
77+
Serial.println(F(" (stopped)"));
78+
79+
myMP3.setVolume(5); //30 is loudest. 5 is comfortable with headphones. 0 is mute.
80+
81+
Serial.print(F("Volume: "));
82+
Serial.println(myMP3.getVolume());
83+
84+
myMP3.setPlayModeNoLoop();
85+
86+
mainMenu();
6087
}
6188

6289
void loop()
6390
{
91+
if (Serial.available())
92+
{
93+
byte incoming = Serial.read();
94+
if (incoming == 's')
95+
{
96+
if(myMP3.stopPlaying() == true)
97+
Serial.println("Stop success");
98+
else
99+
Serial.println("Stop command failed");
100+
}
101+
else if (incoming == 'x')
102+
{
103+
if (myMP3.reset() == true)
104+
Serial.println("Reset success");
105+
else
106+
Serial.println("Reset command failed");
107+
}
108+
else if (incoming == 'a')
109+
{
110+
myMP3.volumeUp();
111+
Serial.print("Volume: ");
112+
Serial.println(myMP3.getVolume());
113+
}
114+
else if (incoming == 'z')
115+
{
116+
myMP3.volumeDown();
117+
Serial.print("Volume: ");
118+
Serial.println(myMP3.getVolume());
119+
}
120+
else if (incoming == 'f')
121+
{
122+
myMP3.fastForward();
123+
}
124+
else if (incoming == 'r')
125+
{
126+
myMP3.rewind();
127+
}
128+
else if (incoming == 'p')
129+
{
130+
myMP3.playPause();
131+
}
132+
else if (incoming == 'e')
133+
{
134+
int currentEQ = myMP3.getEQ();
135+
currentEQ++; //Go to next EQ. Device automatically wraps.
136+
137+
myMP3.setEQ(currentEQ);
138+
139+
currentEQ = myMP3.getEQ();
140+
Serial.print(F("Current EQ: "));
141+
Serial.println(currentEQ);
142+
}
143+
else if (incoming == 'm')
144+
{
145+
int currentMode = myMP3.getPlayMode();
146+
currentMode++; //Go to next mode.
147+
148+
if(currentMode > 4)
149+
currentMode = 0;
150+
151+
myMP3.setPlayMode(currentMode);
152+
153+
currentMode = myMP3.getPlayMode();
154+
Serial.print(F("Current Mode: "));
155+
Serial.println(currentMode);
156+
}
157+
else if (incoming == '<')
158+
{
159+
myMP3.playPrevious();
160+
}
161+
else if (incoming == '>')
162+
{
163+
myMP3.playNext();
164+
}
165+
else if (incoming == '#')
166+
{
167+
delay(20);
168+
while (Serial.available()) Serial.read();
169+
170+
Serial.println(F("Track number to play: "));
171+
while (Serial.available() == 0) delay(1);
172+
int value = Serial.parseInt();
173+
174+
// Note: Track must be named 0001.mp3 to myMP3.playTrackNumber(1)
175+
myMP3.playTrackNumber(value);
176+
}
177+
else if (incoming == 'c')
178+
{
179+
Serial.print(F("Current track: "));
180+
Serial.println(myMP3.getTrackNumber());
181+
}
182+
else if (incoming == 't')
183+
{
184+
Serial.print(F("Current track elapsed time (s): "));
185+
Serial.println(myMP3.getTrackElapsedTime());
186+
}
187+
else if (incoming == 'T')
188+
{
189+
Serial.print(F("Current track length (s): "));
190+
Serial.println(myMP3.getTrackTotalTime());
191+
}
192+
else if (incoming == '\r' || incoming == '\n')
193+
{
194+
//Ignore these
195+
}
196+
else
197+
{
198+
Serial.print(F("Unknown command: "));
199+
Serial.write(incoming);
200+
Serial.println();
201+
mainMenu();
202+
}
203+
}
204+
}
205+
206+
void mainMenu()
207+
{
208+
Serial.println();
209+
Serial.println(F("SparkFun MY1690 Menu:"));
64210

211+
Serial.println(F("s) Stop play"));
212+
Serial.println(F("x) Reset IC"));
213+
Serial.println(F("a) Volume up"));
214+
Serial.println(F("z) Volume down"));
215+
Serial.println(F("f) Fast forward"));
216+
Serial.println(F("r) Reverse"));
217+
Serial.println(F("p) Play/Pause toggle"));
218+
Serial.println(F("e) Set EQ"));
219+
Serial.println(F("m) Set play mode"));
220+
Serial.println(F("<) Play previous"));
221+
Serial.println(F(">) Play next"));
222+
Serial.println(F("#) Play track number"));
223+
Serial.println(F("c) Current track number"));
224+
Serial.println(F("t) Track elapsed time"));
225+
Serial.println(F("T) Track total time"));
226+
Serial.println(F("Enter command:"));
65227
}

examples/Example2_KitchenSink/Example2_KitchenSink.ino

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
GND -> GND
2222
2323
Don't forget to load some MP3s on your sdCard and plug it in too!
24+
Note: Track must be named 0001.mp3 to myMP3.playTrackNumber(1)
2425
*/
2526

2627
#include "SparkFun_MY1690_MP3_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_MY1690
2728

2829
//For boards that support software serial
2930
#include "SoftwareSerial.h"
30-
SoftwareSerial serialMP3(6, 4); //RX on Arduino connected to TX on MY1690's, TX on Arduino connected to the MY1690's RX pin
31+
SoftwareSerial serialMP3(2, 3); //RX on Arduino connected to TX on MY1690's, TX on Arduino connected to the MY1690's RX pin
3132

3233
//For boards that have multiple hardware serial ports
3334
//HardwareSerial serialMP3(2); //Create serial port on ESP32: TX on 17, RX on 16
@@ -50,7 +51,7 @@ void setup()
5051
int songCount = myMP3.getSongCount();
5152
if (songCount == 0)
5253
{
53-
Serial.println(F("Oh no! No songs found. Try adding songs or plugging in the sd card. Freezing."));
54+
Serial.println(F("Oh no! No songs found. Make sure the SD card is inserted and there are MP3s on it. Freezing."));
5455
while (1);
5556
}
5657

@@ -60,22 +61,28 @@ void setup()
6061
Serial.print(F("MY1690 Version: "));
6162
Serial.println(myMP3.getVersion());
6263

63-
//You can check to see if a given command was received correctly
64-
bool response = myMP3.play(); //Will play the lowest numbered song in the folder
65-
Serial.print(F("Play reponse: "));
66-
if (response == true)
67-
Serial.println(F("true"));
68-
else
69-
Serial.println(F("false"));
64+
myMP3.play(); //Will play the lowest numbered song in the folder
7065

71-
Serial.print(F("Playback Status: "));
72-
Serial.println(myMP3.getPlayStatus());
66+
//It takes ~30ms for a track to start playing. If we check immediately, the track has not yet started.
67+
delay(50);
7368

74-
myMP3.setVolume(25);
69+
int playStatus = myMP3.getPlayStatus();
70+
// 0 = stop, 1 = play, 2 = pause, 3 = fast forward, 4 = rewind
71+
72+
Serial.print(F("playStatus: "));
73+
Serial.print(playStatus);
74+
if (playStatus == 1)
75+
Serial.println(F(" (playing)"));
76+
else if (playStatus == 0)
77+
Serial.println(F(" (stopped)"));
78+
79+
myMP3.setVolume(5); //30 is loudest. 5 is comfortable with headphones. 0 is mute.
7580

7681
Serial.print(F("Volume: "));
7782
Serial.println(myMP3.getVolume());
7883

84+
myMP3.setPlayModeNoLoop();
85+
7986
mainMenu();
8087
}
8188

@@ -86,20 +93,28 @@ void loop()
8693
byte incoming = Serial.read();
8794
if (incoming == 's')
8895
{
89-
myMP3.stopPlaying();
96+
if(myMP3.stopPlaying() == true)
97+
Serial.println("Stop success");
98+
else
99+
Serial.println("Stop command failed");
90100
}
91101
else if (incoming == 'x')
92102
{
93-
myMP3.reset();
103+
if (myMP3.reset() == true)
104+
Serial.println("Reset success");
105+
else
106+
Serial.println("Reset command failed");
94107
}
95108
else if (incoming == 'a')
96109
{
97110
myMP3.volumeUp();
111+
Serial.print("Volume: ");
98112
Serial.println(myMP3.getVolume());
99113
}
100114
else if (incoming == 'z')
101115
{
102116
myMP3.volumeDown();
117+
Serial.print("Volume: ");
103118
Serial.println(myMP3.getVolume());
104119
}
105120
else if (incoming == 'f')
@@ -128,7 +143,10 @@ void loop()
128143
else if (incoming == 'm')
129144
{
130145
int currentMode = myMP3.getPlayMode();
131-
currentMode++; //Go to next mode. Device automatically wraps.
146+
currentMode++; //Go to next mode.
147+
148+
if(currentMode > 4)
149+
currentMode = 0;
132150

133151
myMP3.setPlayMode(currentMode);
134152

@@ -152,6 +170,8 @@ void loop()
152170
Serial.println(F("Track number to play: "));
153171
while (Serial.available() == 0) delay(1);
154172
int value = Serial.parseInt();
173+
174+
// Note: Track must be named 0001.mp3 to myMP3.playTrackNumber(1)
155175
myMP3.playTrackNumber(value);
156176
}
157177
else if (incoming == 'c')
@@ -161,14 +181,18 @@ void loop()
161181
}
162182
else if (incoming == 't')
163183
{
164-
Serial.print(F("Current track elapsed time: "));
184+
Serial.print(F("Current track elapsed time (s): "));
165185
Serial.println(myMP3.getTrackElapsedTime());
166186
}
167187
else if (incoming == 'T')
168188
{
169-
Serial.print(F("Current track total time: "));
189+
Serial.print(F("Current track length (s): "));
170190
Serial.println(myMP3.getTrackTotalTime());
171191
}
192+
else if (incoming == '\r' || incoming == '\n')
193+
{
194+
//Ignore these
195+
}
172196
else
173197
{
174198
Serial.print(F("Unknown command: "));

0 commit comments

Comments
 (0)