Leia também!
Home / Ferramentas / Arduíno / DFPlayer módulo mp3 player para Arduíno

DFPlayer módulo mp3 player para Arduíno

Arduíno é uma plataforma de código aberto que facilita a montagem e prototipagem de projetos. Até agora você deve saber que o Arduíno pode acender Leds, Girar motores, receber tensão analógica, Imprimir valores em um display de LCD, e agora finalmente tocar MP3 com o módulo DFPlayer.

wpid-img_20150826_192819.jpg

Este é o módulo.

wpid-img_20150826_192857.jpg

Possui entrada para cartão microSD. Possui também uma entrada USB e de áudio analógico auxiliar, mas não tem os conectores. Não testei, mas acho que seria possível soldar um conector e fazer isso funcionar!

wpid-img_20150826_192919.jpg

O módulo tem dois chips, acredito eu que seja um decoder MP3 e um amplificador estéreo, até 3W!

wpid-img_20150826_192928.jpg

Abaixo a pinagem. Olhá só o DAC_R, DAC_L para entrada analógica e o USB- e USB+ para a entrada USB. Quem quiser pode ler o datasheet e tentar entender para que serve cada pino.

arduino mp3 pinout

Para ligar ao Arduíno UNO eu usei esta pinagem.

arduino mp3

Baixei a biblioteca DFPlayer-Mini-mp3 e tentei rodar os programas exemplo. Todos uma droga. Eu resolvi então fazer meu próprio programa exemplo usando a biblioteca:

#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup () {
Serial.begin (9600);
mySerial.begin (9600);
mp3_set_serial (mySerial); //set softwareSerial for DFPlayer-mini mp3 module
delay(10); // delay 1ms to set volume

mp3_reset();
delay(1000);

mp3_set_volume (10); // value 0~30
delay(10);

}
void loop () {
if (Serial.available()) {
char command = Serial.read();

switch (command) {
case ‘S’:
mp3_stop();
delay(10);
break;
case ‘N’:
mp3_next();
delay(10);
break;
case ‘P’:
mp3_prev();
delay(10);
break;
}
}
}

Com o programa que fiz, o MP3 player toca arquivos do cartão SD na ordem que eles estão gravados. Para tocar basta abrir o Monitor Serial em 9600 e enviar “N” para a próxima música e “P” para a anterior. Funcionou! Veja abaixo a minha ligação. Deixei dois fios soltos para ligar ao alto-falante, que no meu caso foi um fone de ouvido. Eu simplesmente encostei no conector do fone, em apenas um dos lados, para ouvir que estava funcionando.

wpid-wp-1440632748801.jpeg

A biblioteca é uma droga, mas a plaquinha funcionou. Não consegui receber via serial o nome da música, ou qualquer outra informação, mas consegui aumentar e abaixar o volume, tocar aleatoriamente e em loop. Muito legal, pena que o suporte seja horrível.

Deixo abaixo o link para o produto e para o datasheet, se alguém quiser fazer uma nova biblioteca:

Produto – http://www.banggood.com/DFPlayer-Mini-MP3-Player-Module-For-Arduino-p-969191.html

Datasheet – http://www.dfrobot.com/wiki/index.php/DFPlayer_Mini_SKU:DFR0299

Sobre Adriano

Professor, Engenheiro e comprador de produtos malucos da China.

