Lolins2 mini and df player

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();
    }
  }


*/
  
}

What settings do you choose for:
USB Mode
USB CDC on boot
USB MSC on boot
USB DFU on boot

Why are you using SoftwareSerial with a board that has three hardware UARTs?

You’re also not telling the SoftwareSerial library which pins to use for Rx and Tx

Pete.

Usb cdc on boot is enabled on arduino ide the others are all disabled, thats the default i think because i don’t actually know what they mean. And software serial is what was on the examples for both libraries, dfplay and df player fast. Ive declared both the pins as described by both the libraries. In my sketch ive tried both just commented out the df player fast commands to try the other one. As for the 3 uarts there is little to no documentation on the boards that state which pins are which.

Yes, but those examples almost certainly written for an Uno/Nano or ESP8266 that only has one (or one and a half) UARTs.

Not really.
You’re missing a line that declares the SoftwareSerial object and defines the Rx and Tx pins.

Is there a reason why you’ve chosen this particular board for your project? You don’t seem to know much about the hardware and it seems to be an overkill for the functionality you require.

Pete.

Ive chosen it because of the size and because i had a bunch of them. Ive used it before with 2 other sketches and didnt expect any issues. Without the blink section it works fine, and the blynk without the df player section connects to my template fine, just together has issues. I guess i could try to shoehorn in a wroom dev kit, if i cant sort it out although it would be nice to know whats going on.

I guess that’s what’s going on is that your device is booting then crashing because of an illegal operation related to your SoftwareSerial configuration, but you’re unable to view the crash dump because you aren’t seeing any serial output.

Pete.

so ive switched to an esp wroom da module, and after i upload the new sketch it boots and reboots for a long time sometimes 10 sometimes 20 then starts, sometimes longer. it started after trying to write a 10th vpin.

#define BLYNK_TEMPLATE_ID "TMPL6YWpvrTbJ"
#define BLYNK_TEMPLATE_NAME "mp3"
#define BLYNK_AUTH_TOKEN            "NRobvC7Q6NGIAVkPoIqdeZPrgXGzKNu0"

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include "OTA.h"
#include "credentials.h"

#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 <DFPlayerMini_Fast.h>

#if !defined(UBRR1H)
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 16); // RX, TX
#endif

DFPlayerMini_Fast myMP3;

int rstpin = 23;
int buspin = 17;
int r2ran = random(1, 134);




int ranwhistle = random (1 ,11);
int angryran = random (1 , 11);
int ranhappy = random (1 , 10);

//unsigned long customSoundStartTime = 0;
//bool isPlayingCustomSound = false;



#define VPIN_VOLUME      V6
#define VPIN_EQUALIZER   V7




BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V0);  // reset
  Blynk.syncVirtual(V1);  // bad motivator
  Blynk.syncVirtual(V6);  // volume
  Blynk.syncVirtual(V7);  // eq
  Blynk.syncVirtual(V4);  // scanner
  Blynk.syncVirtual(V5);  // periscope
  Blynk.syncVirtual(V8);  //light saber
  Blynk.syncVirtual(V9);   // zapper
  Blynk.syncVirtual(V2);  // angry holos
  //Blynk.syncVirtual(V11);  // angry holos
  //Blynk.syncVirtual(V12);  // happy hollos
 
}



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

  myMP3.volume(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

  myMP3.EQSelect(eq);

}

BLYNK_WRITE(V0) // 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 v0 pressed"); // Debugging output
    ESP.restart();
  //rst();
    //myMP3.reset();
    Blynk.virtualWrite(V0, 0);
  }
}
//////////////////////////

BLYNK_WRITE(V1) // 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 v1 pressed"); // Debugging output
     Serial.print("Playing track 4 from folder 9 ");
    myMP3.playFolder (9, 4);
    Blynk.virtualWrite(V1, 0);
  }
}
//////////////////////////

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
    Serial.print("Playing track 7 from folder 10 scanner ");
    myMP3.playFolder(10, 7);
    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
    Serial.print("Playing track 6 from folder 10 scanner ");
    myMP3.playFolder(10, 6);  // Play the custom sound from folder 2, track 1
    Blynk.virtualWrite(V5, 0);
  }
}

