Sound · lesson 5 of 8
See which frequencies are in a sound
KY-037 or INMP441MAX98357A + speaker (optional)Our own FFT (no library) runs on the newest 512 samples about 25 times a second: bars from 100 Hz to 8 kHz, a scrolling waterfall, a tuner that names the note you whistle or hum, and a game you steer with the pitch of your whistle. With the speaker, the board checks itself: ref plays a reference note for the tuner, sweep climbs from 100 Hz to 8 kHz across the bars.
Find the frequency of your whistle, see why finer bins are slower, and score in the steer game.
You're done when
- The bars view shows a single tall bar when you whistle and many low ones when you talk.
- The tuner names your note and the needle goes teal within ±5 cents.
fft 1024andfft 256: you can say what changed (Hz per bin, how fast it reacts).- steer: you scored at least 3 targets.
On the board
- 3V3VCC
- 3V3MICS +
- GPIO 6AO
- GPIO 7BLK
- GPIO 8RES
- GPIO 9DC
- GPIO 10CS
- GPIO 11SDA
- GPIO 12SCL
- 5VAMP VIN
- GNDGND
- GPIO 5BTN
- GNDMICS G
- GPIO 42SD
- GPIO 41WS
- GPIO 40SCK
- GPIO 39BCLK
- GPIO 38LRC
- GPIO 0BOOT
- GPIO 47DIN
- GPIO 21DO
- GNDAMP G
You will learn
- FFT bins
- Hann window & leakage
- Nyquist (8 kHz)
- resolution vs speed
- log frequency
- notes & cents
- reference tones
- log sweep
uv run pio run -d labs/sound-lab-s5 -e sound-lab-s5 -t uploadParts required
Parts library- ESP32-S3-DevKitC-1 + USB-C data cable
- 1.9″ ST7789 screen
- KY-037 analog microphone
- INMP441 I²S microphone
- Optional: MAX98357A amp + speaker
Build a sound, see its spectrum
Up to three tones plus noise, the samples on top and the FFT's bins below. Untick the window to see leakage; change N to trade sharp bins for a slower answer.
Visual explanation of windowing, FFT frequency bins, sample rate, and Nyquist limit on ESP32-S3. Up to three tones plus noise, the samples on top and the FFT's bins below. Untick the window to see leakage; change N to trade sharp bins for a slower answer.
- Key concepts: FFT bins, Hann window & leakage, Nyquist (8 kHz), resolution vs speed, log frequency, notes & cents, reference tones, log sweep.
- Signals & pins: 3V3 (VCC), 3V3 (MICS +), GPIO6 (AO), GPIO7 (BLK), GPIO8 (RES).
Interactive diagram loads after page initialization.
From a whistle to a note
Six steps, the same as the tuner view does 25 times a second. Move the whistle slider and watch the parabola find the pitch between two bins.
Autocorrelation / peak-bin pitch tracker converting whistled frequencies into game controls. Six steps, the same as the tuner view does 25 times a second. Move the whistle slider and watch the parabola find the pitch between two bins.
- Key concepts: FFT bins, Hann window & leakage, Nyquist (8 kHz), resolution vs speed, log frequency, notes & cents, reference tones, log sweep.
- Signals & pins: 3V3 (VCC), 3V3 (MICS +), GPIO6 (AO), GPIO7 (BLK), GPIO8 (RES).
Interactive diagram loads after page initialization.
What the screen shows
Four views. Click = next, double-click = the action at the bottom left (hold, hold, peaks, target), long press = hold.
Gallery of ST7789 audio visualizers rendered across the Sound track. Four views. Click = next, double-click = the action at the bottom left (hold, hold, peaks, target), long press = hold.
- Key concepts: FFT bins, Hann window & leakage, Nyquist (8 kHz), resolution vs speed, log frequency, notes & cents, reference tones, log sweep.
- 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 pin | ESP32-S3 | Notes |
|---|---|---|
| KY-037 + · G | 3V3 | The 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 AO | GPIO 6 | Analog out: the microphone's voltage. GPIO 6 is ADC1 channel 5: ADC1 keeps working while Wi-Fi is on, ADC2 doesn't. |
| KY-037 DO | GPIO 21 | Digital out: the LM393 comparator says high when the sound is louder than the blue trim pot's setting. |
| INMP441 VDD · GND | 3V3 | The digital mic (I2S). VDD on 3V3 (share the breadboard rail with the KY-037), GND on GND. 3.3 V only. |
| INMP441 L/R | GND | Low = it talks in the left slot, the one the board reads. |
| INMP441 SCK | GPIO 40 | The bit clock. The ESP32 drives it: 16 000 × 64 = 1.024 MHz. |
| INMP441 WS | GPIO 41 | Word select: left slot / right slot, flips every 32 clock ticks. |
| INMP441 SD | GPIO 42 | The data, most significant bit first. Pulled down, so a missing mic reads as zeros. |
| MAX98357A VIN · GND | 5V | The speaker amplifier. 5V gives the most (about 3 W into 4 Ω); 3V3 works, quieter. |
| MAX98357A BCLK | GPIO 39 | Bit clock of the second I2S port (I2S1; the mic uses I2S0, so both run at once). |
| MAX98357A LRC | GPIO 38 | Word select (left/right). |
| MAX98357A DIN | GPIO 47 | The samples, 16-bit. |
| MAX98357A GAIN · SD | nothing | Leave 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 03 | Unchanged. 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.
uv run pio run -d labs/sound-lab-s5 -e sound-lab-s5 -t uploadMac terminalroom quiet- Does
- Builds lab S5 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), thenSound lab S5 …, 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 inmp441ormic 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.
(whistle, then hum)with your handsmake some noise- Does
- The bars view: one tall bar for a whistle (1-3 kHz), lower and wider for a hum.
- You should see
loudest 1.76 kHz (A6)at the top; right:N 512 - 31 Hz/bin - … us.- If not
- Nothing moves: whistle within a hand's width (no amplifier on the module).
peaksserial monitormake some noise- Does
- Prints the 5 strongest frequencies with their notes.
- You should see
1765.6 Hz -31.2 dBFS A6 +2 cents…
fft 1024serial monitorsound: doesn't matter- Does
- Twice as many samples: bins 15.6 Hz apart, but each answer looks at 64 ms.
fft 256: 62.5 Hz bins, 16 ms. - You should see
- FFT 1024: 15.6 Hz per bin, 64 ms window.
ref (or ref A4, ref 440)serial monitorroom quiet- Does
- A 1 s sine on the speaker: the note nearest to what you whistled in the last 2 s, else A4. S5 reads the ring directly, so it hears its own tone on purpose. Double-click on tuner does the same.
- You should see
- reference A4 = 440.0 Hz, 1 s; the tuner shows A4 with the needle near 0.- If not
- Off by many cents: the speaker and mic are fine; check
a4.
sweepserial monitorroom quiet- Does
- A 4 s tone from 100 Hz to 8 kHz on a log scale; the screen jumps to the waterfall.
- You should see
- A diagonal line climbing the waterfall at an even slope: log frequency, like the bars.
a4 442serial monitorsound: doesn't matter- Does
- Tunes the note names to A4 = 442 Hz (some orchestras do).
- You should see
- A4 = 442.0 Hz; the tuner's cents shift by about 8.
(steer view: whistle up and down)with your handsmake some noise- Does
- The dot follows your pitch on a log scale (600-2500 Hz); hold it in the ring 1 s to score. The RGB LED takes the dot's colour.
- You should see
+ target 1!, a new ring elsewhere.- If not
- Can't reach the top:
range 500 2000.
limitsserial monitorsound: doesn't matter- Does
- What this FFT can and can't see.
- You should see
- Up to 8000 Hz (Nyquist), bins 31.2 Hz apart, 32 ms per answer, and the no-amplifier warning.
Steps
0 of 6 ticked. Ticks are saved in this browser.
Limits worth knowing: at 16 000 samples a second nothing above 8 kHz can be seen (Nyquist), and higher sounds fold back as fakes. Each band learns its own quiet (a fan hums low, a laptop whines high), so the views show dB above each band's floor. Speech has many harmonics and no single clear peak, which is why the tuner wants clarity ≥ 12 dB: whistle or hum.
Preview: what you should see
Interactive audio lab simulator displaying live waveforms, dBFS loudness, FFT bins, and synthesized tones.
- Key concepts: FFT bins, Hann window & leakage, Nyquist (8 kHz), resolution vs speed, log frequency, notes & cents, reference tones, log sweep.
- 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 pinoutExplore 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
- RMT
Plays and records exact pulse trains: IR remotes, RGB LEDs
- SAR ADC
Two 12-bit converters that turn a voltage into a number
- GDMA
Moves data between memory and peripherals without the CPU
Troubleshooting & hardware gotchas
See all 17 ESP32-S3 hardware gotchas- What if it does not work or behaves unexpectedly?
- Limits worth knowing: at 16 000 samples a second nothing above 8 kHz can be seen (Nyquist), and higher sounds fold back as fakes. Each band learns its own quiet (a fan hums low, a laptop whines high), so the views show dB above each band's floor. Speech has many harmonics and no single clear peak, which is why the tuner wants clarity ≥ 12 dB: whistle or hum.
- If “uv run pio run -d labs/sound-lab-s5 -e sound-lab-s5 -t upload” does not work
- Wrong mic picked:
mic inmp441ormic 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 “(whistle, then hum)” does not work
- Nothing moves: whistle within a hand's width (no amplifier on the module).
- If “ref (or ref A4, ref 440)” does not work
- Off by many cents: the speaker and mic are fine; check
a4. - If “(steer view: whistle up and down)” does not work
- Can't reach the top:
range 500 2000. - 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.