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
- NPN Bipolar Junction Transistor (BJT)
- 1k Ohm Resistor
- 520 Ohm Resistor
- Basic 16x2 Character LCD - Black on Green 5V
- Breakout Board for microSD
- Small 8 ohm speaker
- Rotary Encoder
As always, fully disconnect power from your circuit before making changes, even simple wire addition/removal.
|Pin||TextLCD pins||mbed pins|
|3||VO||0V, via 1k resistor|
|Pin||RPG pins||mbed pins|
|SD Card Assignments|
|Pin||SD pins||mbed pins|
|7||cs (chip select)||p8|
|Pin||Speaker pin||mbed pins|
|1||via 520 ohm resistor to NPN BJT Base||p18|
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.
- Ticker API, used to interrupt the sound every second to update the LCD
- 16x2 LCD library, used to display .wav file names and elapsed time
- SD Card File System library, used to store .wav files for the audio player
- Debounce In library, used as a software solution to mechanical bouncing of our pushbutton (RPG)
- Wav Player library, used for playing .wav files using the 8 ohm speaker
- Wav Support library, used to extract .wav file header information for time calculations
- Rotary Pulse Generator library, used for scrolling through the song choices on the LCD and for push-button feedback
- Allow the user to freely remove and insert SD card when songs are not playing
1 comment on Wav player with RPG-based menu:
Please log in to post comments.