-
-
Notifications
You must be signed in to change notification settings - Fork 283
PlatformIO
The library has been developed to be used in Arduino, but it can also be used easily in PlatformIO.
-
Create a new PlatformIO Project.
-
Update the platformio.ini file in the root of the project:
[platformio]
description = A2DP Example
default_envs = esp32dev
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = https://github.com/pschatzmann/ESP32-A2DP
https://github.com/pschatzmann/arduino-audio-tools.git
build_flags = -DCORE_DEBUG_LEVEL=2
board_build.partitions = huge_app.csv
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
In the build_flags you can also set the variables defined in config.h: e.g. -DA2DP_I2S_AUDIOTOOLS=1 is activating the output via AudioTools and -DA2DP_LEGACY_I2S_SUPPORT=1 is activating the legacy output support.
If you use a2dp with the audio tools, you need to specify the partition scheme to make sure that you have enough PROGMEM for the application.
- Add your desired Arduino sketch into the src directory e.g.
#include <Arduino.h>
#include "AudioTools.h"
#include "BluetoothA2DPSink.h"
I2SStream i2s;
BluetoothA2DPSink a2dp_sink(i2s);
void setup() {
a2dp_sink.start("MyMusic");
}
void loop() {
}
The file name does not matter but is should have a cpp or ino extension - you could use e.g. simple.ino or main.cpp. You could also take e.g. any sketch from the samples directory.
- Compile the project
This step also automatically installs the ESP32-A2DP project into the .pio/libdeps/esp32dev/ESP32-A2DP/ directory.
-
Upload the binary
-
Open a new Platformio Terminal and confirm that you get log messages:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
[D][BluetoothA2DPSink.cpp:154] start(): start
[I][BluetoothA2DPSink.cpp:159] start(): Device name will be set to 'MyMusic'
[D][BluetoothA2DPSink.cpp:735] init_nvs(): init_nvs
[D][BluetoothA2DPSink.cpp:751] get_last_connection(): get_last_connection
[D][BluetoothA2DPSink.cpp:222] init_bluetooth(): init_bluetooth
[I][BluetoothA2DPSink.cpp:227] init_bluetooth(): controller initialized
[I][BluetoothA2DPSink.cpp:236] init_bluetooth(): bluedroid initialized
[I][BluetoothA2DPSink.cpp:244] init_bluetooth(): bluedroid enabled
[D][BluetoothA2DPSink.cpp:326] app_task_start_up(): app_task_start_up
[D][BluetoothA2DPSink.cpp:879] app_task_handler_2(): app_task_handler_2
[D][BluetoothA2DPSink.cpp:852] app_task_handler(): app_task_handler
[D][BluetoothA2DPSink.cpp:299] app_task_handler(): app_task_handler
[D][BluetoothA2DPSink.cpp:251] app_work_dispatch(): app_work_dispatch event 0x0, param len 0
[D][BluetoothA2DPSink.cpp:283] app_send_msg(): app_send_msg
[D][BluetoothA2DPSink.cpp:306] app_task_handler(): app_task_handler, sig 0x1, 0x0
[W][BluetoothA2DPSink.cpp:309] app_task_handler(): app_task_handler, APP_SIG_WORK_DISPATCH sig: 1
[D][BluetoothA2DPSink.cpp:274] app_work_dispatched(): app_work_dispatched
[D][BluetoothA2DPSink.cpp:176] operator()(): av_hdl_stack_evt_2
[D][BluetoothA2DPSink.cpp:583] av_hdl_stack_evt(): av_hdl_stack_evt evt 0
[D][BluetoothA2DPSink.cpp:588] av_hdl_stack_evt(): av_hdl_stack_evt av_hdl_stack_evt BT_APP_EVT_STACK_UP
[D][BluetoothA2DPSink.cpp:597] av_hdl_stack_evt(): AVRCP controller initialized!
[D][BluetoothA2DPSink.cpp:621] av_hdl_stack_evt(): esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE)
- Make adjustments
- You can extend the sketch with your own logic
- You could replace the sketch with any other example that can be found in .pio/libdeps/esp32dev/ESP32-A2DP/examples
- After you confirmed that everything is working you should consider to lower the debug level in platformio.ini because a high log level might impact the sound quality!
You can request a specific ESP32 core version (e.g. 2.0.3) with the help of platform_packages.
[platformio]
description = A2DP Example
default_envs = esp32dev
[env:esp32dev]
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
board = esp32dev
framework = arduino
lib_deps = https://github.com/pschatzmann/ESP32-A2DP
https://github.com/pschatzmann/arduino-audio-tools.git
platform_packages = platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.3
build_flags = -DCORE_DEBUG_LEVEL=5
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
I was using the lib_deps functionality. As an alternative you could remove the lib_deps = https://github.com/pschatzmann/ESP32-A2DP
and do a git clone https://github.com/pschatzmann/ESP32-A2DP
into the lib folder
a high CORE_DEBUG_LEVEL (e.g 5) helps to identify issues. It is however also a potential source of troubles and has a big impact on the stability and audio quality! - so try to keep it as low as possible: 1 displays only Errors, 2 displays errors and warnings.