Skip to content
esp-labsESP32-S3 bench guide
ESP32-S3 DevKitC pinoutThis lesson uses: VCC on 3V3, MICS + on 3V3, AO on 6, BLK on 7, RES on 8, DC on 9, CS on 10, SDA on 11, SCL on 12, AMP VIN on 5V, GND on GND, BTN on 5, MICS G on GND, SD on 42, WS on 41, SCK on 40, BCLK on 39, LRC on 38, BOOT on 0, DIN on 47, DO on 21, AMP G on GND.ESP32-S3WROOM-1 N16R8BOOTRSTRGBUSBCOM3V3VCC3V3MICS +RST45BTN6AO7BLK151617188RES3469DC10CS11SDA12SCL13145VAMP VINGNDGNDGNDMICS GTX 43RX 441242SD41WS40SCK39BCLK38LRC3736350BOOT454847DIN21DO2019GNDAMP GGND
  • used in this lesson
  • safe GPIO
  • avoid
  • power
  • ground
  • button input
  • RC522
Between lessons
  1. Ctrl+C closes the monitor on the Mac only. The board keeps running.
  2. Unplug USB: this is what stops the program and the screen
  3. Rewire while off
  4. Check VCC is on 3V3, no loose ends
  5. Plug in, flash the next lesson

Never unplug during Writing at 0x…. Pin changing from output to input? Flash first, then wire.

Lesson S7

Sound · lesson 7 of 8

Make the board play: a synth on one speaker

built, not flashed

MAX98357A + speakerNumbers go out over I2S to the MAX98357A, a class-D amplifier: it switches the speaker fully on and off about 300 000 times a second, and how long each pulse lasts follows the number. The cone is too slow to follow, so it moves with the average: the wave. S7 makes notes in five timbres, chords, envelopes, tunes and game sounds, and draws what you hear.

Goal

Hear the difference between the five waves, play a chord and a tune, change the envelope until a note plucks, and fire every game sound.

You're done when

  • beep and the hello chime come out of the speaker at vol 20.
  • On wave, the spectrum shows one line for sine, odd harmonics for square, all for saw.
  • adsr 1 300 0 50 makes note A4 600 sound plucked; adsr 300 80 65 300 soft.
  • tune korobeiniki plays and the piano roll scrolls; fx explosion rumbles.

You will learn

  • I2S out
  • class-D amplifier
  • timbre = harmonics
  • aliasing at 16 kHz
  • ADSR vs clicks
  • semitones & chords
  • tempo
  • procedural sound
  • squared volume
uv run pio run -d labs/sound-lab-s7 -e sound-lab-s7 -t upload
Open this lab's code on GitHubesp-labs / labs / sound-lab-s7 (opens in a new tab)

Parts required

Parts library
  • ESP32-S3-DevKitC-1 + USB-C data cable
  • 1.9″ ST7789 screen
  • MAX98357A amp + speaker

From numbers to a moving cone

What happens to a sample after the board computes it, why the volume knob is squared, and the echo guard that keeps the microphone from hearing the speaker as claps.

I2S digital output path from ESP32-S3 I2S1 + GDMA into the MAX98357A Class-D speaker amplifier. What happens to a sample after the board computes it, why the volume knob is squared, and the echo guard that keeps the microphone from hearing the speaker as claps.

  • Key concepts: I2S out, class-D amplifier, timbre = harmonics, aliasing at 16 kHz, ADSR vs clicks, semitones & chords, tempo, procedural sound, squared volume.
  • Signals & pins: 3V3 (VCC), 3V3 (MICS +), GPIO6 (AO), GPIO7 (BLK), GPIO8 (RES).

Interactive diagram loads after page initialization.

A synth to play with

The same waves and envelope as the board. Pick a wave, press a key to hear it in this browser (quietly; nothing plays until you press), and drag the envelope's handles. The red bars are harmonics the board can't make at 16 kHz: they fold back as wrong notes.

Interactive wavetable and ADSR synthesizer generating sine, square, saw, and triangle tones over I2S. The same waves and envelope as the board. Pick a wave, press a key to hear it in this browser (quietly; nothing plays until you press), and drag the envelope's handles. The red bars are harmonics the board can't make at 16 kHz: they fold back as wrong notes.

  • Key concepts: I2S out, class-D amplifier, timbre = harmonics, aliasing at 16 kHz, ADSR vs clicks, semitones & chords, tempo, procedural sound, squared volume.
  • Signals & pins: 3V3 (VCC), 3V3 (MICS +), GPIO6 (AO), GPIO7 (BLK), GPIO8 (RES).

Interactive diagram loads after page initialization.

What the screen shows