//////////////////////////
BLYNK_WRITE(V8) // 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 v8 pressed"); // Debugging output
    Serial.print("Playing track 5 from folder 5 music ");
    myMP3.playFolder(5, 5);  // Play the custom sound from folder 2, track 1
    Blynk.virtualWrite(V8, 0);
  }
}

//////////////////////////

BLYNK_WRITE(V9) // Executes when the value of virtual pin 1 changes zapper
{
  if (param.asInt() == 1)
  {
    // execute this code if the switch widget is now ON
    int ranwhistle = random (1 ,11);
    Serial.println("Virtual button v9 pressed"); // Debugging output
    Serial.print("Playing track ");
      Serial.print(ranwhistle);
      Serial.print(" from folder 6 ");
    myMP3.playFolder(6, ranwhistle);  // Play the custom sound from folder 2, track 1
    Blynk.virtualWrite(V9, 0);
  }
}

BLYNK_WRITE(V2) // Executes when the value of virtual pin 1 changes zapper
{
  if (param.asInt() == 1)
  {
    // execute this code if the switch widget is now ON
    int ranwhistle = random (1 ,11);
    Serial.println("Virtual button v2 pressed"); // Debugging output
    Serial.print("Playing track ");
      //Serial.print(ranwhistle);
      Serial.print(" from folder 3 ");
      myMP3.playFolder(3, 3);
    //myMP3.playFolder(3, ranwhistle);  // Play the custom sound from folder 2, track 1
    Blynk.virtualWrite(V10, 0);
  }
}
/*
//////////////////////////
BLYNK_WRITE(V11) // Executes when the value of virtual pin 1 changes
{
  if (param.asInt() == 1)
  {
    int angryran = random (1 , 11);
    // execute this code if the switch widget is now ON
    Serial.println("Virtual button v10 pressed"); // Debugging output
     Serial.print("Playing track ");
      Serial.print(angryran);
      Serial.print(" from folder 3 ");
    myMP3.playFolder(3, angryran);  // Play the custom sound from folder 2, track 1
    Blynk.virtualWrite(V11, 0);
  }
}
/*
//////////////////////////
BLYNK_WRITE(V10) // 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
    myMP3.playFolder(5, random(1,5));  // Play the custom sound from folder 2, track 1
    Blynk.virtualWrite(V10, 0);
  }
}
//////////////////////////
//////////////////////////
BLYNK_WRITE(V12) // 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
    myMP3.playFolder(7,ranhappy);  // Play the custom sound from folder 2, track 1
    Blynk.virtualWrite(V12, 0);
  }
}
*/
void setup()
{


  setupOTA("devkit sounds", mySSID, myPASSWORD);

  Serial.begin(115200);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

delay(1000);

  pinMode(buspin, INPUT);
   pinMode(rstpin, OUTPUT);
   digitalWrite (rstpin, HIGH);

  mySerial.begin(9600);
  myMP3.begin(mySerial);

  delay(1000);

  Serial.println("Setting volume to max");
  myMP3.volume(10);

  Serial.println("playing track 1");
  myMP3.playFolder(1, 1);
}

