A Bluetooth A2DP audio receiver for ESP32 that streams audio to a MAX98357A I2S DAC.
- Bluetooth Classic A2DP sink (audio receiver)
- SBC codec decoding with automatic sample rate detection (16/32/44.1/48 kHz)
- I2S audio output to MAX98357A DAC
- iOS compatible (Secure Simple Pairing)
- Watchdog timer for crash recovery
- Serial debug output
- ESP32-WROOM-32 module
- MAX98357A I2S DAC module
- Speaker (4-8 ohm)
- 5V power supply
| ESP32 GPIO | MAX98357A | Description |
|---|---|---|
| GPIO26 | BCLK | Bit clock |
| GPIO25 | LRC | Word select (L/R clock) |
| GPIO22 | DIN | Serial data |
| 3.3V | VIN | Power |
| GND | GND | Ground |
- ESP-IDF v6.0-beta1 or later
- Python 3.8+
# Set up ESP-IDF environment
. $IDF_PATH/export.sh
# Set target
idf.py set-target esp32
# Build
idf.py build
# Create merged binary for manual flashing
idf.py merge-bin --output build/merged-flash.binidf.py -p /dev/ttyUSB0 flashesptool.py --chip esp32 write_flash 0x0 build/merged-flash.bin- Power on the ESP32
- On your phone/computer, search for Bluetooth devices
- Connect to "ESP32 Speaker"
- Accept the pairing request (numeric comparison)
- Play audio - it will stream to the connected speaker
Edit main/main.c:
#define BT_DEVICE_NAME "Your Speaker Name"Edit main/main.c:
#define I2S_BCK_PIN GPIO_NUM_26
#define I2S_WS_PIN GPIO_NUM_25
#define I2S_DATA_PIN GPIO_NUM_22Connect at 115200 baud to see debug output:
idf.py -p /dev/ttyUSB0 monitoresp32-BT-spkr/
├── CMakeLists.txt # Project CMake configuration
├── sdkconfig.defaults # Default SDK configuration
├── README.md # This file
├── LICENSE # MIT License
└── main/
├── CMakeLists.txt # Main component CMake
└── main.c # Application source code
- Controller mode: BR/EDR only (Classic Bluetooth)
- Profile: A2DP Sink
- Codec: SBC
- Pairing: Secure Simple Pairing (SSP) with numeric comparison
Phone → Bluetooth A2DP → SBC Decoder → I2S → MAX98357A → Speaker
A 30-second task watchdog monitors system health. If the system hangs, it will automatically reboot.
- Ensure no other device is connected
- Power cycle the ESP32
- Check serial output for errors
- Verify MAX98357A wiring
- Check that audio is playing on the source device
- Verify I2S pin configuration matches your wiring
- Move closer to the ESP32
- Reduce interference from other 2.4GHz devices
- Ensure adequate power supply
MIT License - See LICENSE file
Robin Kluit
- 1.0 - Initial release