-
- Notifications
You must be signed in to change notification settings - Fork 309
Working with PlatformIO
The library has been developed to be used in Arduino, but it can also be used easily in PlatformIO. When
-
Create a new PlatformIO Project.
-
Update the platformio.ini file in the root of the project:
[platformio] description = Audio Example default_envs = esp32dev [env:esp32dev] platform = https://github.com/platformio/platform-espressif32.git board = esp32dev framework = arduino lib_deps = https://github.com/pschatzmann/arduino-audio-tools.git build_flags = -DCORE_DEBUG_LEVEL=5 -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-function -Wno-format-extra-args monitor_speed = 115200 monitor_filters = esp32_exception_decoder
Please note that:
- for the ESP32, I recommend to specify the partition scheme e.g.
board_build.partitions = huge_app.csv
. Here is the list of all available predefined options. - You can specify the GIT versions when you specify the library: e.g. https://github.com/pschatzmann/arduino-audio-tools.git#v0.9.8 if you don't want to use the main branch with the latest corrections.
- If you use another platform you need to adapt the settings depending your needs. e.g for the RP2040 use
[env:pico] platform = https://github.com/maxgerhardt/platform-raspberrypi.git board = pico framework = arduino board_build.core = earlephilhower
- you might need to add additional dependencies e.g.
lib_deps = https://github.com/pschatzmann/arduino-audio-tools, https://github.com/pschatzmann/arduino-libhelix, https://github.com/greiman/SdFat
- to get the best sound quality, I suggest to set build_flags = -DCORE_DEBUG_LEVEL=2 // stands for Warning
- if you use #platform = espressif32 inline variables are not supported. Change the platforms as indicated above.
- Add your desired Arduino sketch into the src directory e.g.
#include <Arduino.h> #include "AudioTools.h" AudioInfo info(44100, 2, 16); SineWaveGenerator<int16_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000 GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave I2SStream out; StreamCopy copier(out, sound); // copies sound into i2s // Arduino Setup void setup(void) { // Open Serial Serial.begin(115200); // start i2s Serial.println("starting I2S..."); I2SConfig config = out.defaultConfig(TX_MODE); config.copyFrom(info); out.begin(config); // Setup sine wave sineWave.begin(info, N_B4); } // Arduino loop - copy sound to out void loop() { copier.copy(); }
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 dependencies into the .pio/libdeps/esp32dev/ directory.
-
Upload the binary
-
Open a new Platformio Terminal and confirm that you get log messages.
-
Make adjustments
- You can extend the sketch with your own logic
- You could replace the sketch with any other example
- 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!
I was using the lib_deps functionality. As an alternative you could remove the lib_deps = https://github.com/pschatzmann/arduino-audio-tools
and do a git clone https://github.com/pschatzmann/arduino-audio-tools
into the lib folder
In oder to debug you need to have am USB JTAG adapter which needs to be connected to the microcontroller.
ESP32 | JTAG Adapter |
---|---|
GND | GND |
GPIO12 | TDI (Test Data In) |
GPIO15 | TDO (Test Data Out) |
GPIO13 | TCK (Test Clock) |
GPIO14 | TMS (Test Mode Select) |
n/a | TRST (Test Reset) optional |
For further information please consult Low-cost ESP32 In-circuit Debugging from Manuel Bl.