Wav player with RPG-based menu

Project by Josh Dunn and Ryan Sartin


This simple audio player utilizes an LCD, RPG (Rotary Pulse Generator), 8 ohm speaker, and SD card to provide the basic functions of a music player.


Upon start-up the project checks to see if an SD card is inserted. If one is found then then the SD card will be searched for all files with a .wav or .WAV extension (the default search location is "/sd/"). Whenever a wave file is found, it's path name is stored in a new node of a doubly-linked list. Once the search has been completed, the total number of wave files found will be displayed on the LCD screen.

From there the RPG will allow the user to scroll through the list of files. Turning the RPG clockwise increments through the linked list and counter-clockwise decrements. When the RPG push-button is pressed, the LCD displays "Song Playing" and uses the path name stored in the current node of the linked-list to open the wave file. The header information is read from the wave file and the total length of the song in seconds is calculated using the equation: total length / (samples per second * number of channels * bytes per sample). This is displayed on the second row of the LCD screen in the format: "Time: /XXXsec", where XXX is the recently calculated number (left justified). The file is closed after the header information is read. Then the Ticker API is initialized with a function that counts the number of elapsed seconds and the file is re-opened. The wave_player library is then used to play the song from the SD card. While playing the ticker function will seize control and count the number of seconds and print it out to the second row of the LCD screen.

If the SD card is ever removed during operation, the LCD will display "No SD card Found" and the mbed will need to be reset. The linked-list will be freed.



After program initialization, the audio player searches the SD card for usable .wav files and displays the number on the screen. The user uses the RPG to cycle left and right between the available file names.


As the user scrolls through the available .wav file choices, the file name is displayed on the LCD (without the .wav file extension).


After the song is selected by the user (shown above), the LCD displays the time elapsed and total song time once the sound begins to play.



Speaker and NPN transistor connections



You can place a diode in parallel with the speaker, as shown here. This flyback diode is used to eliminate sudden voltage spikes across inductive loads when the power supply is reduced or removed. It is highly recommended to use such a diode for large loads such as motors.

SC Card breakout board and RPG connections


LCD connections



  • NPN Bipolar Junction Transistor (BJT)
  • 1k Ohm Resistor
  • 520 Ohm Resistor



As always, fully disconnect power from your circuit before making changes, even simple wire addition/removal.

LCD Assignments
PinTextLCD pinsmbed pins
3VO0V, via 1k resistor
7D0not connected
8D1not connected
9D2not connected
10D3not connected
RPG Assignments
PinRPG pinsmbed pins
SD Card Assignments
PinSD pinsmbed pins
7cs (chip select)p8
Speaker Assignment
PinSpeaker pinmbed pins
1via 520 ohm resistor to NPN BJT Basep18


Import programWav_player_RPG_menu

This program utilizes an LCD, RPG, 8 ohm speaker, and SD card to provide the basic functions of a music player. The project cycles through the SD card for .wav files and tracks elapsed time. See http://mbed.org/users/rsartin3/notebook/wav-player-with-RPG-based-menu/ for more information.

Additional Resources

Further Improvements

  • Allow the user to freely remove and insert SD card when songs are not playing

1 comment on Wav player with RPG-based menu:

03 Jul 2013

hey how would you use this with a usb pen drive on the Components Workshop Board thanks

Please log in to post comments.