🛠 I2S Audio Streaming on ESP32 with MAX98357A Amp

Adafruit Stereo I2S 3W Amplifier Breakout - Dual MAX98357A · intermediaire · Configurez un système de diffusion audio réseau complet en connectant un ESP32 à l'amplificateur stéréo MAX98357A pour lire des flux I2S.

Objectives

This tutorial aims to create a functional network audio node. You will learn to configure the I2S interface of a microcontroller (here, an ESP32) to transmit a digital audio stream to the Adafruit Stereo I2S 3W Amplifier. Unlike analog amplifiers, the MAX98357A processes the signal digitally until output, offering high fidelity and 92% efficiency. We will explore the specific wiring required for Bridge Tied Load (BTL) mode and logic level management.

Required Materials

Steps

  1. Power Preparation: The amp is efficient but can draw current spikes. Connect the amp's VIN pin to a stable 5V power supply. Connect GND to the common ground of the ESP32 and the power supply.
  1. I2S Wiring: The ESP32 uses specific pins for I2S. Connect pins as follows (check your board's datasheet):

*Note: The MAX98357A does not require a MCLK (Master Clock) pin, simplifying wiring.*

  1. Speaker Connection: BTL mode means outputs are not ground-referenced. For the Left channel:

Repeat for the Right channel with OUT R+ and OUT R-. Never connect speaker terminals to Ground (GND).

  1. Software Configuration: In Arduino IDE, select the ESP32-audio-i2s or I2S.h library. Initialize the I2S bus with pins defined in Step 2. Set the sampling rate (e.g., 44100 Hz) and resolution (16-bit).
  1. Stream Playback: Load an audio file or network stream (via Wi-Fi) into the buffer. Send PCM samples via the I2S interface's write() function. The amp will automatically convert the digital signal to analog power.

Verification

Power up the system. You should hear a slight background noise (25µV RMS) if no signal is sent. Start audio playback. Verify that sound comes from both speakers without excessive distortion. If sound is saturated, reduce software volume or check that hardware gain (jumpers) is not set too high (start at 9dB).

Going Further

Add volume control functionality via a web interface (ESP32 WebServer) or a digital potentiometer. You can also explore FLAC file playback for higher audio quality, managing decoding on the microcontroller before I2S transmission.

Other tutorials for this board

← Back to the board 🛠 All tutorials