0

I am building a project with Arduino Nano and the component in the subject, which, as far as I understand, can be assimilated to a DFPlayerMini (not sure if it's the same thing or it's just a cheap knockoff).

Following one of the millions of tutorials on the net I managed to make it work, I can correcly play audio files out of an SD card, but the weird thing is, that it only works while I'm connected to the Arduino with the serial monitor open on my IDE: the moment I close the IDE and power everything via Vin or via any other means - including USB power from the PC - it fails to do anything.

If this can be helpful, the wiring is as follows (taken from the instructables website where I found the first tutorial) Basic DFPlayer Wiring

And the code running everything is the following

main.cpp

#include <Arduino.h>
#include <modules/Sound.h>

#define BTN 3
#define TX 10
#define RX 11

Sound sound(TX, RX);

void setup() {
  Serial.begin(9600);
  Serial.println("Init");
  pinMode(BTN, INPUT);
  
  if (!sound.init()) {
    Serial.println("Nope");
  }

  sound.playInitSound();
}

void loop() {
  // unrelated stuff
}

modules/Sound.h

#include <Arduino.h>
#include <DFRobotDFPlayerMini.h>
#ifndef __SOUND__
#define __SOUND__

#define SOUND_POWER_UP   1
#define SOUND_POWER_DOWN 2

class Sound {
    public:
        Sound(uint8_t txPin, uint8_t rxPin);
        boolean init();
        void playInitSound();
    protected:
        DFRobotDFPlayerMini soundboard;
        uint8_t txPin;
        uint8_t rxPin;
};

#endif

modules/Sound.cpp

#include <Arduino.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
#include "modules/Sound.h"

Sound::Sound(uint8_t txPin, uint8_t rxPin) {
    this->txPin = txPin;
    this->rxPin = rxPin;
}

boolean Sound::init() {
    SoftwareSerial mySerial(txPin, rxPin);
    mySerial.begin(9600);
    boolean working = soundboard.begin(mySerial);
    if (working) {
        soundboard.volume(10);
    }
    return working;
}

void Sound::playInitSound() {
    soundboard.play(SOUND_POWER_UP);
}

As I said, everything works as long as I'm connected to the serial monitor from the IDE (if it's any relevant, I'm using PlatformIO on VSCode, on Linux).

I also tried to use the if (!sound.init()) part to make the arduino LED cyclically blink if there is a failure, and indeed it starts blinking.

Any thought? Any way I can add more info to help troubleshooting?

EDIT:

I tried removing all instances of usage of the Serial but it doesn't help

I started thinking that maybe it was a faulty Arduino, so I switched to another controller and this one behaves a bit differently: the sound module gets initialized (I don't see the blinking led that would mean failure) but no sound is played.

The main difference between the two controllers is that the "faulty" one has the new bootloader, the one that is partially working has the old bootloader instead. Not sure if this is meaningful in the least.

EDIT 2:

The arduino with the old bootloader works just fine, beats me why

5
  • @jsotola Sadly, it does not help. I removed all Serial stuff and it still does not work if not plugged to the serial monitor. The situation changes a bit when changing the controller though. I'm updating the post to reflect these last findings.
    – Luca
    Apr 16, 2022 at 17:50
  • this part is confusing ... the moment I close the IDE and power everything via Vin or via any other means - including USB power from the PC - it fails to do anything .... does the failure occur simply by closing the IDE program? ... is it the powering by Vin that causes the failure?
    – jsotola
    Apr 16, 2022 at 18:10
  • @jsotola any way I power it, be it via Vin or via USB the problem occurs. I'm beginning to think that it's the board that's defective, because the other one I have seems to be working just fine
    – Luca
    Apr 16, 2022 at 19:31
  • I'm having the same problem. Did you find a way to make it work?
    – user86864
    Sep 29, 2022 at 3:42
  • @user86864 sadly, no. I am convinced that the board is defective. Any other board works. I suggest getting a new board, maybe a cheap one, and try it out
    – Luca
    Sep 30, 2022 at 12:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.