DFplayermini X Bluetooth Mp3 Player Control
by CarlosVoltT in Circuits > Arduino
78 Views, 0 Favorites, 0 Comments
DFplayermini X Bluetooth Mp3 Player Control
In this tutorial we will see how to make an MP3 file player with the DFplayer mini module, Arduino and a 128x32 OLED display.
More info and updates in https://rogerbit.com/wprb/2022/12/dfplayermini-x-bluetooth/
In this tutorial we will see how to make an MP3 file player with the DFplayer mini module, Arduino and a 128x32 OLED display. We will see how to assemble the printed circuit, provided by PCBWay, we will analyze the source code, and finally we will test how the device works.
If you want to play your music on a private beach or at meetings, this MP3 player with DFplayer module and Arduino is perfect for you. It includes a printed circuit so you can build it yourself.
If you want to play your music on a private beach or at meetings, this MP3 player with DFplayer module and Arduino is perfect for you. It includes a printed circuit so you can build it yourself. With it you can play MP3s.
Female pins
Socket for arduino nano
A 1 Kohm resistor
OLED display sh1106
This is a 128x64 dot monochrome OLED display module with I2C interface. It has several advantages over LCD displays, such as high brightness, very good contrast, a wider viewing angle, and low power consumption. It is compatible with Arduino Rasberry Pi and PIC microcontrollers among others. It works with logic levels from 3.3V to 5V and has a viewing angle greater than 160 degrees. The screen size is 1.3 inches. It is powered by a voltage of 3.3V to 5V. It can be used in applications such as smart watches, MP3, thermometers, instruments, and various projects, etc.
Bookshop
Characteristics
- Interface: I2C (3.3V / 5V logic level)
- Resolution: 128 x 64
- Angle of view: >160 degrees
- Display color: Blue
- Display size: 1.3 inch
- Driver IC: SH1106
- Power supply: DC 3.3V~5V
- Operating temperature: -20~70'C
- Application: smart watch, MP3, thermometer, instruments, DIY projects, etc.
Seven push buttons
A micro SD card
hc-05 modules
- Works as a bluetooth master and slave device
- Configurable via AT commands
- Bluetooth V2.0+EDR
- Operating frequency: 2.4 GHz ISM band
- Modulation: GFSK (Gaussian Frequency Shift Keying)
- Transmit power: <=4dBm, Class 2
- Sensitivity: <=-84dBm @ 0.1% BER
- Security: Authentication and encryption
- Bluetooth profiles: Bluetooth serial port.
- Distance of up to 10 meters in optimal conditions
- Operating Voltage: 3.6 VDC to 6 VDC
- Current Consumption: 30 mA to 50 mA
- Chip: BC417143
- Version or firmware: 3.0-20170609
- Default Baud: 38400
- Supported baud rates: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200.
- Interface: Serial TTL
- Antenna: Integrated into the PCB
- Security: Authentication and encryption (Default password: 0000 or 1234)
- Working temperature (Max): 75°C
- Working temperature (Min): -20°C
- Dimensions: 4.4 x 1.6 x 0.7 cm
PCB
Download gerber file —> gerbermp3dfplayer
Circuit
Source Code
#include "U8glib.h"//Librería para el control del display oled
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE);// I2C / TWI Se habilita esta linea según el display a usar en este caso el driver SH1106
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
String texto = "";
int vol = 10;
String cadena;
SoftwareSerial mySoftwareSerial(10, 11); // RX, TX pines por software para la comunicación con el módulo dfplayer mini
DFRobotDFPlayerMini myDFPlayer;
int play_d2 = 2;
int pause_d9 = 9;
int stop_d4 = 4;
int next_d5 = 5;
int prev_d6 = 6;
int voltmas_d7 = 7;
int volmenos_d8 = 8;
int estado_pausa = 0;
void setup()
{
mySoftwareSerial.begin(9600);
Serial.begin(9600);//Velocidad del módulo bluetooth
pinMode(play_d2, INPUT_PULLUP);
pinMode(pause_d9, INPUT_PULLUP);
pinMode(stop_d4, INPUT_PULLUP);
pinMode(next_d5, INPUT_PULLUP);
pinMode(prev_d6, INPUT_PULLUP);
pinMode(voltmas_d7, INPUT_PULLUP);
pinMode(volmenos_d8, INPUT_PULLUP);
Serial.println();
Serial.println(F("Inicializando DFPlayer mini"));
if (!myDFPlayer.begin(mySoftwareSerial)) { //Usa softwareSerial para communicarte con el módulo mp3.
Serial.println(F("No es posible iniciar:"));
Serial.println(F("1.Comprueba las conexiones"));
Serial.println(F("2.Por favor inserte una tarjeta SD"));
while(true);
}
Serial.println(F("DFPlayer Mini online."));
myDFPlayer.volume(vol); //Se setea el volumen
//Se mostrará el siguente texto en el display
texto = "NO TRACK";
oled();
}
void loop()
{
while (Serial.available()) {
delay(3);
char c = Serial.read();
cadena += c;
}
//Lectura del estado de los pulsadores
int boton_play = digitalRead(play_d2);
int boton_pause = digitalRead(pause_d9);
int boton_stop = digitalRead(stop_d4);
int boton_next = digitalRead(next_d5);
int boton_prev = digitalRead(prev_d6);
int boton_volmas = digitalRead(voltmas_d7);
int boton_volmenos = digitalRead(volmenos_d8);
//Si se aprieta el botón de play se cumple
if(boton_play == LOW || cadena == "play"){
delay(100);
myDFPlayer.enableLoopAll();
myDFPlayer.play();
texto = "PLAY";//Se mostrará el siguente texto en el display
oled();
}
//Pone en pausa el track de música
if(boton_pause == LOW || cadena == "pause"){
if(estado_pausa == 0){
delay(200);
myDFPlayer.pause();
texto = "PAUSE";
oled();
estado_pausa = 1;
}else{
delay(200);
myDFPlayer.start();//Vuelve a iniciar el tema donde quedó la pausa
texto = "PLAY";
oled();
estado_pausa = 0;
}
}
//Para el track de música que se estaba repoduciendo
if(boton_stop == LOW || cadena == "stop"){
delay(100);
myDFPlayer.stop();
texto = "STOP";
oled();
}
//Reproduce el próximo tack de música
if(boton_next == LOW || cadena == "next"){
delay(100);
myDFPlayer.next();
texto = "NEXT";
oled();
delay(500);
texto = "PLAY";
oled();
}
//Reproduce el anterior tack de música
if(boton_prev == LOW || cadena == "prev"){
delay(100);
myDFPlayer.previous();
texto = "PREV";
oled();
delay(500);
texto = "PLAY";
oled();
}
//Incrementa el vólumen hasta 35 como máximo
if(boton_volmas == LOW || cadena == "volmas"){
delay(100);
if(vol <35){
myDFPlayer.volumeUp();
vol = vol + 1;
oled();
}
}
//Decrementa el vólumen hasta 0 como mínimo
if(boton_volmenos == LOW || cadena == "volmenos"){
delay(100);
if(vol >0){
myDFPlayer.volumeDown();
vol = vol - 1;
oled();
}
}
//Habilita la reproducción la aleatoria
if(cadena == "random"){
delay(100);
myDFPlayer.randomAll();
texto = "RANDOM";
oled();
}
//Habilita la reproducción en bucle
if(cadena == "eloop"){
delay(100);
myDFPlayer.enableLoopAll();
texto = "E.LOOP";
oled();
}
//deshabilita la reproducción en bucle
if(cadena == "dloop"){
delay(100);
myDFPlayer.disableLoopAll();
texto = "D.LOOP";
oled();
}
//Funciones de equalizador
//Habilita Normal
if(cadena == "normal"){
delay(100);
myDFPlayer.EQ(DFPLAYER_EQ_NORMAL);
texto = "NORMAL";
oled();
}
//Habilita Pop
if(cadena == "pop"){
delay(100);
myDFPlayer.EQ(DFPLAYER_EQ_POP);
texto = "POP";
oled();
}
//Habilita Rock
if(cadena == "rock"){
delay(100);
myDFPlayer.EQ(DFPLAYER_EQ_ROCK);
texto = "ROCK";
oled();
}
//Habilita Jazz
if(cadena == "jazz"){
delay(100);
myDFPlayer.EQ(DFPLAYER_EQ_JAZZ);
texto = "JAZZ";
oled();
}
//Habilita Classic
if(cadena == "classic"){
delay(100);
myDFPlayer.EQ(DFPLAYER_EQ_CLASSIC);
texto = "CLASSIC";
oled();
}
//Habilita Bass
if(cadena == "bass"){
delay(100);
myDFPlayer.EQ(DFPLAYER_EQ_BASS);
texto = "BASS";
oled();
}
if(cadena != ""){
cadena = "";
}
}
//Funcíon para mostrar texto en el dislplay oled
void oled(){
u8g.firstPage();
do {
draw();//Llama a la función draw
} while( u8g.nextPage() );
// Reconstruir la imagen después de un tiempo
delay(50);
}
void draw(void) {
//Imprimimos en pantalla
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(0, 20);
u8g.print("REPRODUCTOR MP3");//
//Muestra la palabra ESTADO
u8g.setPrintPos(0, 40);
u8g.print("ESTADO: ");//
u8g.setPrintPos(55, 40);
u8g.print(texto);//Estado de reproducción del track de música PLAY STOP PAUSE
//Muestra la palabra de VOLUMEN
u8g.setPrintPos(0, 60);
u8g.print("VOLUMEN:");
u8g.setPrintPos(65, 60);
u8g.print(vol);//Muestra el incremento o decremento del volumen de reproducción
}