Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Build an ESP32-S3 Portable Media Player

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through building a battery-powered portable media player around the ESP32-S3. You'll get a device that plays MP3/AAC/WAV files from a microSD card, displays track info on a small screen, and is controlled with physical buttons. You'll need basic soldering skills and some familiarity with the Arduino IDE or ESP-IDF.

What You'll Need

  • ESP32-S3 development board (with at least 4MB flash, preferably 8MB)
  • I2S DAC module (e.g., MAX98357A) or an I2S audio breakout
  • MicroSD card module (SPI-based) and a microSD card (FAT32 formatted)
  • Small OLED or TFT display (I2C or SPI, 0.96" or 1.3" works well)
  • 3 or 4 momentary push buttons
  • Lithium-ion battery (3.7V) with a TP4056 charging module (optional but recommended)
  • Breadboard, jumper wires, and a soldering iron
  • USB cable for programming
  • Arduino IDE with ESP32 board support installed, or ESP-IDF
  • Audio files in MP3, AAC, or WAV format (test with a short clip first)

Step-by-Step

  1. Prepare the audio files. Format a microSD card as FAT32. Create a folder named music and copy a few short MP3 or WAV files into it. Avoid very long filenames and special characters.
  2. Wire the I2S DAC. Connect the MAX98357A (or similar) to the ESP32-S3: BCLK to GPIO 4, LRC to GPIO 5, DIN to GPIO 6, and VIN to 3.3V, GND to GND. If your DAC has an SD pin, tie it to 3.3V to enable the output.
  3. Wire the microSD card module. Connect the SPI pins: CS to GPIO 10, MOSI to GPIO 11, SCK to GPIO 12, MISO to GPIO 13. Power it with 3.3V (not 5V) to avoid logic level issues.
  4. Wire the display. For an I2C OLED: connect SDA to GPIO 8, SCL to GPIO 9, VCC to 3.3V, GND to GND. For an SPI display, use the default SPI pins and set CS/DC/RST to free GPIOs.
  5. Wire the buttons. Connect each button between a GPIO and GND. Use GPIOs 14, 15, 16, 17 for Previous, Play/Pause, Next, and Volume (or as you prefer). Enable internal pull-up resistors in code.
  6. Optional: add battery and charging. Connect the TP4056 module's BAT+ and BAT- to a Li-ion cell, and its OUT+ and OUT- to the ESP32's 5V and GND pins (or use a protected battery and connect directly to the 3.3V rail with a switch). Ensure the ESP32's EN pin gets a proper power-on reset signal.
  7. Install required libraries. In Arduino IDE, install: ESP32-audioI2S by schreibfaul1, SD (built-in), Adafruit SSD1306 (for OLED) or TFT_eSPI (for TFT), and Adafruit GFX.
  8. Write the firmware. Start with a simple sketch that initializes the SD card, opens an audio file, and plays it via the I2S DAC. Then add button handling and display updates. Use the Audio library's methods like connecttoFS, setVolume, and pauseResume.
  9. Upload and test. Connect the ESP32-S3 via USB, select the correct board and port, and upload the sketch. Open the Serial Monitor to see debug output. If no sound, check wiring and the file path.
  10. Add controls and display. Implement button debouncing (e.g., with millis()) and map buttons to functions: next/previous track, pause/resume, and volume up/down. Update the display with the current track name and elapsed time.
  11. Enclosure. Once everything works on a breadboard, transfer the circuit to a perfboard or design a 3D-printed case. Cut holes for the buttons, screen, and USB port.

Common Mistakes

  • Using 5V on the microSD module – this can damage the ESP32's GPIOs. Always use 3.3V.
  • Incorrect I2S pin assignments – the library expects specific pins; double-check your wiring against the code.
  • Forgetting to format the SD card as FAT32 – the library won't read exFAT.
  • Not using pull-up resistors on buttons – internal pull-ups are fine, but only if enabled in code.
  • Charging the battery while the ESP32 is powered via USB – this can cause instability; use a diode or a proper power path.

Tips

  • Use a dedicated I2S DAC module instead of the ESP32's built-in DAC – the quality is much better.
  • Store the audio library's buffer in PSRAM if your board has it – this reduces stuttering.
  • Add a small amplifier and a speaker for a standalone player, or use a headphone jack with a simple amp.
  • Use a rotary encoder for volume control – it's more intuitive than buttons.
  • Enable the ESP32's deep sleep mode to save battery when idle.

Troubleshooting

  • No sound: Check the I2S wiring, especially BCLK and LRC. Verify the file path (e.g., /music/song.mp3). Test with a WAV file first.
  • SD card not mounting: Check SPI pins and CS. Try a different card or reformat to FAT32. Some modules need a 10k pull-up on MISO.
  • Display not working: For I2C, scan the I2C address using a sketch. For SPI, check the TFT_eSPI configuration file – you must edit it to match your pins.
  • Stuttering audio: Increase the audio buffer size in the library, or use a faster SD card. Also, avoid heavy CPU tasks in the loop.
  • Buttons not responding: Check for cold solder joints and ensure the GPIOs are not already used by the display or SD.
  • Battery not charging: Verify the TP4056 connections and that the charging module receives 5V. Check the battery polarity.

Frequently Asked Questions

Can I use the ESP32's built-in DAC instead of an I2S module?

Yes, but audio quality is poor (8-bit, noisy). For a decent player, an I2S DAC is strongly recommended.

What audio formats are supported?

The ESP32-audioI2S library supports MP3, AAC, FLAC, WAV, and OGG, among others. Check the library's documentation for the full list.

How long will the battery last?

With a 2000mAh battery and moderate volume, expect 6-10 hours. Power consumption depends on the display and amplifier.

Can I stream music over Wi-Fi instead of using an SD card?

Yes, the library can stream from HTTP servers, but that adds complexity and requires a Wi-Fi connection.

Do I need a level shifter for the SD card?

Most ESP32-S3 boards are 3.3V logic, so a level shifter is not needed if the module is powered with 3.3V.

Can I add a touchscreen?

Yes, if you use an SPI TFT with touch, you can integrate touch controls. The code will be more complex but doable.