Thank you
I understand what you say although I think that's not the issue because we also tried this configuration (the picture "wiring") and it didn't work.
I tried the new library and it actually works way better, thank you for the recommendation. The sleeping function doesn't work though, I find it a bit weird. The power consumption is 280mA, both when it plays and when it allegedly sleeps. I added down here the parts in the code which involves the sleeping function of the DFPlayer, it is not my full code and therefore the code down here might look a bit weird. It goes with the picture which I called "wiring 2"). I suppose I made the sleeping function good, there's not much place for mistakes here, so why does my DFPlayer consumes almost 300mA when it sleeps ?
#include <DFPlayerMini_Fast.h>
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "LowPower.h"
DFPlayerMini_Fast myDFPlayer;
const int wakeUpPin = 2;
int buttonStart = 3 ;
int transistorPin = 8 ;
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX 11 Resistor
int switchFolderButton = 12 ;
boolean sleeping = true ;
boolean countingDown = false ;
int randomNumber ;
boolean playShort = true ;
int numberFilesLongFolder ;
int numberFilesShortFolder ;
static unsigned long timer ;
static unsigned long busyCount;
int busyCountInterval = 5000 ;
int sleepingCountInterval = 5000 ;
int busyState ;
//start
void playRandom (int folder, int randomNumber) {
myDFPlayer.playFolder(folder, randomNumber); //Play file
}
//switch folder from short file -> long file or long -> short
void switchDirectory () {
playShort = !playShort ;
}
void wakeUp()
{
}
void setup()
{
Serial.begin (4800) ;
mySoftwareSerial.begin(9600);
myDFPlayer.begin (mySoftwareSerial) ;
pinMode(wakeUpPin, INPUT);
digitalWrite (wakeUpPin, HIGH) ;
pinMode (buttonStart, INPUT) ;
digitalWrite (buttonStart, HIGH);
pinMode (switchFolderButton, INPUT) ;
digitalWrite (switchFolderButton, HIGH);
pinMode (transistorPin, OUTPUT) ;
digitalWrite (transistorPin, LOW);
busyCount = 0 ;
}
void loop()
{
attachInterrupt(0, wakeUp, LOW);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
detachInterrupt(0);
// wake up & start
if (!digitalRead (wakeUpPin) && sleeping) {
delay (50) ;
if (!digitalRead (wakeUpPin) && sleeping) {
digitalWrite (wakeUpPin, LOW) ;
digitalWrite (transistorPin, HIGH);
// it doesn't work if the command shows up only once
numberFilesShortFolder = myDFPlayer.numTracksInFolder(1) ;
numberFilesLongFolder = myDFPlayer.numTracksInFolder(2) ;
numberFilesShortFolder = myDFPlayer.numTracksInFolder(1) ;
numberFilesLongFolder = myDFPlayer.numTracksInFolder(2) ;
sleeping = false ;
if (playShort) {
randomNumber = random (1, (numberFilesShortFolder + 1)) ;
playRandom(1, randomNumber) ;
}
else {
randomNumber = random (1, (numberFilesLongFolder + 1) ) ;
playRandom(2, randomNumber); //Play file
}
delay (200) ;
}
}
if (!digitalRead(buttonStart) ) {
delay (50) ;
if (!digitalRead(buttonStart) ) {
if (playShort) {
randomNumber = random (1, numberFilesShortFolder + 1) ;
playRandom(1, randomNumber) ;
}
else {
randomNumber = random (1, numberFilesLongFolder + 1) ;
playRandom(2, randomNumber); //Play file
}
delay (200) ;
}
}
}
}
//switch folder
if (!digitalRead(switchFolderButton) ) {
delay (50) ;
if (!digitalRead(switchFolderButton) ) {
switchDirectory () ;
delay (200) ;
}
}
//making the arduino go to sleep when the file ends / stopped for a while
if (millis () - busyCount >= busyCountInterval ) {
busyCount = millis () ;
busyState = digitalRead (busy) ;
}
if (busyState && !countingDown) {
timer = millis () ;
countingDown = true ;
}
//without this delay the file don't stop after a file ended
delay (10) ;
//go to sleep
if (busyState && millis () - timer > sleepingCountInterval ) {
sleeping = true ;
timer = millis () ;
digitalWrite (transistorPin, LOW);
digitalWrite (wakeUpPin, HIGH) ;
}
}
Thank you all very much )

