by Constantin Traian-Alexandru
The aim of this project is to build a practical portable music player that is compatible with common hardware and files (standard batteries, microSD cards and .mp3 music files, respectively). The ultimate goal of this would be to have a music player that can be built from scratch by anyone, and which is able to play music files without relying on cloud services.
A DFPlayer Mini module will be used to read the .mp3 files inside the microSD card and will output the decoded audio. The DFPlayer will be used instead of a conventional SD card reader due to the difficulty in decoding .mp3 signals on an Arduino.
The Arduino will control the interfacing with the user (control buttons for input, an LCD display for output), as well as the functions of the DFPlayer (play/pause, track selection etc.).
The LCD Display will show information such as the current track. The buttons can be used to play/pause and navigate, as well as increase/decrease the volume. The audio is outputted to two stereo speakers (powered by an amplifier).
The following components will be used in the project:
Breadboard test designs for the screen, DFPlayer, as well as testing the complete functionality using earphones:
It is also recommended to use a 1KΩ resistor for the RX pin on the DFPlayer in order to avoid a poor sound quality.
The following libraries have been used in this project:
Firstly, one major drawback of the DFPlayer in contrast to a normal SD card reader is the fact that it and only it has access to the contents of the micro SD card. The Arduino is able to give commands to the DFPlayer specifying what tracks should be played, but it will never have direct access to them.
Consequently, in order to allow the users to select the tracks they want to be played, a replica of a file system has been implemented, consisting of two multidimensional arrays: the first one, “filesystem”, stores the names of the songs (.mp3 files), as well as that of the album (file directory) in which they are located. The second array, “fileindex”, is necessary in order to account for the position of the tracks in the “filesystem” array, relative to the order in which they are read in the sequential “queue” of the DFPlayer.
The DFPlayer reads from the microSD card a folder structure of the following kind:
It is to be noted, however, that the files and folders need not be named to 01, 002 etc., as the DFPlayer orders them according to the date and time that they were written to the microSD card.
The DFPlayer is also able to read up to 255 files inside 99 folders - however, the small 2kB SRAM of the ATmega328p is not able to even initialize that large of a multidimensional array; the memory of the “file system” was restricted to holding 4 folders of 16 files.
On the basis of such a file structure as discussed above, I have thought of implementing an interface to navigate through the albums and songs, as well as playing them. The result was a 3-screen system which allows the user to navigate through a list of albums, then a list of songs inside an album, and then allows for playing a song with basic music player controls (play/pause, next, volume up/down). In order to keep the project simplistic, the 5 buttons on the front panel each have specific functions when pressed, depending on the screen which is shown:
The screens can be scrolled up and down if the album has many songs that cannot be displayed on the screen, similarly to old Nokia UIs.
When initially tested, I discovered that my ST7735 LCD screen had a problem with the offset of the pixels. This can be attributed to the microcontroller of the display not being an original manufactured by Sitronix.
I managed to correct this problem by adding a manual offset inside the Adafruit library.
Inside Documents\Arduino\libraries\Adafruit_ST7735_and_ST7789_Library\Adafruit_ST77xx.cpp:
void Adafruit_ST77xx::commonInit(const uint8_t *cmdList) { _colstart = 2; _rowstart = 1; begin(); if (cmdList) { displayInit(cmdList); } }
The code can be summarized as follows:
There are many improvements that can potentially be made to the design, for example: the addition of an EEPROM memory module to expand the capacity of the files; an automated script for copying songs in sync from the PC to both the EEPROM and the microSD card.
However, I feel that the scope of the project has been fulfilled and that it demonstrates the capabilities of the Arduino in being used for the implementation of a Portable Music Player.
Archive: pmp.zip
Software used:
Study materials: