Skip to content

chaoticvoltlabs/ESP32-Bluetooth-speaker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ESP32 Bluetooth Speaker

A Bluetooth A2DP audio receiver for ESP32 that streams audio to a MAX98357A I2S DAC.

Features

  • 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

Hardware Requirements

  • ESP32-WROOM-32 module
  • MAX98357A I2S DAC module
  • Speaker (4-8 ohm)
  • 5V power supply

Wiring

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

Software Requirements

  • ESP-IDF v6.0-beta1 or later
  • Python 3.8+

Building

# 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.bin

Flashing

Direct flashing (ESP32 connected via USB)

idf.py -p /dev/ttyUSB0 flash

Manual flashing with merged binary

esptool.py --chip esp32 write_flash 0x0 build/merged-flash.bin

Usage

  1. Power on the ESP32
  2. On your phone/computer, search for Bluetooth devices
  3. Connect to "ESP32 Speaker"
  4. Accept the pairing request (numeric comparison)
  5. Play audio - it will stream to the connected speaker

Configuration

Changing Device Name

Edit main/main.c:

#define BT_DEVICE_NAME "Your Speaker Name"

Changing I2S Pins

Edit main/main.c:

#define I2S_BCK_PIN     GPIO_NUM_26
#define I2S_WS_PIN      GPIO_NUM_25
#define I2S_DATA_PIN    GPIO_NUM_22

Serial Monitor

Connect at 115200 baud to see debug output:

idf.py -p /dev/ttyUSB0 monitor

Project Structure

esp32-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

Technical Details

Bluetooth Stack

  • Controller mode: BR/EDR only (Classic Bluetooth)
  • Profile: A2DP Sink
  • Codec: SBC
  • Pairing: Secure Simple Pairing (SSP) with numeric comparison

Audio Pipeline

Phone → Bluetooth A2DP → SBC Decoder → I2S → MAX98357A → Speaker

Watchdog

A 30-second task watchdog monitors system health. If the system hangs, it will automatically reboot.

Troubleshooting

Device not visible on Bluetooth

  • Ensure no other device is connected
  • Power cycle the ESP32
  • Check serial output for errors

No audio output

  • Verify MAX98357A wiring
  • Check that audio is playing on the source device
  • Verify I2S pin configuration matches your wiring

Audio stuttering

  • Move closer to the ESP32
  • Reduce interference from other 2.4GHz devices
  • Ensure adequate power supply

License

MIT License - See LICENSE file

Author

Robin Kluit

Version History

  • 1.0 - Initial release

About

A Bluetooth A2DP audio receiver for ESP32 that streams audio to a MAX98357A I2S DAC.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors