Sunday, October 28, 2012

Arduino mp3 player (II)



The SD structure

In this post I'll try to explain a little the code of  our 'Jukebox' Arduino hearted .
The main problem I found for this project, was the limitation SD library, with reduced FAT which only allowed the names in 8.3 format.
The solution was to create a small catalog in a text file from which to read the entries.

The directory structure on the SD has the following format:
raiz
 +-artistas.txt
 +-[ARTIST01]
 |   +-album.txt
 |   +-[ALBUM01]
 |   |   +-track.txt
 |   |   +-track001.mp3
 |   |   +-track002.mp3
 |   |   .....
 |   |   +-track0nn.mp3
 |   +-[ALBUM02]
 |   .......
 |   +-[ALBUMnn]
 +-[ARTIST02]
 .....
 +-[ARTISTnn]

This means there are three levels: artist, album and track. Each level has a text file with the catalog entries (a line of text for each artist, album or song).
The names of the folders and files must be such as are in the scheme (you can always change the code).
It's a bit cumbersome to create the card, but ... worthwhile. I used a program that makes it much easier MP3Tag, enabling export to text tracks of a directory and rename mp3.


The code

It consists of a library 'AGMp3' handling the chip and SD, and the sketch of the player. You can download it from here

The library is responsible for the initialization of the chip, the SD bus and SPI. It has methods to write / read in the records of the chip, and to play an mp3.
As for the sketch starts reading file 'artistas.txt' located in the root of the SD and then through the encoder and buttons 'navigate' for the directory structure. At each level reads the corresponding text file to load the list of catalog. In the last level play the selected mp3.
Once being played, the encoder is responsible for varying the volume which is displayed on the LCD with a value of 0 to 10.
The Forward button go to the next song during playback.

To show the progress of the song, I have defined some characters on the LCD.


Here you have some pictures of the construction process

Hope you like it! ....




If you liked it, remember to share it on your favorite social network. Thanks

