hi im having trouble with the df player mini with a lolin s2 mini. the df player sketch works, and the blynk sketch works but together it resets the esp, all i can hear is the pc doing the usb connect and disconnect sound. serial monitor cant seem to display anything either. any help would be greatly appreciated as this is the last piece of my very long r2d2 build.
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "33333333333"
#define BLYNK_TEMPLATE_NAME "mp3"
#define BLYNK_AUTH_TOKEN "auth token"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "TelstraA857CE";
char pass[] = "fuateu9u4t";
#include <DFPlayer.h>
#include <SoftwareSerial.h>
#define MP3_RX_PIN 39 //GPIO5/D1
#define MP3_TX_PIN 40 //GPIO4/D2
#define MP3_SERIAL_SPEED 9600 //DFPlayer Mini suport only 9600-baud
#define MP3_SERIAL_BUFFER_SIZE 32 //software serial buffer size in bytes, to send 8-bytes you need 11-bytes buffer (start byte+8-data bytes+parity-byte+stop-byte=11-bytes)
#define MP3_SERIAL_TIMEOUT 100 //average DFPlayer response timeout 100msec..200msec
SoftwareSerial mp3Serial;
DFPlayer mp3;
/*
#include <DFPlayerMini_Fast.h>
#if !defined(UBRR1H)
#include <SoftwareSerial.h>
SoftwareSerial mySerial(39, 40); // RX, TX
#endif
DFPlayerMini_Fast myMP3;
*/
int buspin = 38;
int ran1 = random(1,20);
#define VPIN_VOLUME V6
#define VPIN_EQUALIZER V7
static unsigned long timer = millis();
static bool playedFirstTrack = false;
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V6); // volume
Blynk.syncVirtual(V7); // eq
Blynk.syncVirtual(V4); // bad sound
Blynk.syncVirtual(V5); // bad sound
}
BLYNK_WRITE(VPIN_VOLUME)
{
int paramVol = param.asInt();
uint8_t volume = constrain(paramVol, 0, 30);
#ifdef BLYNK_PRINT
BLYNK_PRINT.print("BLYNK_WRITE(VPIN_VOLUME): ");
BLYNK_PRINT.println(paramVol);
#endif
mp3.setVolume(volume);
}
//////////////////////////////////
BLYNK_WRITE(VPIN_EQUALIZER)
{
int paramEq = param.asInt();
uint8_t eq = constrain(paramEq, 1, 6) - 1; // Blynk starts with 1, setEqualizer starts with 0
#ifdef BLYNK_PRINT
BLYNK_PRINT.print("BLYNK_WRITE(VPIN_EQUALIZER): ");
BLYNK_PRINT.println(paramEq);
#endif
mp3.setEQ(eq);
}
BLYNK_WRITE(V4) // Executes when the value of virtual pin 1 changes
{
if(param.asInt() == 1)
{
// execute this code if the switch widget is now ON
Serial.println("Virtual button v4 pressed"); // Debugging output
mp3.playFolder(1, 1);
Blynk.virtualWrite(V4, 0);
}
}
//////////////////////////
BLYNK_WRITE(V5) // Executes when the value of virtual pin 1 changes
{
if(param.asInt() == 1)
{
// execute this code if the switch widget is now ON
Serial.println("Virtual button v5 pressed"); // Debugging output
mp3.playFolder(12, 1); // Play the custom sound from folder 2, track 1
// Blynk.virtualWrite(V4, 0);
}
}
//////////////////////////
void setup()
{
// Debug console
Serial.begin(115200);
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// You can also specify server:
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080);
pinMode(buspin, INPUT);
/*
#if !defined(UBRR1H)
mySerial.begin(9600);
myMP3.begin(mySerial);
#else
//Serial1.begin(9600);
// myMP3.begin(Serial1, true);
#endif
delay(1000);
Serial.println("Setting volume to max");
myMP3.volume(10);
Serial.println("Looping track 1");
*/
mp3Serial.begin(MP3_SERIAL_SPEED, SWSERIAL_8N1, MP3_RX_PIN, MP3_TX_PIN, false, MP3_SERIAL_BUFFER_SIZE, 0); //false=signal not inverted, 0=ISR/RX buffer size (shared with serial TX buffer)
mp3.begin(mp3Serial, MP3_SERIAL_TIMEOUT, DFPLAYER_MINI, false); //DFPLAYER_MINI see NOTE, false=no response from module after the command
mp3.stop(); //if player was runing during ESP8266 reboot
mp3.reset(); //reset all setting to default
mp3.setSource(2); //1=USB-Disk, 2=TF-Card, 3=Aux, 4=Sleep, 5=NOR Flash
mp3.setEQ(0); //0=Off, 1=Pop, 2=Rock, 3=Jazz, 4=Classic, 5=Bass
mp3.setVolume(10); //0..30, module persists volume on power failure
}
void loop()
{
Blynk.run();
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!
/*
if (!playedFirstTrack) {
if (digitalRead(buspin) == HIGH) {
playedFirstTrack = true;
// myMP3.repeatFolder(3);
mp3.playFolder(2, ran1); // Play the first track from folder 3
timer = millis();
}
} else {
if (digitalRead(buspin) == HIGH && (millis() - timer > 6000)) {
timer = millis();
// myMP3.startRepeat();
mp3.next();
}
}
*/
}