Skip to content

Commit

Permalink
Extract 'switch to MP3 mode' functionality to be called explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
baldram committed Jul 7, 2017
1 parent 0f9194d commit ac892e0
Show file tree
Hide file tree
Showing 6 changed files with 713 additions and 35 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,22 @@ Then initialize the player and use as in following example:
```
player.begin();
player.setVolume(VOLUME);
player.switchToMp3Mode();
player.playChunk(helloMp3, sizeof(helloMp3));
```

For complete code please check `examples` folder.
For complete code please check [examples](https://github.com/baldram/ESP_VS1053_Library/tree/master/examples) folder.

#### 3rd party dependencies
Please note that `player.switchToMp3Mode()` is an optional switch. Some of VS1053 modules will start up in MIDI mode. The result is no audio when playing MP3.
You can modify the board, but there is a more elegant way without soldering. For more details please read a discussion here: [http://www.bajdi.com/lcsoft-vs1053-mp3-module/#comment-33773](http://www.bajdi.com/lcsoft-vs1053-mp3-module/#comment-33773).
<br />No side effects for boards which do not need this switch, so you can call it just in case.

The library use also a 3rd party logging framework [ArduinoLog](http://platformio.org/lib/show/1532/ArduinoLog/) for debugging purposes.<br />
This dependency will be solved automatically.
#### Third-party dependencies

Then you are able to include and use this library from your code (you have several log levels):
The library use also a third-party logging framework [ArduinoLog](http://platformio.org/lib/show/1532/ArduinoLog/) for debugging purposes.<br />
This dependency will be resolved automatically.

Then you are able to include and use this library from your code (it offers several log levels):

```
#include <ArduinoLog.h>
Expand Down
12 changes: 2 additions & 10 deletions examples/SimpleMp3Player/SimpleMp3Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
*/

#include <Arduino.h>
#include <ArduinoLog.h> // PlatformIO library id=1532
#include <VS1053.h> // this library
#include <VS1053.h> // this ESP_VS1053_Library
#include <helloMp3.h>

// Wiring of VS1053 board (SPI connected in a standard way)
Expand All @@ -53,20 +52,13 @@ void setup () {
// initialize SPI
SPI.begin();

// open serial monitor for debugging
Serial.begin(9600);
while(!Serial && !Serial.available()){}
Log.begin(LOG_LEVEL_VERBOSE, &Serial);

// initialize a player
Log.notice("\n Hello VS1053!");
player.begin();
player.switchToMp3Mode(); // optional, some boards require this
player.setVolume(VOLUME);
}

void loop() {
Log.notice("Playing sound... ");

// play mp3 flow each 3s
player.playChunk(helloMp3, sizeof(helloMp3));
delay(3000);
Expand Down
78 changes: 78 additions & 0 deletions examples/SimpleMp3PlayerWithDebug/SimpleMp3PlayerWithDebug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
A simple example to use ESP_VS1053_Library (plays a test sound every 3s)
https://github.com/baldram/ESP_VS1053_Library
If you like this project, please add a star.
For debugging it uses third-party library ArduinoLog.
No need to add a depenency in lib_deps explicitly, since
it is used internally by ESP_VS1053_Library.
Copyright (C) 2017 Marcin Szalomski (github.com/baldram)
Licensed under GNU GPL v3
The circuit (example wiring for ESP8266 based board like eg. LoLin NodeMCU V3):
---------------------
| VS1053 | ESP8266 |
---------------------
| SCK | D5 |
| MISO | D6 |
| MOSI | D7 |
| XRST | RST |
| CS | D1 |
| DCS | D0 |
| DREQ | D3 |
| 5V | VU |
| GND | G |
---------------------
Note: It's just an example, you may use a different pins definition
To run this example define the platformio.ini as below.
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
lib_deps =
baldram/ESP_VS1053_Library
*/

#include <Arduino.h>
#include <ArduinoLog.h> // PlatformIO library id=1532
#include <VS1053.h> // this ESP_VS1053_Library
#include <helloMp3.h>

// Wiring of VS1053 board (SPI connected in a standard way)
#define VS1053_CS D1
#define VS1053_DCS D0
#define VS1053_DREQ D3

#define VOLUME 100 // volume level 0-100

VS1053 player(VS1053_CS, VS1053_DCS, VS1053_DREQ);

void setup () {
// initialize SPI
SPI.begin();

// open serial monitor for debugging
Serial.begin(9600);
while(!Serial && !Serial.available()){}
Log.begin(LOG_LEVEL_VERBOSE, &Serial);

// initialize a player
Log.notice("Hello VS1053!\n");
player.begin();
player.switchToMp3Mode(); // optional, some boards require this
player.setVolume(VOLUME);
}

void loop() {
Log.notice("Playing sound... ");

// play mp3 flow each 3s
player.playChunk(helloMp3, sizeof(helloMp3));
delay(3000);
}
Loading

0 comments on commit ac892e0

Please sign in to comment.