void generalsounds() {
  static unsigned long timer = millis();
  static bool playedFirstTrack = false;
  int r2ran = random(1, 134);
  int folderNumber = 2; // The folder number you want to play from

  if (!playedFirstTrack) {
    if (myMP3.isPlaying() == false) {
      playedFirstTrack = true;
      // myMP3.repeatFolder(3);
      myMP3.playFolder(folderNumber, r2ran);  // Play the first track from folder 3
      Serial.print("Playing track ");
      Serial.print(r2ran);
      Serial.print(" from folder ");
      Serial.println(folderNumber);
      timer = millis();
    }
  } else {
    if (digitalRead(buspin) == HIGH && (millis() - timer > 8000)) {
      timer = millis();
      myMP3.playFolder(folderNumber, r2ran);
      Serial.print("Playing track ");
      Serial.print(r2ran);
      Serial.print(" from folder ");
      Serial.println(folderNumber);
      // myMP3.startRepeat();
      // myMP3.playNext();
      // myMP3.repeatFolder(folderNumber);
    }
  }
}




void loop()
{
#ifdef defined(ESP32_RTOS) && defined(ESP32)
#else // If you do not use FreeRTOS, you have to regulary call the handle method.
  ArduinoOTA.handle();
#endif



  Blynk.run();


  generalsounds();


}
void rst() {
    digitalWrite (rstpin , LOW);
   delay(200);
    digitalWrite (rstpin , HIGH);
}

the output says its only using 59 percent of memory.

You have a flaw in the logic of this BLYNK_WRITE callback, as its impossible to do a Blynk.virtualWrite if the device is rebooted before you get to that line of code…

I’d change the sequence of operations, and remove the Blynk.syncVirtual(V0); from your BLYNK_CONNECTED callback.

As most of your BLYNK_CONNECTED callbacks end with writing a “0” to that virtual pin, these widgets will be in the “Off” state by default. if that’s the case, why are you synchronising their values in BLYNK_CONNECTED?

I don’t understand what’s happening with OTA in your sketch, but I doubt that it will work when you seem to be initialising your OTA client before you create your WiFi connection. I’m guessing that some of your OTA stuff is buried in credentials.h?

Calling generalsounds(); from your void loop, and having delays in your void loop after calling Blynk.begin() aren’t good practice from, a Blynk perspective.

You also have quite a lot of unused code and inaccurate comments in your sketch, which doesn’t help us (or you) understand what’s happening within the sketch. I’d suggest that you have a clean up.

Pete.

ok, ive cleaned up the code and removed all the blynk writes to “0”. the ota works fine and there is only 1 call to function in the void loop. It still boots a few times then runs the program.

Seeing the revised code, and your serial monitor output would probably help.

Pete.

[4803] Connecting to TelstraA857CE
[8330] Connected to WiFi
[8330] IP: 192.168.0.123
[8331] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v1.2.0 on ESP32

 #StandWithUkraine    https://bit.ly/swua


[8341] Connecting to blynk.cloud:80
[8670] Ready (ping: 169ms).
BLYNK_WRITE(VPIN_VOLUME): 13
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400d7751  PS      : 0x00060f30  A0      : 0x800d7810  A1      : 0x3ffcb620  
A2      : 0x3ffc378c  A3      : 0x0000000d  A4      : 0x0000000a  A5      : 0x00000000  
A6      : 0x3ffc4928  A7      : 0x3ffc4914  A8      : 0x0000ffed  A9      : 0x000000ff  
A10     : 0x00000000  A11     : 0x00000000  A12     : 0x5e5bad65  A13     : 0x3ffc45fc  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x40089e85  LEND    : 0x40089e95  LCOUNT  : 0xffffffff  


Backtrace: 0x400d774e:0x3ffcb620 0x400d780d:0x3ffcb640 0x400d3115:0x3ffcb660 0x400d3acd:0x3ffcb680 0x400d3eff:0x3ffcb6e0 0x400d3515:0x3ffcb750 0x400d36ec:0x3ffcb780 0x400d3b25:0x3ffcb800 0x400d3b81:0x3ffcbc40 0x400d3ce3:0x3ffcbc60 0x400d3515:0x3ffcbcc0 0x400d4101:0x3ffcbcf0 0x400d96fe:0x3ffcbd20