33 comments:

  1. Thank you for blogging this useful project.

    ReplyDelete
  2. Thank you. I'm glad you have been useful

    ReplyDelete
  3. Can I download full your code and lib? thank you!

    ReplyDelete
  4. Hi Guay,

    How about adding the 3x4 keypad to control the volume, mute, or other button function? it seems the arduino not pin out enough. Is't right?

    ReplyDelete
  5. Saludos por su proyecto MP3, lo he montado ya tengo el hardware listo pero me da error en la tarjeta, pienso que es por lo el formato o lo el archivo te textos en el sd card, agradecería tu ayuda.
    Wilder padilla

    ReplyDelete
  6. @Wilder Padilla
    Que tipo de error?
    La SD tiene que estar formateada con FAT32, y el archivo de texto tiene la estructura comentada.
    Cuidado con la SD, si la tienes con cables. Yo tuve problemas utilizando cable plano y tuve que cambiar a un cable trenzado.
    Los mp3 creo recordar que no pueden estar a más de 160 Kbp

    ReplyDelete
  7. El error estaba en la conexión ya funciona y muy bien, felicitaciones y gracias por publicar el proyectó me fue de mucha utilidad.
    Hasta otra oportunidad Wilder Padilla.

    ReplyDelete
  8. Realmente tu proyecto me parece fantástico, quiero realizar un reproductor también con una tarjeta arduino uno un LCD DE 2x16 y una tarjeta mp3 como la que te muestro en el siguiente link
    http://www.electronica.com.ve//ventas/catalog/product_info.php?cPath=83&products_id=2882
    esta ya tiene la ranura para tarjeta SD incorporada mi problema es el código te agradecería si me puedes ayudar en fritzing hay un proyecto pero creo que el código no sirve
    este es el link
    http://fritzing.org/projects/connecting-a-sparkfun-mp3-shield-and-a-qy-1602-or
    gracias y saludos

    ReplyDelete
  9. @Kaled Souky
    En teoría el código te debería valer el mismo. Esta placa tiene el decodificadro de MP3 y la SD en la misma placa, pero por lo demás no cambia. Tienes que prestar atención a los pines que se utilizan para seleccionar el chip y la SD (mira la tabla que hay en la primera parte) y al resto de pines de control. Por lo que he podido ver en el esquema de la placa, la correspondencia con los pines del Arduino son los mismos, pero revísalo bien.

    ReplyDelete
  10. Good evening!
    I need your help. I read the code with Arduino Program (1.0.2 and 1.0.4) but I have problems with visualization of some characters. For example the line:
    if (letra == '�') {
    letra = 'n' +125;
    }
    I have the same problem with other lines.
    Please can you help me?
    Thank you!
    My email is:
    antonio.filoni@inwind.it

    ReplyDelete
  11. @nio19691969
    Is a Arduino ide problem with no ASCII characters
    (letra == '�') ==> (letra == 'ñ')

    Other lines ?

    ReplyDelete
  12. Hi, and many thanks for your fast reply.
    May i have your email so i can send to you entire sketch?
    I have another question. With VS1053 instead of VS100x module it's possible play flac files with your player?.
    Again thank you!!!!
    Antonio

    ReplyDelete
  13. @nio19691969
    Yes, you can sent me teh sketch.
    I do not know if you can play 'flac'. In the code you will have to change the extension (now looking mp3). The rest should work, because the file is read and sent to VS100X in packets of 32 bytes.

    ReplyDelete
  14. Hi, and many thanks for your reply.
    The sketch iso too long for the post. (maximum 4.096 characters)
    Have you got an email?
    Thank you.
    Antonio

    ReplyDelete
  15. how to create the directory structure ?

    ReplyDelete
  16. If I delete the Part of LCD Code it still work?

    ReplyDelete
  17. @PatriotaML
    Yes, you could use two buttons to move to the next or previous song, as in the simple mp3 players.

    ReplyDelete
  18. I made this system, but I'm facing problem.
    Could you share the examples of "artistas.txt", "album.txt", and "track.txt". many thanks.

    ReplyDelete
  19. Thanks a lot for quick reply, I'm very happy now.

    ReplyDelete
  20. Everything looks almost ok but the system doesn't play the music when I choose it on lcd.
    By the way I'm using the sparkfun mp3 shield. When I choose a track its name just moves up on the screen.
    And also my mp3 module connected not with 3.3V as it shown on the image but with 5V because with 3.3V it doesn't get power up.

    ReplyDelete
  21. thank you sir how can i get the components and the library file?

    ReplyDelete
  22. Dear Sir, I have a question about mp3 metadata, How to write arduino sketch to get information about time playing (seconds) or size(MegaByte) each songs ? Its too difficult for me...please help me.

    ReplyDelete
  23. its support all lang file name?
    like english hebrew etc

    ReplyDelete
  24. It is very useful information. Thank you. For more information related to this Click here

    ReplyDelete
  25. Hello,

    So i am currently trying to build a pocket version of this, and currently having some problems. I was going to look at your code for some reference, but most of the functions and variables are all Portuguese, so it is hard to follow. I just want to ask if you can translate the code to English so that i can easily work with this.

    It would be greatly appreciated.

    ReplyDelete
  26. Yeah, still hoping for an English version PLEASE....
    It would be greatly appreciated as commented by the last person

    ReplyDelete
  27. Completed the project using your code and instructions, everything worked using the Arduino UNO but it was LOW on memory, SO, I used an Arduino Mega256 and all is well, I had to change where the pins on the Mega vs the UNO for the encoder and buttons. THANK YOU VERY MUCH.

    ReplyDelete

Note: Only a member of this blog may post a comment.

Arduino Chromatic Clock, with Steampunk style

Arduino Chromatic Clock, with Steampunk  style Need a unique gift for Christmas? ... This watch unlike normal, uses colors instead of...