As mentioned, I am allotting the following code for 2 DF Players to get operated with the 2 built in cores of ESP32 unit
4 of the GPIOs are defined as input
Rest in code below
#include <DFPlayerMini_Fast.h>
#include <SoftwareSerial.h>
#define LED1 2
#define LED2 15
const byte tap1 = 32;
const byte tap2 = 33;
const byte tap3 = 27;
const byte tap4 = 14;
const byte ledPin [] = {2,15};
TaskHandle_t Task1, Task2;
SemaphoreHandle_t baton;
// SoftwareSerial mySerial1(3, 1); // RX, TX
#define RXD2 16
#define TXD2 17
DFPlayerMini_Fast player1;
SoftwareSerial mySerial(18, 19); // RX, TX
DFPlayerMini_Fast player;
void Buttons(const byte pin, const byte ledPin){
if(!digitalRead(pin)){
digitalWrite(ledPin, HIGH);
}else{
digitalWrite(ledPin, LOW);
}
}
void codeForTask1( void * parameter )
{
for (;;) {
// Buttons(tap1, LED2);
// Buttons(tap2, LED2);
if(!digitalRead(tap1))
{
// digitalWrite(ledPin,1);
player.play(1);
// Serial.print(player);
while(!digitalRead(tap1));
}
if(!digitalRead(tap2))
{
// digitalWrite(ledPin,1);
player.play(2);
// Serial.print(player);
while(!digitalRead(tap2));
}
}
// delay(100);
}
void codeForTask2( void * parameter )
{
for (;;) {
// Buttons(tap3, LED1);
// Buttons(tap4, LED1);
if(!digitalRead(tap3))
{
// digitalWrite(ledPin,1);
player1.play(1);
// Serial.print(player);
while(!digitalRead(tap3));
}
if(!digitalRead(tap4))
{
// digitalWrite(ledPin,1);
player1.play(2);
// Serial.print(player);
while(!digitalRead(tap4));
}
}
// delay(100);
}
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
if(player1.begin(Serial2, false))
{
// player1.volume(22);
// player1.stop();
}
mySerial.begin(9600);
if(player.begin(mySerial, false))
{
// player.volume(22);
// player.stop();
}
pinMode(tap1, INPUT);
pinMode(tap2, INPUT);
pinMode(tap3, INPUT);
pinMode(tap4, INPUT);
baton = xSemaphoreCreateMutex();
xTaskCreatePinnedToCore(
codeForTask1,
"Task1",
1000,
NULL,
1,
&Task1,
1);
// delay(500); // needed to start-up task1
//delay(100);
xTaskCreatePinnedToCore(
codeForTask2,
"Task2",
1000,
NULL,
1,
&Task2,
0);
delay(100);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
}
void loop() {
delay(1);
}
Now I am operating a DF Player with 2 of the inputs with the core 0 and rest 2 inputs for second DF Player via core 1
Now when I Start the operation to play files pressing buttons randomly for both the core at same time, its working fine for some 5 seconds approx
After that suddenly the system stops responding for 1 or 2 seconds and then the original process retrieves
Again same 5 seconds play and then 1 or 2 seconds gap
and it continues . . . . .
While the process getting out of order for a second, I noticed that, it seems like both the cores are interrupting or cancelling each other or say fighting with each other
So is this an issue which is related to my code above or it's the DF player or the memory card unit ????
Please Comment and help me in solving
Thanks !!!