🛠 GPIO and I/O Integration with the MAX98357A I2S Amplifier

Adafruit Stereo I2S 3W Amplifier Breakout - Dual MAX98357A · intermediaire · Apprenez à contrôler l'amplificateur via les GPIO et à intégrer des capteurs ou affichages dans un système audio I2S.

Objectifs

This tutorial aims to master the interface between a microcontroller (like ESP32 or RP2040) and the Adafruit Stereo I2S 3W Amplifier card. We will explore GPIO pin management for digital I2S control, while integrating input/output peripherals such as push-buttons for volume control or LEDs for status indication. The goal is to understand how to allocate GPIO resources without conflict, respecting the card's 3.3V/5V logic specifications, and optimizing routing to minimize electromagnetic interference on the digital audio signal.

Matériel nécessaire

Étapes

  1. Identify I2S pins: On your microcontroller, identify pins dedicated to I2S. For ESP32, these are typically GPIO 25 (BCLK), GPIO 26 (LRC/WS), and GPIO 22 (DOUT). Note that the MAX98357A does not require MCLK (Master Clock), simplifying wiring.
  2. Power wiring: Connect the amplifier card's VIN to 5V (or 3.3V if your MCU supports it for logic, but 5V is recommended for power). Connect GND to common ground.
  3. Audio output connection: Connect L+ and L- outputs to the left speaker, and R+ and R- to the right speaker. Warning: BTL (Bridge Tied Load) mode means negative poles must NOT be connected to circuit ground.
  4. GPIO configuration for I2S: In your code, configure selected pins in I2S mode. Ensure logic voltages are compatible (card accepts 3.3V and 5V).
  5. Add user inputs: Connect a push-button between a free GPIO pin (e.g., GPIO 13) and GND. Configure this pin as input with internal pull-up resistor. This button will toggle gain modes (3dB to 15dB) if using jumpers, or mute sound.
  6. Add status output: Connect LED to another GPIO pin (e.g., GPIO 12) via resistor. This LED will blink during audio playback to indicate active I2S stream.
  7. Write control code: Initialize I2S peripheral. In main loop, read button state. If pressed, change gain parameter or pause. Activate LED if audio buffer contains data.

Vérification

Open serial monitor. Press button: gain should change or sound mute. LED should light up when audio is sent. Listen to speaker: sound should be clear, without excessive background noise (output noise < 25µV RMS). Verify card does not overheat (thermal protections active if >100°C).

Pour aller plus loin

Explore using MCU internal ADC to create audio feedback (VU-meter) or add digital potentiometer (I2C) for fine volume control, keeping in mind that MAX98357A card handles volume at digital stream level if MCU supports it.

Other tutorials for this board

← Back to the board 🛠 All tutorials