Angled front view of the MAX98357 I2S amplifier with speaker terminal and pre-soldered pins

MAX98357 Pre-Soldered I2S Class D Audio Amplifier Module | ShillehTek Product Manual

ArduinoESP32Raspberry PiPicomanual-product-10645386068255
$6.99 USD In stock · Order by 3pm ET, ships today

Overview

The MAX98357A is a digital audio amplifier. It takes I2S audio, the digital audio bus found on many microcontrollers and single-board computers, converts it to analog and drives a speaker directly, all in one chip. There is no separate DAC, no analog wiring and no hum-prone signal path: three signal wires go in and a speaker comes out. It is a mono Class D amplifier that delivers up to about 3 W into a 4 ohm speaker from a 5 V supply.

This pre-soldered module has a 7-pin header (LRC, BCLK, DIN, GAIN, SD, GND and VIN) and a screw terminal for the speaker. It runs from 2.5 to 5.5 V and accepts 3.3 V or 5 V logic. The gain is 9 dB by default and can be changed with the GAIN pin. The SD pin shuts the amplifier down or selects the channel, and by default the board plays a mix of the left and right channels.

It works with any board that has an I2S output: the ESP32, Raspberry Pi, Raspberry Pi Pico and I2S-capable Arduinos such as the Nano 33 IoT and MKR boards. The Arduino Uno and classic Nano have no I2S port and cannot drive it. This manual covers the pinout, wiring, test-tone code for each platform, and answers on gain, channel selection, speakers and noise.

At a Glance

Type
I2S Class D mono amplifier
Output Power
Up to 3 W into 4 ohm
Supply
2.5 – 5.5 V
Audio Input
I2S: LRC, BCLK, DIN
Gain
9 dB default, 3 – 15 dB
Speaker
4 – 8 ohm, screw terminal

Specifications

Parameter Value
Amplifier IC MAX98357A, mono Class D with built-in DAC
Audio input I2S: LRC (word clock), BCLK (bit clock), DIN (data). No MCLK needed.
Sample rates 8 to 96 kHz
Output power About 3 W into 4 ohm or 1.8 W into 8 ohm at 5 V (10% THD)
Supply voltage 2.5 – 5.5 V
Logic level 3.3 V or 5 V
Gain 9 dB default · 3, 6, 12 or 15 dB with the GAIN pin
Channel (L+R)/2 mix by default · left or right with the SD pin
Shutdown SD pin to GND
Speaker 4 to 8 ohm on the screw terminal (bridge-tied output)
Board size About 19 × 18 mm

Pinout Diagram

With the screw terminal at the top and the header at the bottom, the pins read left to right: LRC, BCLK, DIN, GAIN, SD, GND and VIN. LRC, BCLK and DIN are the three I2S signals. GAIN and SD are optional setting pins and can stay unconnected. VIN takes 2.5 to 5.5 V. The speaker goes on the screw terminal, which is marked - and +. The amplifier drives both speaker wires, so never connect either of them to ground.

MAX98357A I2S Class D amplifier module pinout diagram showing LRC, BCLK, DIN, GAIN, SD, GND and VIN pins and the speaker terminal

Wiring Guide

The amplifier needs power, ground and the three I2S signals. Screw the speaker into the terminal first. Power VIN from 5 V where you can: the amplifier is louder there, and its current does not load your board's 3.3 V regulator.

Arduino Wiring (Nano 33 IoT, MKR, Zero)

The Arduino Uno and classic Nano have no I2S port, so they cannot drive this amplifier. The SAMD21 boards below can, using the I2S library that comes with their board package.

Amp Pin Nano 33 IoT MKR Zero
VIN 3.3V 5V 5V
GND GND GND GND
LRC A2 3 0
BCLK A3 2 1
DIN 4 A6 9
No Uno: The Uno, Mega and classic Nano have no I2S hardware. Use one of the boards above, an ESP32 or a Pico instead.
Nano 33 IoT: Power the amplifier from the 3.3V pin. The 5V pin on this board is not connected unless you bridge the VUSB pads on its underside.

ESP32 Wiring

Amp Pin ESP32 Pin Notes
VIN 5V or VIN Power
GND GND Ground
BCLK GPIO 26 Bit clock
LRC GPIO 25 Word clock
DIN GPIO 22 Audio data
Any pins: The ESP32 can route I2S to almost any GPIO. If you use other pins, change the three pin numbers at the top of the sketch to match.
Board package: The sketch uses ESP_I2S.h, which is part of the ESP32 board package from version 3.0. Update the package in Boards Manager if the include is not found.

Raspberry Pi Wiring

Amp Pin Raspberry Pi Pin Notes
VIN 5V (Pin 2) Power
GND GND (Pin 6) Ground
BCLK GPIO 18 (Pin 12) Bit clock
LRC GPIO 19 (Pin 35) Word clock
DIN GPIO 21 (Pin 40) Audio data
Enable it: Edit /boot/firmware/config.txt, put a # in front of dtparam=audio=on, add the line dtoverlay=max98357a and reboot. Then run speaker-test -c2 to hear test noise.

Raspberry Pi Pico Wiring

Amp Pin Pico Pin Notes
VIN VBUS (Pin 40) USB 5 V
GND GND (Pin 38) Ground
BCLK GP16 (Pin 21) Bit clock
LRC GP17 (Pin 22) Word clock
DIN GP18 (Pin 24) Audio data
Pin order: In MicroPython on the Pico, the LRC pin must be the GPIO directly after the BCLK pin, for example GP16 and GP17. DIN can be any free pin.

Code Examples

View or download this product's example code on GitHub.

Each example plays a steady test tone of about 440 Hz, enough to confirm the wiring before you move on to real audio. The volume values are deliberately low. Raise them once you hear the tone.

Arduino Nano 33 IoT, MKR and Zero — Test Tone

max98357_tone_arduino.ino
// MAX98357 I2S amplifier - 440 Hz test tone from an I2S-capable Arduino
// For SAMD21 boards (Nano 33 IoT, MKR family, Zero). The Uno and classic Nano have no I2S.
// Wiring: LRC  = A2 (Nano 33 IoT), 3 (MKR) or 0 (Zero)
//         BCLK = A3 (Nano 33 IoT), 2 (MKR) or 1 (Zero)
//         DIN  = 4 (Nano 33 IoT), A6 (MKR) or 9 (Zero)
//         VIN  = 3.3V or 5V, GND = GND
#include <I2S.h>

const int sampleRate = 8000;       // samples per second
const int frequency  = 440;        // tone pitch in Hz
const int amplitude  = 2000;       // volume, up to 32767
const int halfWave   = sampleRate / frequency / 2;   // samples per half wave

short sample = amplitude;
int count = 0;

void setup() {
  Serial.begin(115200);
  if (!I2S.begin(I2S_PHILIPS_MODE, sampleRate, 16)) {
    Serial.println("Failed to start I2S");
    while (true) { delay(1000); }
  }
}

void loop() {
  if (count % halfWave == 0) {
    sample = -sample;                // flip the square wave
  }
  I2S.write(sample);                 // left channel
  I2S.write(sample);                 // right channel
  count++;
}

ESP32 — Sine Test Tone

max98357_tone_esp32.ino
// MAX98357 I2S amplifier - 440 Hz sine test tone from an ESP32
// Needs the ESP32 board package 3.0 or newer, which provides ESP_I2S.h
// Wiring: VIN = 5V, GND = GND, BCLK = GPIO 26, LRC = GPIO 25, DIN = GPIO 22
#include <ESP_I2S.h>

const int PIN_BCLK = 26;
const int PIN_LRC  = 25;
const int PIN_DIN  = 22;

const int sampleRate  = 44100;     // samples per second
const float frequency = 440.0;     // tone pitch in Hz
const int amplitude   = 4000;      // volume, up to 32767

I2SClass i2s;
int16_t samples[512];              // 256 stereo frames: left, right, left, right ...
float phase = 0.0;

void setup() {
  Serial.begin(115200);
  i2s.setPins(PIN_BCLK, PIN_LRC, PIN_DIN);
  if (!i2s.begin(I2S_MODE_STD, sampleRate, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO)) {
    Serial.println("Failed to start I2S");
    while (true) { delay(1000); }
  }
}

void loop() {
  const float step = 2.0 * PI * frequency / sampleRate;
  for (int i = 0; i < 256; i++) {
    int16_t value = (int16_t)(amplitude * sin(phase));
    samples[2 * i] = value;          // left channel
    samples[2 * i + 1] = value;      // right channel
    phase += step;
    if (phase >= 2.0 * PI) phase -= 2.0 * PI;
  }
  i2s.write((uint8_t *)samples, sizeof(samples));   // waits until the samples are queued
}

Raspberry Pi — Python Test Tone

max98357_tone.py
#!/usr/bin/env python3
# MAX98357 I2S amplifier on Raspberry Pi - create a test tone and play it
# One-time setup in /boot/firmware/config.txt: put a # in front of dtparam=audio=on,
# add the line dtoverlay=max98357a, then reboot.
# Wiring: VIN = 5V (pin 2), GND = pin 6, BCLK = GPIO 18 (pin 12),
#         LRC = GPIO 19 (pin 35), DIN = GPIO 21 (pin 40)
import math
import struct
import subprocess
import wave

