Skip to content

Commit aa80f2b

Browse files
nopnop2002baldram
authored andcommitted
Update examples for compatibility with both ESP8266 and ESP32 (#40)
1 parent 7ecc51e commit aa80f2b

File tree

2 files changed

+55
-26
lines changed

2 files changed

+55
-26
lines changed

examples/Mp3PlayerDemo/Mp3PlayerDemo.ino

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
Licensed under GNU GPL v3
88
99
The circuit (example wiring for ESP8266 based board like eg. LoLin NodeMCU V3):
10-
---------------------
11-
| VS1053 | ESP8266 |
12-
---------------------
13-
| SCK | D5 |
14-
| MISO | D6 |
15-
| MOSI | D7 |
16-
| XRST | RST |
17-
| CS | D1 |
18-
| DCS | D0 |
19-
| DREQ | D3 |
20-
| 5V | VU |
21-
| GND | G |
22-
---------------------
10+
--------------------------------
11+
| VS1053 | ESP8266 | ESP32 |
12+
--------------------------------
13+
| SCK | D5 | IO18 |
14+
| MISO | D6 | IO19 |
15+
| MOSI | D7 | IO23 |
16+
| XRST | RST | EN |
17+
| CS | D1 | IO5 |
18+
| DCS | D0 | IO16 |
19+
| DREQ | D3 | IO4 |
20+
| 5V | 5V | 5V |
21+
| GND | GND | GND |
22+
--------------------------------
2323
2424
Note: It's just an example, you may use a different pins definition.
2525
For ESP32 example, please follow the link:
@@ -31,10 +31,17 @@
3131
platform = espressif8266
3232
board = nodemcuv2
3333
framework = arduino
34+
lib_deps =
35+
ESP_VS1053_Library
3436
37+
[env:esp32dev]
38+
platform = espressif32
39+
board = esp32dev
40+
framework = arduino
3541
lib_deps =
3642
ESP_VS1053_Library
3743
44+
3845
*/
3946

4047
// This ESP_VS1053_Library
@@ -45,9 +52,17 @@
4552
#include "SampleMp3.h"
4653

4754
// Wiring of VS1053 board (SPI connected in a standard way)
55+
#ifdef ARDUINO_ARCH_ESP8266
4856
#define VS1053_CS D1
4957
#define VS1053_DCS D0
5058
#define VS1053_DREQ D3
59+
#endif
60+
61+
#ifdef ARDUINO_ARCH_ESP32
62+
#define VS1053_CS 5
63+
#define VS1053_DCS 16
64+
#define VS1053_DREQ 4
65+
#endif
5166

5267
#define VOLUME 100 // volume level 0-100
5368

examples/WebRadioDemo/WebRadioDemo.ino

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
77
Wiring:
88
--------------------------------
9-
| VS1053 | ESP8266 | Other |
9+
| VS1053 | ESP8266 | ESP32 |
1010
--------------------------------
11-
| SCK | D5 | - |
12-
| MISO | D6 | - |
13-
| MOSI | D7 | - |
14-
| XRST | - | - |
15-
| CS | D1 | - |
16-
| DCS | D0 | - |
17-
| DREQ | D3 | - |
18-
| 5V | - | VCC |
19-
| GND | - | GND |
11+
| SCK | D5 | IO18 |
12+
| MISO | D6 | IO19 |
13+
| MOSI | D7 | IO23 |
14+
| XRST | RST | EN |
15+
| CS | D1 | IO5 |
16+
| DCS | D0 | IO16 |
17+
| DREQ | D3 | IO4 |
18+
| 5V | 5V | 5V |
19+
| GND | GND | GND |
2020
--------------------------------
2121
2222
Dependencies:
2323
-VS1053 library by baldram (https://github.com/baldram/ESP_VS1053_Library)
24-
-ESP8266Wifi
24+
-ESP8266Wifi/WiFi
2525
2626
To run this example define the platformio.ini as below.
2727
@@ -30,7 +30,13 @@
3030
board = nodemcuv2
3131
framework = arduino
3232
build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH
33+
lib_deps =
34+
ESP_VS1053_Library
3335
36+
[env:esp32dev]
37+
platform = espressif32
38+
board = esp32dev
39+
framework = arduino
3440
lib_deps =
3541
ESP_VS1053_Library
3642
@@ -47,11 +53,19 @@
4753
*/
4854

4955
#include <VS1053.h>
56+
#ifdef ARDUINO_ARCH_ESP8266
5057
#include <ESP8266WiFi.h>
51-
5258
#define VS1053_CS D1
5359
#define VS1053_DCS D0
5460
#define VS1053_DREQ D3
61+
#endif
62+
63+
#ifdef ARDUINO_ARCH_ESP32
64+
#include <WiFi.h>
65+
#define VS1053_CS 5
66+
#define VS1053_DCS 16
67+
#define VS1053_DREQ 4
68+
#endif
5569

5670
// Default volume
5771
#define VOLUME 80
@@ -60,7 +74,7 @@ VS1053 player(VS1053_CS, VS1053_DCS, VS1053_DREQ);
6074
WiFiClient client;
6175

6276
// WiFi settings example, substitute your own
63-
char* ssid = "TP-Link";
77+
const char* ssid = "TP-Link";
6478
const char* password = "xxxxxxxx";
6579

6680
// http://comet.shoutca.st:8563/1

0 commit comments

Comments
 (0)