Skip to main content

Music Player

Compact music player with microSD input, outputting to a speaker, featuring controls for play, pause, skip, and volume.

info

Author: Pasaroiu Mihai Octavian
GitHub Project Link: https://github.com/UPB-FILS-MA/project-12mihai05.git

Description

This project is a compact music player built with a Raspberry Pi Pico W and programmed in Rust. It uses an SPI-connected microSD module to read songs, playing them through a speaker with an amplifier for clear audio output. The music will be outputted as PWM through a speaker. The user interface consists of push buttons for basic controls (next song, previous song, and play/pause), a potentiometer for smooth volume adjustment, and an I2C LCD screen that displays the current song's title. Additionally, a set of PWM-controlled LEDs offers a dynamic visual representation of the music's intensity, with brightness varying based on the PWM duty cycle of the audio output to the speaker.

Motivation

Building a music player with a Raspberry Pi Pico W using Rust allowed me to work on a project that I could personally enjoy, while also learning valuable skills in microcontroller programming and hardware integration. I like to listen to music, and it seemed interesting to create a project that combines technology with something I love. Plus, it's a great way to make something cool that I can show off to my friends.

Architecture

Architecture Diagram

Log

Week 6 - 12 May

Make the hardware part and work for the software.

Week 7 - 19 May

Continue developing and debugging software.

Week 20 - 26 May

Finished the software and made the case for the project.

Hardware

This project utilizes a Raspberry Pi Pico to facilitate digital audio playback from a 32GB microSD card formatted in FAT32, interfaced via SPI protocol. The audio output is delivered through a 1W speaker powered by a PAM8403 Class D Stereo Mini Amplifier, enhanced by an RC filter comprising a 680-ohm resistor and a 10nF capacitor, which filters frequencies above 23.4kHz. Visual augmentation is achieved through four LEDs, controlled by PWM signals that vary in intensity corresponding to the audio output's duty cycle, providing a dynamic representation of sound intensity. User interaction is managed through a 1602 LCD display, operating on the I2C protocol, which displays the current song title. The system also incorporates three push-buttons connected to the microcontroller's GPIO pins with 10k-ohm pull-up resistors, assigned to play/pause functionality and navigation between tracks. Additionally, a potentiometer is integrated for volume control, offering user-adjustable audio output levels.

Schematics

kicad hardware image 1 hardware image 2 hardware image 3

Bill of Materials

DeviceUsagePrice
Rapspberry Pi Pico WThe microcontroller35 RON
1602 LCDLCD Display16.34 RON
AmplifierBoosts audio output3.99 RON
ButtonsPlay/Pause and previous/next song2.16 RON
Different color ledsVisual representation of the music's intensity6 RON
WiresConnects electronic components13.79 RON
BreadboardComponent integration9.98 RON
PotentiometerAdjust volume2.36 RON
SpeakerOutputs the song4.27 RON
ResistorsLimits current flow14.99 RON
MicroSD Card ModuleReads the song from the microSD4.39 RON
CapacitorLow-pass filter(RC)0.39 RON

Software

LibraryDescriptionUsage
embedded-sdmmc-rsMicroSD card managementUsed for reading the files from microSD
ag-lcdLCD display driverUsed for displaying the name of the song playing
port-expanderManagement and use of I/O expander chipsManage the PCF8574 I/O expander for controlling LCD display via the I2C bus
cortex-mProvides low-level APIs for ARM Cortex-M processorsInterrupt handling and system control
embassy-executorManages asynchronous tasksHandles logging over USB in an asynchronous manner
embassy-syncProvides synchronization primitives for use in async tasksUsed to protect shared resources using mutexes
embassy-timeProvides time-related utilitiesManaging delays and scheduling tasks
heaplessEnables the use of fixed-size data structures that do not require heap memoryManaging strings and vectors that have a fixed capacity
logFacilitates loggingOutput debug and information messages
microfftProvides fast Fourier transform (FFT) calculationsPerforming FFT on audio data to analyze frequencies and amplitudes
bytemuckOffers safe casting between data typesUsed to safely cast slices of bytes to slices of other types
fixedImplements fixed-point arithmetic typesTransform bytes in FixedU16
  1. How to connect SD Card to Raspberry Pi Pico using SPI
  2. How to use the LCD using I2C
  3. Check and search for dependecies: 1, 2
  4. Example of how to play music using PWM
  5. Audio output circuit example