Wav player with RPG-based menu
Project by Josh Dunn and Ryan Sartin
Purpose
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.
Description
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.
Pictures
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.
Video
Schematic
Speaker and NPN transistor connections
Information
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
Parts
- NPN Bipolar Junction Transistor (BJT)
- 1k Ohm Resistor
- 520 Ohm Resistor
- mbed
- Basic 16x2 Character LCD - Black on Green 5V
- Breakout Board for microSD
- Small 8 ohm speaker
- Rotary Encoder
Pins
Note
As always, fully disconnect power from your circuit before making changes, even simple wire addition/removal.
LCD Assignments | ||
---|---|---|
Pin | TextLCD pins | mbed pins |
1 | GND | 0V |
2 | VCC | 5.0V |
3 | VO | 0V, via 1k resistor |
4 | RS | p25 |
5 | RW | 0V |
6 | E | p26 |
7 | D0 | not connected |
8 | D1 | not connected |
9 | D2 | not connected |
10 | D3 | not connected |
11 | D4 | p27 |
12 | D5 | p28 |
13 | D6 | p29 |
14 | D7 | p30 |
RPG Assignments | ||
---|---|---|
Pin | RPG pins | mbed pins |
1 | 6 | p16 |
2 | 7 | p17 |
3 | 8 | 0V |
4 | 9 | p19 |
SD Card Assignments | ||
---|---|---|
Pin | SD pins | mbed pins |
1 | cd | p9 |
2 | do | p6 |
3 | GND | 0V |
4 | sclk | p7 |
5 | VCC | 3.3V |
6 | di | p5 |
7 | cs (chip select) | p8 |
Speaker Assignment | ||
---|---|---|
Pin | Speaker pin | mbed pins |
1 | via 520 ohm resistor to NPN BJT Base | p18 |
Program
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
- 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
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:
Please log in to post comments.
hey how would you use this with a usb pen drive on the Components Workshop Board thanks