11 Comentários

  1. I have the same problem with DFPlayer and Arduino Due:
    My problem: I bought some Mini-MP3-Players and my son compiled the Software “Get Started” (in “DFPlayer Mini SKU DFR0299 – DFRobot Electronic Product Wiki and Tutorial Arduino and Robot Wiki-DFRobot.com.htm” without any Problem for Arduino UNO. He said, Arduino DUE is better, so I bought a DUE. With the following result:
    The compilation of (it is the shrinked “Get Started”!):
    **************************************************
    #include “Arduino.h”
    #include “SoftwareSerial.h”
    #include “DFRobotDFPlayerMini.h”

    SoftwareSerial mySoftwareSerial(10, 11); // RX, TX
    //DFRobotDFPlayerMini myDFPlayer;
    //void printDetail(uint8_t type, int value);
    void setup() {
    // put your setup code here, to run once:
    }
    void loop() {
    // put your main code here, to run repeatedly:
    }
    **************************************************
    results with error:
    sketch\sketch_nov14a.ino.cpp.o: In function `__static_initialization_and_destruction_0′:
    C:\Users\Gerd\Documents\Arduino\sketch_nov14a/sketch_nov14a.ino:5: undefined reference to `SoftwareSerial::SoftwareSerial(unsigned char, unsigned char, bool)’
    C:\Users\Gerd\Documents\Arduino\sketch_nov14a/sketch_nov14a.ino:5: undefined reference to `SoftwareSerial::~SoftwareSerial()’
    collect2.exe: error: ld returned 1 exit status

    It’s okay, because in SoftwareSerial.h:

    public:
    // public methods
    SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);

    there are three terms (rec.Pin, trans.Pin, inverse_l.), but in “Get Started” there are only two terms (SoftwareSerial mySoftwareSerial(10, 11); // RX, TX)

    My Problem: Why for Ard. UNO it’s compiled with no errors, but for Ard. DUE with errors. Is it another library? What can I do?

  2. bonjour a tous

    j’aimerai reussir a lire en boucle mes 4 fichiers mp3 pour une maquette forraine je ne trouve pas comment faire .Je veux simplement un bout code qui ordonne de lire a la suite mes fichiers MP3
    Merci de votre aide voici le code que j’ai mis mais ca ne me conviens pas .#include
    #include

    SoftwareSerial DFPlayerSerial( 10, 11 ); // RX, TX

    void setup()
    {
    Serial.begin( 115200 );
    Serial.print( “\n\nDFPlayer_Mini_Mp3\n” );

    DFPlayerSerial.begin( 9600 );
    mp3_set_serial( DFPlayerSerial );
    mp3_set_device( 2 ); // Carte SD
    mp3_set_volume( 30 ); // 0-30
    mp3_single_loop (true); // Joue fichier en boucle
    }

    void loop()
    {
    mp3_next();
    _delay_ms( 78000 );
    }

  3. Der DFPlayer läuft problemlos mit dem Arduino Mega2560.
    Mit dem Arduino Due geht die Softserial-Bibliothek nicht.
    Habe versucht die Funktionen aus der DFPlayer_Mini_Mp3 mit dem Serial2.print über TX2-Port16 am Due auszugeben. Danach noch ein Test mit der soft_uart_serial-Library uber TX=11 und RX=10.
    Habe dort 9600Baud und Sende-Länge 64Bit eingestellt und die Vorbelegung der Variable send_buf[10] aus der DFPlayer_Mini_Mp3.h übernommen. Irgendwie klappt da nichts.

    Will lieber mit dem Due arbeiten, da er besser für größere Projekte geeignet ist.
    Hat da jemand von Euch schon mal was in der Richtung probiert?

    Tschau …Ulf

    • No. I have only tested with Arduino Uno. This module is a complete mp3 player, so there is no need to use Arduino’s processor. Any Arduino will do fine.

    • perigalacticon

      Did you ever get this to work with the Due? I am using Due for a large robot project and would like to use this mp3 player. I get errors about software serial and the serial buffer also but don’t know the fix. Does someone have an updated library?

      Thanks.

  4. Adorei seu tutorial, me ajudou a entender esse shield. Como eu faço para ele executar uma musica específica. Exemplo, quero que ele execute a música 001.mp3.
    Usei essa linha de comando e não deu certo:
    case ‘P’:
    mp3_play(1);
    delay(10);
    break;

    Quando coloco “N” funciona normalmente. Mas quero em uma lista que ele execute apenas a música específica.

    Tem como me ajudar?

Deixe um Comentário para Adriano Moutinho Cancelar resposta

Seu endereço de e-mail não será publicado. Campos Obrigatórios *

*