ELF file SHA256: 448d68f07a3ba62e

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13260
load:0x40080400,len:3028
entry 0x400805e4
[3089] Connecting to TelstraA857CE
[6112] Connected to WiFi
[6112] IP: 192.168.0.123
[6113] 

this is the serial monitor output and the revised code

#define BLYNK_TEMPLATE_ID "TMPL6YWpvrTbJ"
#define BLYNK_TEMPLATE_NAME "mp3"
#define BLYNK_AUTH_TOKEN            "NRobvC7Q6NGIAVkPoIqdeZPrgXGzKNu0"

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include "OTA.h"
#include "credentials.h"

#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 <DFPlayerMini_Fast.h>

#if !defined(UBRR1H)
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 16); // RX, TX
#endif

DFPlayerMini_Fast myMP3;


int buspin = 17;
int r2ran = random(1, 134);
int ranwhistle = random (1 , 11);
int angryran = random (1 , 11);
int ranhappy = random (1 , 10);

#define VPIN_VOLUME      V6
#define VPIN_EQUALIZER   V7




BLYNK_CONNECTED()
{
  Blynk.syncVirtual(V0);  // reset
  Blynk.syncVirtual(V1);  // bad motivator
  Blynk.syncVirtual(V6);  // volume
  Blynk.syncVirtual(V7);  // eq
  Blynk.syncVirtual(V4);  // scanner
  Blynk.syncVirtual(V5);  // periscope
  Blynk.syncVirtual(V8);  //light saber
  Blynk.syncVirtual(V9);   // zapper
  Blynk.syncVirtual(V2);  // angry holos
  
}



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

  myMP3.volume(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

  myMP3.EQSelect(eq);

}

BLYNK_WRITE(V0) // Executes when the value of virtual pin 0 changes
{
  if (param.asInt() == 1)
  {
    // execute this code if the switch widget is now ON
    Serial.println("Virtual button v0 pressed"); // Debugging output
    ESP.restart();

  }
}
//////////////////////////
BLYNK_WRITE(V1) // 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 v1 pressed"); // Debugging output
    Serial.print("Playing track 4 from folder 9 ");
    myMP3.playFolder (9, 4);
  
  }
}
//////////////////////////

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
    Serial.print("Playing track 7 from folder 10 scanner ");
    myMP3.playFolder(10, 7);
  
  }
}
//////////////////////////

BLYNK_WRITE(V5) // Executes when the value of virtual pin 5 changes
{
  if (param.asInt() == 1)
  {
    // execute this code if the switch widget is now ON
    Serial.println("Virtual button v5 pressed"); // Debugging output
    Serial.print("Playing track 6 from folder 10 scanner ");
    myMP3.playFolder(10, 6);  // Play the custom sound from folder 2, track 1
    
  }
}

//////////////////////////
BLYNK_WRITE(V8) // Executes when the value of virtual pin 8 changes
{
  if (param.asInt() == 1)
  {
    // execute this code if the switch widget is now ON
    Serial.println("Virtual button v8 pressed"); // Debugging output
    Serial.print("Playing track 5 from folder 5 music ");
    myMP3.playFolder(5, 5);  // Play the custom sound from folder 2, track 1
   
  }
}

//////////////////////////

BLYNK_WRITE(V9) // Executes when the value of virtual pin 9 changes zapper
{
  if (param.asInt() == 1)
  {
    // execute this code if the switch widget is now ON
    int ranwhistle = random (1 , 11);
    Serial.println("Virtual button v9 pressed"); // Debugging output
    Serial.print("Playing track ");
    Serial.print(ranwhistle);
    Serial.print(" from folder 6 ");
    myMP3.playFolder(6, ranwhistle);  // Play the custom sound from folder 2, track 1
    
  }
}

  BLYNK_WRITE(V2) // Executes when the value of virtual pin 1 changes zapper
  {
  if (param.asInt() == 1)
  {
    // execute this code if the switch widget is now ON
    int ranwhistle = random (1 ,11);
    Serial.println("Virtual button v2 pressed"); // Debugging output
    Serial.print("Playing track ");
      //Serial.print(ranwhistle);
      Serial.print(" from folder 3 ");
      
    myMP3.playFolder(3, ranwhistle);  // Play the custom sound from folder 2, track 1
    
  }
  }
 
