This project is written in Arduino and uses two libraries by Phil Schatzmann that enable Bluetooth audio output on the ESP32. After you install the libraries, you'll compile and upload the main program file to your board.
Install the Libraries
Both of the libraries that you need for this project are not in the Arduino IDE Library Manager, so you will need to install them manually.
ESP32-A2DP
Navigate to the ESP32-A2DP repository. Click on the green Code button at the top of the page and then click Download ZIP in the dropdown.
A popup window will open with your system's file manager. Find the ESP32-A2DP .ZIP folder that you downloaded and click Open.
Arduino Audio Tools
Navigate to the Arduino Audio Tools repository. Click on the green Code button at the top of the page and then click Download ZIP in the dropdown.
A popup window will open with your system's file manager. Find the Arduino Audio Tools .ZIP folder that you downloaded and click Open.
Code
The code is the bt_music_receiver_arduino_i2s_3.ino example from the ESP32-A2DP library with the pins adjusted for the I2S wiring in this project.
// SPDX-FileCopyrightText: 2020 Phil Schatzmann // // SPDX-License-Identifier: GPL-3.0-or-later /* Streaming Music from Bluetooth Copyright (C) 2020 Phil Schatzmann This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ // ==> Example which shows how to use the built in ESP32 I2S >= 3.0.0 #include "ESP_I2S.h" #include "BluetoothA2DPSink.h" const uint8_t I2S_SCK = 8; /* Audio data bit clock */ const uint8_t I2S_WS = 7; /* Audio data left and right clock */ const uint8_t I2S_SDOUT = 14; /* ESP32 audio data output (to speakers) */ I2SClass i2s; BluetoothA2DPSink a2dp_sink(i2s); void setup() { i2s.setPins(I2S_SCK, I2S_WS, I2S_SDOUT); if (!i2s.begin(I2S_MODE_STD, 44100, I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO, I2S_STD_SLOT_BOTH)) { Serial.println("Failed to initialize I2S!"); while (1); // do nothing } a2dp_sink.start("Lumon Industries Speaker"); } void loop() { }
The code initializes the I2S DAC and creates a Bluetooth device called Lumon Industries Speaker
that will begin advertising for you to connect to. All of the actual Bluetooth and audio code exists in the two libraries used.
Page last edited March 24, 2025
Text editor powered by tinymce.