A nightstand noise generator based on M5Stack Atom Echo and integrating with Home Assistant
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 132 lines 5.4 kB view raw view rendered
1# Audio signal chain 2 3## Why we chose an I2S amp 4 5The ESP32 on the Atom Echo outputs **digital I2S** — a three-wire serial protocol carrying PCM samples as ones and zeros. No raw speaker or analog amp can play I2S; it has to be decoded first. 6 7Two architectures were on the table: 8 9| Path | Chain | Parts | 10| ---- | ----- | ----- | 11| **I2S amp (chosen)** | ESP32 → I2S amp → speaker | MAX98357A | 12| Analog amp | ESP32 → I2S DAC → analog amp → speaker | PCM5102A + PAM8302 | 13 14Both work. The I2S-amp path is shorter, uses one fewer board, has fewer wires, less noise surface, smaller enclosure footprint, and simpler ESPHome config. We're going with it. 15 16The onboard NS4168 on the Atom Echo is itself an I2S amp — the MAX98357A is in the same category, just better-suited because we can put it outside the thermally-constrained Atom Echo case and drive a properly-sized speaker. 17 18## Full signal chain 19 20``` 21 Atom Echo (ESP32-PICO-D4) 22 23 │ digital I2S: BCLK + LRCK + DOUT 24 │ (on unused GPIOs — G21, G26, G32) 25 26 MAX98357A 27 (I2S in, Class D amp out) 28 29 │ bridge-tied speaker output (V+ / V−) 30 │ no common ground to the speaker 31 32 GRS 3FR-4 (4Ω 25W max) 33``` 34 35## MAX98357A specs 36 37- **Input**: I2S (BCLK + LRCK + DIN) 38- **Output**: bridge-tied load, 3.2 W into 4Ω at 5V supply (matches our driver exactly) 39- **Gain**: configurable via GAIN pin — 3 / 6 / 9 / 12 / 15 dB. Floating = 9 dB default, which is fine for our volumes. 40- **Channel select (SD pin)**: 41 - Float = both L+R channels summed (mono mix) — our default 42 - Tied low = shutdown 43 - Tied with specific voltage dividers = left-only or right-only 44- **Supply**: 2.5–5.5 V (we use 5 V) 45- **Package**: on a ~21×16 mm breakout board (Adafruit 3006 variant; generic Chinese boards are similar size) 46 47## Wiring detail 48 49### Atom Echo → MAX98357A 50 51| Atom Echo pin | MAX98357A pin | Notes | 52| ------------------- | ------------- | ----- | 53| 5V | VIN | side header or GROVE red | 54| GND | GND | | 55| G26 (GROVE yellow) | BCLK | bit clock | 56| G32 (GROVE white) | LRC | word select (LRCK) | 57| G25 (side header) | DIN | I2S serial data — only safely-available external GPIO (G19/G22/G23/G33 are reserved for the onboard NS4168, G27 is the RGB LED, G39 is the button) | 58| — | SD | leave floating = mono (L+R summed) | 59| — | GAIN | leave floating = 9 dB default | 60 61### MAX98357A → speaker 62 63| MAX98357A | Speaker | 64| --------- | ------- | 65| OUT+ | speaker + | 66| OUT− | speaker − | 67 68**Bridge-tied load — don't ground either speaker terminal.** Both speaker wires go to the amp, nowhere else. 69 70### Power 71 72- Atom Echo powered via USB-C from a 5V 2A UL-listed wall adapter 73- MAX98357A taps 5V + GND from the Atom Echo's side header 74- Total estimated draw: Atom Echo ~0.3 A + MAX98357A at typical volume ~0.2 A ≈ 0.5 A. Well within a 2 A supply. 75 76## Volume control 77 78The MAX98357A has no onboard potentiometer — gain is fixed by the GAIN pin configuration. Volume comes from two places: 79 801. **GAIN pin** — set once at build time. Floating (9 dB) is the default and fine. If we find it's too loud at full software volume, pull GAIN to ground through a 100 kΩ resistor for 3 dB, or to VIN for 15 dB. We'll tune if needed. 812. **ESPHome software volume** (via HA) — fine-grained runtime control. 82 83## ESPHome config sketch 84 85```yaml 86i2s_audio: 87 - id: i2sout 88 i2s_lrclk_pin: GPIO32 89 i2s_bclk_pin: GPIO26 90 91speaker: 92 - platform: i2s_audio 93 id: echo_speaker 94 i2s_dout_pin: GPIO21 95 dac_type: external 96 mode: mono 97``` 98 99Critically, we do **not** configure the `speaker:` block against the onboard NS4168 pins (G19/G22/G33). That leaves the onboard amp receiving no I2S data — idle, silent, cool. 100 101## Pin availability recap 102 103Free GPIOs on the Atom Echo after accounting for mic / amp / LED / button: 104 105- G26 (GROVE yellow) → I2S BCLK 106- G32 (GROVE white) → I2S LRC 107- G25 (side header) → I2S DIN 108 109## Parts list for this chain (per unit) 110 111| Part | Source | Notes | 112| ---- | ------ | ----- | 113| M5Stack Atom Echo | owned | | 114| MAX98357A breakout | [Adafruit 3006][adafruit-3006] (~$6) or generic Amazon/AliExpress (~$3) | need 2 total for both units | 115| GRS 3FR-4 speaker | owned | see [reference/speakers/grs-3fr-4.md](./speakers/grs-3fr-4.md) | 116| 5V 2A USB wall adapter + USB-C cable | off-the-shelf | UL-listed brick | 117| Dupont wires / hookup wire | stock | | 118 119## Sources 120 121- [MAX98357A datasheet (Analog Devices / Maxim)][max98357-ds] 122- [Adafruit MAX98357 I2S Class-D Mono Amp (product page + guide)][adafruit-3006] 123- [ESPHome I²S Audio Speaker component][esphome-i2s] 124- [SparkFun I2S Audio Breakout (MAX98357A)][sparkfun-14809] 125- [M5Stack Atom Echo docs][m5-docs] — pin map 126- [Internal speaker disable notes](./atom-echo/disabling-internal-speaker.md) 127 128[max98357-ds]: https://www.analog.com/media/en/technical-documentation/data-sheets/MAX98357A-MAX98357B.pdf 129[adafruit-3006]: https://www.adafruit.com/product/3006 130[esphome-i2s]: https://esphome.io/components/speaker/i2s_audio/ 131[sparkfun-14809]: https://www.sparkfun.com/products/14809 132[m5-docs]: https://docs.m5stack.com/en/atom/atomecho