Go Down

Topic: Keep struggling with DFPlayer. Faulty module? (Read 1 time) previous topic - next topic

Agatsuma

I cant get it to work as intended. It almost always fails to play sound second time in second condition block. arduino gets there (controlled with serial responses), command get sent, but player do not play sound. And if I send Loop command, then whatever file number I send is ignored and DFPlayer loops last played file.

Maybe Im blind and there is an error in my code, but sometimes it plays sound second time as it should.

I have 1KOhm resistor in Tx-Rx line.

Faulty module?

Code: [Select]
#include <DFRobotDFPlayerMini.h>

#include <SoftwareSerial.h>

SoftwareSerial ss(4,5);

DFRobotDFPlayerMini mp3;

#define SWITCH_PIN 10

float soundTimer=0;
long startMillis=0;
int playingSound = 0;

void setup() {       
 
  pinMode(SWITCH_PIN,INPUT_PULLUP);
 
  Serial.begin(9600);
  ss.begin(9600);

 
  while(!mp3.begin(ss)){
  }
 
  mp3.volume(30);
  delay(200);
 
}


void loop() {

  if(digitalRead(SWITCH_PIN) == LOW && playingSound == 0)
  {
    mp3.play(1);
    delay(200);
    playingSound = 1;
    soundTimer = 1626;
    startMillis = millis();
  }

  if(playingSound == 1 && millis()-startMillis > soundTimer)
  {
    mp3.play(1);
    delay(200);
    playingSound = 2;
    soundTimer = 1626;//1826
    startMillis = millis();
  }
 
}

Agatsuma

Forgot to mention important thing, audio file being played is 1836 ms long, so second play command sent while there is still 10ms of first file left. The goal is to play them seamlessly.

Agatsuma

Forr anyone who encountered same problem, it seems that 10ms before end of the playback is too smal of an interval. Made it 20ms, so I start new play after 1816 ms of playback of a 1836 ms file, and it works. Seamless playback of two files.

Agatsuma

After more testing 25-30 ms overlap seems to be more stable.

Go Up