Five views. Click = next, double-click = the action at the bottom left. Keys: long press = the next chord. Tunes and fx: long press picks the next one. Elsewhere a long press stops the sound.

Gallery of ST7789 audio visualizers rendered across the Sound track. Five views. Click = next, double-click = the action at the bottom left. Keys: long press = the next chord. Tunes and fx: long press picks the next one. Elsewhere a long press stops the sound.

  • Key concepts: I2S out, class-D amplifier, timbre = harmonics, aliasing at 16 kHz, ADSR vs clicks, semitones & chords, tempo, procedural sound, squared volume.
  • Signals & pins: 3V3 (VCC), 3V3 (MICS +), GPIO6 (AO), GPIO7 (BLK), GPIO8 (RES).

Interactive diagram loads after page initialization.

Wiring: the microphones and the speaker (wire what the lab needs; the screen stays as in lesson 03)

Module pinESP32-S3Notes
KY-037 + · G3V3The analog mic. + on the second 3V3 pin (the screen has the first), G on GND. Never 5 V: AO and DO swing up to the module's supply, and the ESP32-S3's pins take 3.3 V at most.
KY-037 AOGPIO 6Analog out: the microphone's voltage. GPIO 6 is ADC1 channel 5: ADC1 keeps working while Wi-Fi is on, ADC2 doesn't.
KY-037 DOGPIO 21Digital out: the LM393 comparator says high when the sound is louder than the blue trim pot's setting.
INMP441 VDD · GND3V3The digital mic (I2S). VDD on 3V3 (share the breadboard rail with the KY-037), GND on GND. 3.3 V only.
INMP441 L/RGNDLow = it talks in the left slot, the one the board reads.
INMP441 SCKGPIO 40The bit clock. The ESP32 drives it: 16 000 × 64 = 1.024 MHz.
INMP441 WSGPIO 41Word select: left slot / right slot, flips every 32 clock ticks.
INMP441 SDGPIO 42The data, most significant bit first. Pulled down, so a missing mic reads as zeros.
MAX98357A VIN · GND5VThe speaker amplifier. 5V gives the most (about 3 W into 4 Ω); 3V3 works, quieter.
MAX98357A BCLKGPIO 39Bit clock of the second I2S port (I2S1; the mic uses I2S0, so both run at once).
MAX98357A LRCGPIO 38Word select (left/right).
MAX98357A DINGPIO 47The samples, 16-bit.
MAX98357A GAIN · SDnothingLeave both unconnected: 9 dB gain, and it plays (left + right) / 2.
speaker (4 Ω, 3 W)amp + / −On the amplifier's screw terminal: the JST-PH2.0 lead's two wires, red to +.
screen (8 wires)as lesson 03Unchanged. The push button on GPIO 5 is optional: it does what BOOT does.

Commands, in order

Type these in the serial monitor (uv run pio device monitor) unless the grey tag says otherwise. The coloured tag says what should be near the board while it runs.

  1. uv run pio run -d labs/sound-lab-s7 -e sound-lab-s7 -t uploadMac terminalroom quiet
    Does
    Builds lab S7 and writes it to the board, then open the monitor with uv run pio device monitor.
    You should see
    Listening for an INMP441 on the I2S pins..., Microphone: INMP441 (I2S, digital) (mic setting: auto) (or KY-037), then Sound lab S7 …, the command list and a three-note hello from the speaker. Stay quiet for half a second: - learning the quiet...
    If not
    Wrong mic picked: mic inmp441 or mic ky037 (saved, restarts). No hello: the speaker is optional; check VIN and DIN. “Failed to connect”: hold BOOT, tap RST, release BOOT, run it again.
  2. vol 20serial monitorroom quiet
    Does
    Start quiet: volume is squared, 20 = 4 % of full power. Saved in NVS (default 40).
    You should see
    - volume 20; then beep plays 440 Hz.
    If not
    Silent: VIN to 5V, DIN to 47, BCLK 39, LRC 38; the speaker on the terminal.
  3. wave square, then wave sawserial monitorroom quiet
    Does
    The timbre: sine, square, triangle, saw, noise (wave next, or a double-click on wave).
    You should see
    - wave square; the spectrum's lines at 1, 3, 5… × the note.
  4. note A4 600serial monitorroom quiet
    Does
    One note (a name or Hz) for 600 ms. A double-click on envelope does the same.
    You should see
    The dot rides the ADSR curve.
    If not
    close to 8 kHz: the limit at 16 kHz above 7 kHz.
  5. adsr 1 300 0 50serial monitorroom quiet
    Does
    The envelope: attack ms, decay ms, sustain %, release ms (default 6 80 65 90). Attack 0 makes a click.
    You should see
    - adsr 1 300 0 50: a plucked string.
  6. chord Am (G7, Fmaj7, Bdim, Dsus4)serial monitorroom quiet
    Does
    Notes together on a one-voice speaker: the board adds them into one buffer (30 s in PSRAM).
    You should see
    - Am = A4 C5 E5; three keys light on keys.
  7. play C4 E4 G4/2 r/4 C5serial monitorroom quiet
    Does
    Notes one after another at bpm (default 120): /4 quarter, /8 eighth, r rest, . dotted.
    You should see
    The keys light in turn.
  8. tune korobeinikiserial monitorroom quiet
    Does
    twinkle ode happy korobeiniki scale arpeggio. Double-click on tunes plays the picked one; long press picks the next.
    You should see
    The piano roll scrolls past the amber playhead.
  9. fx laser (coin jump powerup explosion siren modem)serial monitorroom quiet
    Does
    Game sounds from recipes: sweeps, noise, a closing filter.
    You should see
    The whole waveform on fx, a playhead crossing it.
  10. stopserial monitorsound: doesn't matter
    Does
    Silence.
    You should see
    The waves in the header stop.