void setup()
{


  setupOTA("devkit sounds", mySSID, myPASSWORD);

  Serial.begin(115200);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

  

  pinMode(buspin, INPUT);
 

  mySerial.begin(9600);
  myMP3.begin(mySerial);

 

  Serial.println("Setting volume to ");
  myMP3.volume(10);

  Serial.println("playing track 1");
  myMP3.playFolder(1, 1);
}



void generalsounds() {
  static unsigned long timer = millis();
  static bool playedFirstTrack = false;
  int r2ran = random(1, 134);
  int folderNumber = 2; // The folder number you want to play from

  if (!playedFirstTrack) {
    if (myMP3.isPlaying() == false) {
      playedFirstTrack = true;
      // myMP3.repeatFolder(3);
      myMP3.playFolder(folderNumber, r2ran);  // Play the first track from folder 3
      Serial.print("Playing track ");
      Serial.print(r2ran);
      Serial.print(" from folder ");
      Serial.println(folderNumber);
      timer = millis();
    }
  } else {
    if (digitalRead(buspin) == HIGH && (millis() - timer > 8000)) {
      timer = millis();
      myMP3.playFolder(folderNumber, r2ran);
      Serial.print("Playing track ");
      Serial.print(r2ran);
      Serial.print(" from folder ");
      Serial.println(folderNumber);

    }
  }
}




void loop()
{
#ifdef defined(ESP32_RTOS) && defined(ESP32)
#else // If you do not use FreeRTOS, you have to regulary call the handle method.
  ArduinoOTA.handle();
#endif



  Blynk.run();


  generalsounds();


}

it still reboots quite a few times, occasionally it runs.

Okay, so is there any reason you didn’t mention the Guru Meditation Error?

You should start by popping that crash dump into the ESP exception decoder and see what says.

Pete.

no reason i didnt mention it except didnt actually notice. so i put it into the crash dump decoder i think nut i have no idea what it means.

PC: 0x400d7741: UpdateClass::write(unsigned char*, unsigned int) at C:\Users\Terry\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\libraries\Update\src\Updater.cpp line 175
0x400d773e: UpdateClass::write(unsigned char*, unsigned int) at C:\Users\Terry\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\libraries\Update\src\Updater.cpp line 175
0x400d77fd: GetReadHandler(uint8_t) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src\utility\BlynkHandlers.cpp line 393
0x400d3115: BlynkWifi::connectWiFi(char const*, char const*) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/BlynkSimpleEsp32.h line 39
0x400d3acd: BlynkApi    > >::processCmd(void const*, unsigned int) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/BlynkApiArduino.h line 105
0x400d3eff: BlynkProtocol   >::processInput() at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/Blynk/BlynkProtocol.h line 283
0x400d3515: BlynkArduinoClientGen ::_connectToPort(unsigned short) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/Adapters/BlynkArduinoClient.h line 54
0x400d36ec: BlynkProtocol   >::run(bool) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/Blynk/BlynkUtility.h line 177
0x400d3b25: BlynkApi    > >::processCmd(void const*, unsigned int) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/BlynkApiArduino.h line 94
0x400d3b73: BlynkApi    > >::processCmd(void const*, unsigned int) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/Blynk/BlynkParam.h line 43
0x400d3515: BlynkArduinoClientGen ::_connectToPort(unsigned short) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/Adapters/BlynkArduinoClient.h line 54
0x400d4101: BlynkProtocol   >::processInput() at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/Blynk/BlynkProtocol.h line 395
0x400d96ee: Stream::timedRead() at C:\Users\Terry\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\cores\esp32\Stream.cpp line 34
EXCVADDR: 0x00000000