RATE = 44100          # samples per second
FREQ = 440.0          # tone pitch in Hz
SECONDS = 2
VOLUME = 0.2          # 0.0 to 1.0

frames = bytearray()
for n in range(RATE * SECONDS):
    value = int(32767 * VOLUME * math.sin(2 * math.pi * FREQ * n / RATE))
    frames += struct.pack("<hh", value, value)      # left and right sample

with wave.open("tone.wav", "wb") as wav:
    wav.setnchannels(2)         # the Pi's I2S output expects stereo
    wav.setsampwidth(2)         # 16-bit samples
    wav.setframerate(RATE)
    wav.writeframes(bytes(frames))

subprocess.run(["aplay", "tone.wav"], check=True)

Raspberry Pi Pico — MicroPython Test Tone

max98357_pico.py
# MAX98357 I2S amplifier on Raspberry Pi Pico (MicroPython) - 441 Hz sine test tone
# Wiring: VIN = VBUS (5 V), GND = GND, BCLK = GP16, LRC = GP17, DIN = GP18
from machine import I2S, Pin
import math
import struct

RATE = 22050          # samples per second
FREQ = 441            # tone pitch in Hz (exactly 50 samples per wave at this rate)
VOLUME = 0.2          # 0.0 to 1.0

# On the Pico the LRC (ws) pin must be the GPIO right after the BCLK (sck) pin
audio = I2S(0, sck=Pin(16), ws=Pin(17), sd=Pin(18),
            mode=I2S.TX, bits=16, format=I2S.MONO, rate=RATE, ibuf=4000)

samples_per_wave = RATE // FREQ
wave = bytearray(samples_per_wave * 2)
for n in range(samples_per_wave):
    value = int(32767 * VOLUME * math.sin(2 * math.pi * n / samples_per_wave))
    struct.pack_into("<h", wave, n * 2, value)

try:
    while True:
        audio.write(wave)       # waits until the samples are queued
except KeyboardInterrupt:
    audio.deinit()

Frequently Asked Questions

Can I use the MAX98357 with an Arduino Uno or Nano?
No. The amplifier needs an I2S audio signal, and the Uno, Mega and classic Nano have no I2S hardware. Use an I2S-capable board such as the Nano 33 IoT, an MKR board, an ESP32 or a Pico. For sound from an Uno, an analog amplifier such as the PAM8406 fed from an audio module is the better fit.
How do I change the gain or volume?
The GAIN pin sets the gain in five steps: unconnected is 9 dB, connected to GND is 12 dB and connected to VIN is 6 dB. A 100k resistor from GAIN to GND gives 15 dB, and a 100k resistor to VIN gives 3 dB. Power the board off and on after changing it. For finer control, scale the sample values in your code, as the volume settings in the examples do.
How do I play only the left or only the right channel?
The voltage on the SD pin selects the output. Below 0.16 V the amplifier shuts down, from 0.16 to 0.77 V it plays the (L+R)/2 mix, from 0.77 to 1.4 V the right channel, and above 1.4 V the left channel. The board's own pull-up sets the mix. Connecting SD straight to VIN selects the left channel. The right channel needs a resistor that brings SD into its window, so measure the pin with a multimeter while you choose the value.
Which speaker should I use?
Any 4 to 8 ohm speaker rated for about 3 W or more, such as the 4 ohm 3 W mini speaker. A 4 ohm speaker plays louder than an 8 ohm one at the same supply voltage. Do not connect headphones, a line input or another amplifier: both outputs are actively driven, and neither one is ground.
Why is there no sound?
Swapped BCLK and LRC wires are the most common cause, so check those first. Make sure the speaker is in the screw terminal, SD is not touching ground and VIN has power. On a Raspberry Pi, confirm the dtoverlay line is in config.txt and that you rebooted. On an ESP32, the board package must be version 3.0 or newer. Finally, raise the volume value in the example.
Why do I hear pops, hiss or distortion?
A pop when audio starts or stops comes from the I2S clocks switching on and off. Keep the stream running with silence, or pull SD low to mute. Distortion at high volume means the output is clipping, so lower the sample volume or the gain. A weak supply also distorts: at 5 V and full volume the amplifier can draw several hundred milliamps, so use a supply with headroom.
Does it need MCLK, and which audio formats work?
No master clock is needed. The MAX98357A takes its timing from BCLK and LRC alone and accepts standard I2S data at sample rates from 8 to 96 kHz. 16-bit audio, as used in all the examples, is the usual choice. The Raspberry Pi's I2S output expects stereo files, which is why the Python example writes the same tone to both channels.

Related Tutorials

Datasheets & downloads

Reference documents for the MAX98357 Pre-Soldered I2S Class D Audio Amplifier Module. This manual covers wiring and code; the documents below carry the full electrical specifications.