Mini MP3 Player Using DFPlayer Mini Mp3 Module with 2.8″ TFT Touch Screen LCD

Overview

This project aims to create a simple MP3 player using the DFPlayer Mini MP3 module and display the songs being played on a TFT Touch Screen LCD display. The device is capable of Pause and Play operations, Next and Previous song selection, with a simple interface that displays the current song playing.

Hardware Used

  • Arduino Uno

  • 2.8″ TFT Touch Screen LCD 240 x 320
  • DFPlayer Mini Mp3 Module
  • 
    
  • LM386 Audio  Module
  • 
    
  • 0.5W 8Ω Speaker
  • Software Used

    Library Used

    Descriptions

    DFPlayer Mini Mp3 Module

    The DFPlayer Mini MP3 Player For Arduino is a small and low price MP3 module with an simplified output directly to the speaker. The module can be used as a stand alone module with attached battery, speaker and push buttons or used in combination with an Arduino UNO or any other microcontroller with UART RX/TX capabilities. It is also applicable to other voice prompt related projects such as car navigation voice broadcast, road transport inspectors, toll station voice prompts, railway station, bus safety inspection voice prompts, and voice prompts for business halls of electricity, communications, and financial business.
    • supported sampling rates (kHz): 8/11.025/12/16/22.05/24/32/44.1/48
    • 24 -bit DAC output, support for dynamic range 90dB , SNR support 85dB
    • fully supports FAT16 , FAT32 file system, maximum support 32G of the TF card, support 32G of U disk, 64M bytes NORFLASH.
    • a variety of control modes, I/O control mode, serial mode, AD button control mode
    • advertising sound waiting function, the music can be suspended. when advertising is over in the music continue to play
    • audio data sorted by folder, supports up to 100 folders, every folder can hold up to 255 songs
    • 30 level adjustable volume, 6 -level EQ adjustable

    2.8″ TFT LCD Display

    2.8 TFT LCD Display Module with Touch - Click Image to Close

    2.8 inch TFT LCD display with SPI interface using the ILI9341 driver chip. Screen resolution – 240×320 colour pixels.
    Touch responsive screen compatible with the URTouch Arduino library.
    Graphics compatible with Adafruit_GFX with Adafruit_ILI9341 Arduino libraries.
    STM32 compatible.
    Uses 3.3V logic and supply.

    LM386 Audio Amplifier Module

    Image result for lm386 audio amplifier module arduino

    The LM386 Audio Amplifier Module is a mono audio amplifier based on the LM386 chip. It operates on a voltage range between 4 V and 12 V. It has an absolute maximum rating of 15 V.

    The LM386M version of the chip will provide a typical output of 325 mW, when the supply voltage is 6 V and the speaker load 8 Ω. A 9 V battery power supply will provide an output of around 500 mW. it provides a gain of 200. if you want to adjust the gain, and hence the volume, just rotate the trimmer clockwise or counter clockwise.

     

    Hardware Set-Up

    Schematic Diagram

    In building the circuit we will be needing 1k ohm resistor for the RX or  the TX part for noise reduction for the audio . Then for the LCD we will be needing 10k ohm resistor since the LCD is 3.3V logic level  and unfortunately it is not 5V tolerant. So, we need to use some 10K resistor if we want to drive it with a board that uses 5V logic levels like the Arduino Uno.
    DFPlayer_Mini_Pin
    This is the Pinout for the DFPlayer Mini
    This the Actual Circuit for the System.

    Software Set-up

    Code:

    #include "Arduino.h"
    #include <SoftwareSerial.h>
    #include <DFMiniMp3.h>
    #include "Adafruit_ILI9341.h" 
    #include <URTouch.h>          
    #include <Adafruit_GFX.h>    // Core graphics library
    #include <Adafruit_TFTLCD.h> // Hardware-specific library
    #include <SPI.h>
    
    
    class Mp3Notify
    {
    public:
      static void OnError(uint16_t errorCode)
      {
        // see DfMp3_Error for code meaning
        Serial.println();
        Serial.print("Com Error ");
        Serial.println(errorCode);
      }
    
      static void OnPlayFinished(uint16_t globalTrack)
      {
        Serial.println();
        Serial.print("Play finished for #");
        Serial.println(globalTrack);
      }
    
      static void OnCardOnline(uint16_t code)
      {
        Serial.println();
        Serial.print("Card online ");
        Serial.println(code);     
      }
    
      static void OnUsbOnline(uint16_t code)
      {
        Serial.println();
        Serial.print("USB Disk online ");
        Serial.println(code);     
      }
    
      static void OnCardInserted(uint16_t code)
      {
        Serial.println();
        Serial.print("Card inserted ");
        Serial.println(code); 
      }
    
      static void OnUsbInserted(uint16_t code)
      {
        Serial.println();
        Serial.print("USB Disk inserted ");
        Serial.println(code); 
      }
    
      static void OnCardRemoved(uint16_t code)
      {
        Serial.println();
        Serial.print("Card removed ");
        Serial.println(code);  
      }
    
      static void OnUsbRemoved(uint16_t code)
      {
        Serial.println();
        Serial.print("USB Disk removed ");
        Serial.println(code);  
      }
    };
    // instance a DFMiniMp3 object, 
    // defined with the above notification class and the hardware serial class
    //
    //DFMiniMp3<HardwareSerial, Mp3Notify> mp3(Serial1);
    
    // Some arduino boards only have one hardware serial port, so a software serial port is needed instead.
    // comment out the above definition and uncomment these lines
     SoftwareSerial mySoftwareSerial(A0, A1); // RX, TX
    DFMiniMp3<SoftwareSerial, Mp3Notify> mp3(mySoftwareSerial);
    
    #define TFT_DC 9              
    #define TFT_CS 10            
    #define TFT_RST 8
    #define TFT_MISO 12         
    #define TFT_MOSI 11           
    #define TFT_CLK 13            
    
    
    #define t_SCK 3              
    #define t_CS 4                
    #define t_MOSI 5              
    #define t_MISO 6             
    #define t_IRQ 7   
    
    #define TS_MINX 204
    #define TS_MINY 195
    #define TS_MAXX 948
    #define TS_MAXY 910  
    
    
    URTouch ts(t_SCK, t_CS, t_MOSI, t_MISO, t_IRQ);
    
    Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
    Adafruit_GFX_Button buttons[9];
    
    int x,y;
    
    char NEXT[5] = {"NEXT"};
    char PREV[5] = {"PREV"};
    char PAUSE[5] = {"||"};
    char PLAY[5] = {"PLY"};
    extern uint8_t myBitmap[];
    
    void waitfortouch(unsigned short int *x,unsigned short int *y){
      do
      {    
        delay(10);
        if (ts.dataAvailable() == true)
        {
          ts.read();
          *x = ts.getX();  //Get touch point  
          *y = ts.getY();
          return;
          }
      }while(ts.dataAvailable()==false); 
    }
    
    void setup() 
    {
       mySoftwareSerial.begin(9600);//initialization for Software Serial
      Serial.begin(115200); // This is the standard baud rate for the Mp3 player
    
      Serial.println("initializing...");
      
      tft.begin();  //initialization for tft lcd                   
      tft.setRotation(3); // set orientation of the display rotation 3 for landscape          
      ts.InitTouch();    //initialize touch Screen               
      ts.setPrecision(PREC_EXTREME); //set precision on reading data
      tft.fillScreen(ILI9341_BLACK);
      
      drawBitmap(0,0, myBitmap,320, 240,ILI9341_WHITE);
      
      mp3.begin();
    
      uint16_t volume = mp3.getVolume();
      Serial.print("volume ");
      Serial.println(volume);
      mp3.setVolume(15);
      
      uint16_t count = mp3.getTotalTrackCount();
      Serial.print("files ");
      Serial.println(count);
      
      Serial.println("starting...");
     mp3.playRandomTrackFromAll();
     ControlBots();
     
      
    }
    
    void loop() 
    {  
      trcknms();
    
       waitfortouch(&x,&y); 
       if (buttons[0].contains(x,y)) 
        {    
         mp3.nextTrack();
        
          }
          
       else if (buttons[1].contains(x,y))
        {  
            mp3.prevTrack(); 
        }
         else if (buttons[2].contains(x,y))
        {
           mp3.pause();
        }
         else if (buttons[3].contains(x,y))
        {
            mp3.start();
        } 
        
    }
    
    void ControlBots()
      {
        buttons[0].initButton(&tft,50,220,60,40,ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE,
                          NEXT, 2); 
              buttons[0].drawButton();
      buttons[1].initButton(&tft, 260,220,60,40,ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE,
                          PREV, 2); 
              buttons[1].drawButton();
      buttons[2].initButton(&tft,120,220,60,40,ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE,
                          PAUSE, 2); 
              buttons[2].drawButton();  
      buttons[3].initButton(&tft,190,220,60,40,ILI9341_WHITE, ILI9341_RED, ILI9341_WHITE,
                          PLAY, 2); 
              buttons[3].drawButton();  
      }
    void trcknms()
    {
      uint16_t curr = mp3. getCurrentTrack();
      if (curr == 1)
      { tft.setCursor(0,30);
        tft.setTextColor(ILI9341_RED, ILI9341_WHITE); 
        tft.setTextSize(3); 
        tft.print ("  DESPACITO         ");
        }
        if (curr == 2)
      { tft.setCursor(0,30);
        tft.setTextColor(ILI9341_RED, ILI9341_WHITE); 
        tft.setTextSize(3); 
        tft.print ("THATS WHAT I LIKE");
        }
        if (curr == 3)
      { tft.setCursor(0,30);
        tft.setTextColor(ILI9341_RED, ILI9341_WHITE); 
        tft.setTextSize(3); 
        tft.print ("  I'M THE ONE        ");
        }
    
       if (curr == 4)
      { tft.setCursor(0,30);
        tft.setTextColor(ILI9341_RED, ILI9341_WHITE); 
        tft.setTextSize(3); 
        tft.print ("   HUMBLE            ");
        }
         if (curr == 5)
      { tft.setCursor(0,30);
        tft.setTextColor(ILI9341_RED, ILI9341_WHITE); 
        tft.setTextSize(3); 
        tft.print ("  SHAPE OF YOU       ");
        }
    }
    void drawBitmap(int16_t x, int16_t y,
     const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) {
    
      int16_t i, j, byteWidth = (w + 7) / 8;
      uint8_t byte;
    
      for(j=0; j<h; j++) {
        for(i=0; i<w; i++) {
          if(i & 7) byte <<= 1;
          else      byte   = pgm_read_byte(bitmap + j * byteWidth + i / 8);
          if(byte & 0x80) tft.drawPixel(x+i, y+j, color);
        }
      }
    }

    This is the entire code for the system.

    Code Breakdown

    class Mp3Notify
    {
    public:
      static void OnError(uint16_t errorCode)
      {
        // see DfMp3_Error for code meaning
        Serial.println();
        Serial.print("Com Error ");
        Serial.println(errorCode);
      }
    
      static void OnPlayFinished(uint16_t globalTrack)
      {
        Serial.println();
        Serial.print("Play finished for #");
        Serial.println(globalTrack);
      }
    
      static void OnCardOnline(uint16_t code)
      {
        Serial.println();
        Serial.print("Card online ");
        Serial.println(code);     
      }
    
      static void OnUsbOnline(uint16_t code)
      {
        Serial.println();
        Serial.print("USB Disk online ");
        Serial.println(code);     
      }
    
      static void OnCardInserted(uint16_t code)
      {
        Serial.println();
        Serial.print("Card inserted ");
        Serial.println(code); 
      }
    
      static void OnUsbInserted(uint16_t code)
      {
        Serial.println();
        Serial.print("USB Disk inserted ");
        Serial.println(code); 
      }
    
      static void OnCardRemoved(uint16_t code)
      {
        Serial.println();
        Serial.print("Card removed ");
        Serial.println(code);  
      }
    
      static void OnUsbRemoved(uint16_t code)
      {
        Serial.println();
        Serial.print("USB Disk removed ");
        Serial.println(code);  
      }
    };

    This is for the Notification function for the status of your Mp3 player and as you can see it is inside a Class function so that it can access functions directly from the library. 

    void waitfortouch(unsigned short int *x,unsigned short int *y){
      do
      {    
        delay(10);
        if (ts.dataAvailable() == true)
        {
          ts.read();
          *x = ts.getX();  //Get touch point  
          *y = ts.getY();
          return;
          }
      }while(ts.dataAvailable()==false); 
    }

    This function is for the Touch Screen to get touch points and perform certain conditions. 

    drawBitmap(0,0, myBitmap,320, 240,ILI9341_WHITE);

    This is for the background since the LCD can only read bitmaps in this case we will just convert jpg or png images to byte arrays using http://javl.github.io/image2cpp/.

    void loop() 
    {  
      trcknms();
    
       waitfortouch(&x,&y); 
       if (buttons[0].contains(x,y)) 
        {    
         mp3.nextTrack();
        
          }
          
       else if (buttons[1].contains(x,y))
        {  
            mp3.prevTrack(); 
        }
         else if (buttons[2].contains(x,y))
        {
           mp3.pause();
        }
         else if (buttons[3].contains(x,y))
        {
            mp3.start();
        } 
        
    }

    This function is for the buttons to perform operation when it is touched.

    For Converting image to byte arrays:

    Select your desired file you want to convert.
    Then if you’re finished setting up your image, click Generate Code then Copy to your text editor and Save it with .c extension. Save it on the sketch where your main code is in.
    It should be like this.
    void drawBitmap(int16_t x, int16_t y,
     const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) {
    
      int16_t i, j, byteWidth = (w + 7) / 8;
      uint8_t byte;
    
      for(j=0; j<h; j++) {
        for(i=0; i<w; i++) {
          if(i & 7) byte <<= 1;
          else      byte   = pgm_read_byte(bitmap + j * byteWidth + i / 8);
          if(byte & 0x80) tft.drawPixel(x+i, y+j, color);
        }
      }
    }

    This is the function to display your bitmap byte array. You can directly copy the routine from your GFX library 

    This the Actual Video of the system with its functions.

    Conclusion

    This project provided a simple integration of the DFPlayer and the TFT Touch Screen but the components used is not only limited for this project. Depending on your desired output, this project can be improved for modification with the code and the layout of the system .

    References

    The post Mini MP3 Player Using DFPlayer Mini Mp3 Module with 2.8″ TFT Touch Screen LCD appeared first on CreateLabz.

    2.8" tft lcdAmplifierArduinoArduino unoAudio amplifierDfplayerDfplayer mini mp3Ili9341KnowledgebaseLcdLm386Mp3Touch screen

    Leave a comment

    All comments are moderated before being published