Decoding stack results
0x400d773e: UpdateClass::write(unsigned char*, unsigned int) at C:\Users\Terry\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\libraries\Update\src\Updater.cpp line 175
0x400d77fd: GetReadHandler(uint8_t) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src\utility\BlynkHandlers.cpp line 393
0x400d3115: BlynkWifi::connectWiFi(char const*, char const*) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/BlynkSimpleEsp32.h line 39
0x400d3acd: BlynkApi    > >::processCmd(void const*, unsigned int) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/BlynkApiArduino.h line 105
0x400d3eff: BlynkProtocol   >::processInput() at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/Blynk/BlynkProtocol.h line 283
0x400d3515: BlynkArduinoClientGen ::_connectToPort(unsigned short) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/Adapters/BlynkArduinoClient.h line 54
0x400d36ec: BlynkProtocol   >::run(bool) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/Blynk/BlynkUtility.h line 177
0x400d3b25: BlynkApi    > >::processCmd(void const*, unsigned int) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/BlynkApiArduino.h line 94
0x400d3b73: BlynkApi    > >::processCmd(void const*, unsigned int) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/Blynk/BlynkParam.h line 43
0x400d3515: BlynkArduinoClientGen ::_connectToPort(unsigned short) at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/Adapters/BlynkArduinoClient.h line 54
0x400d4101: BlynkProtocol   >::processInput() at C:\Users\Terry\OneDrive\Documents\Arduino\libraries\blynk-library-master\src/Blynk/BlynkProtocol.h line 395
0x400d96ee: Stream::timedRead() at C:\Users\Terry\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\cores\esp32\Stream.cpp line 34

not even close to understanding.

I think a better approach would have been to comment-out all of your Blynk.syncVirtual statements from BLYNK_CONNECTED, at least during testing.

You should also comment-out generalsounds(); from your void loop.

It’s interesting that these lines of code in your void setup don’t seem to be executing, according to your serial monitor…

You should probably update to v1.3.0

Pete.

I do not want to add to the confusion but I gave up using Blynk.syncVirtual due to crashes I was never able to understand.

As parts of your setup is not being executed, it could very well be the Blynk.syncVirtual call in BLYNK_CONNECTED cause the issue as they may be executed well before “myMP3.volume(10)”.

It is a quick test to comment out all the statements in BLYNK_CONNECTED and see how it goes.

2 Likes

Well this seemed to have fixed the issue so far, I assumed the blynk connected was needed , and the same with the virtual sync.

This seems to confirm a possible issue with the virtual sync (I have seen the issue on both ESP8266 and ESP32 platforms).

You only need it if you want your hardware at boottime to be in sync with the status of the virtual pins as stored in the Blynk server (which is not your case I learned).

The below might not be relevant to you but might help other people, this is what I did:

  • removed all virtual sync from the code.
  • added a httpsGet on the Blynk server for all the virtual pins I need to know the stored status.
  • having all states at hand, you can now decide yourself when to sync, in which sequence and at what rate.

Looks complicated but it’s not and it works without issues.

Piet.

I suspect the problem in this case is that @Tezza has virtual pin buttons to play specific music tracks, and is also calling generalsounds() from the void loop.
generalsounds() seems to be playing random tracks, so will override whatever is happening that is triggered by the virtual pins. It’s also possible for multiple track selection buttons to be pressed, so when they sync it would trigger one track playback, then the other, then all of this being overridden by generalsounds()

A better approach would probably be a menu widget or segmented switch to choose the desired track, o and of course to stop calling generalsounds() all the time.

Pete.

actually Pete its the other way around, the general plays random tracks from a specific folder and the virtual pins are used to trigger certain sounds, they will be triggered using the automations for example when the periscope goes up plays a track from folder 10 track 6

I think you’re assuming that generalsounds() isn’t triggered again until the periscope sound has ended.

Pete.