Steps

0 of 5 ticked. Ticks are saved in this browser.

One speaker, one stream: chords and tunes are rendered into PSRAM first (up to 30 s), then played. At 16 000 samples a second nothing above 8 kHz exists, so a square or saw's high harmonics fold back down as wrong frequencies: a slight grit on high notes, the honest limit of a simple synth. Every other sound lab uses the same speaker for its chimes, and the echo guard keeps its detectors deaf while it plays.

Preview: what you should see

Interactive audio lab simulator displaying live waveforms, dBFS loudness, FFT bins, and synthesized tones.

  • Key concepts: I2S out, class-D amplifier, timbre = harmonics, aliasing at 16 kHz, ADSR vs clicks, semitones & chords, tempo, procedural sound, squared volume.
  • Signals & pins: 3V3 (VCC), 3V3 (MICS +), GPIO6 (AO), GPIO7 (BLK), GPIO8 (RES).

Interactive diagram loads after page initialization.

ESP32-S3 peripherals used in this lab

Open interactive GPIO pinout

Explore the hardware blocks, pin rules, and registers behind this experiment.

  • GPIO and IO MUX

    45 pins, and a matrix that routes almost any signal to almost any pin

  • I2S

    Digital audio in and out: microphones, amplifiers, codecs

  • SPI

    Fast four-wire bus for screens, card readers and flash

  • SAR ADC

    Two 12-bit converters that turn a voltage into a number

  • GDMA

    Moves data between memory and peripherals without the CPU

  • UART

    Three serial ports, the one you see in the serial monitor

Troubleshooting & hardware gotchas

See all 17 ESP32-S3 hardware gotchas
What if it does not work or behaves unexpectedly?
One speaker, one stream: chords and tunes are rendered into PSRAM first (up to 30 s), then played. At 16 000 samples a second nothing above 8 kHz exists, so a square or saw's high harmonics fold back down as wrong frequencies: a slight grit on high notes, the honest limit of a simple synth. Every other sound lab uses the same speaker for its chimes, and the echo guard keeps its detectors deaf while it plays.
If “uv run pio run -d labs/sound-lab-s7 -e sound-lab-s7 -t upload” does not work
Wrong mic picked: mic inmp441 or mic ky037 (saved, restarts). No hello: the speaker is optional; check VIN and DIN. “Failed to connect”: hold BOOT, tap RST, release BOOT, run it again.
If “vol 20” does not work
Silent: VIN to 5V, DIN to 47, BCLK 39, LRC 38; the speaker on the terminal.
If “note A4 600” does not work
close to 8 kHz: the limit at 16 kHz above 7 kHz.
Four pins are read at reset
GPIO0, GPIO3, GPIO45 and GPIO46 are sampled the moment the chip comes out of reset: they pick the boot mode, the flash voltage, the ROM log and the JTAG source. Anything wired to them must not pull them the wrong way at power-up. After reset they are normal pins again.
GPIO3 has no pull resistor at reset
GPIO0 has a weak pull-up and GPIO45/46 weak pull-downs, but GPIO3 floats. When the eFuses make it choose the JTAG source, an outside circuit has to hold it at a clear level.
ADC2 stops working while Wi-Fi is on
The ADC2 channels (GPIO11-20) cannot be used at the same time as Wi-Fi: the radio shares ADC2 through an arbiter. Put analog sensors on ADC1 (GPIO1-10), as the sound labs do with GPIO6.
GPIO47 and 48 run at 1.8 V on R16V modules
Modules with the ESP32-S3R16V chip set the flash voltage to 1.8 V, and GPIO47/48 share that supply. A 3.3 V part on those pins sees the wrong levels.