-
-
Notifications
You must be signed in to change notification settings - Fork 278
Working with 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 = Audio Example
default_envs = esp32dev
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps = https://github.com/pschatzmann/arduino-audio-tools
build_flags = -DCORE_DEBUG_LEVEL=5 -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-function -Wno-format-extra-args
monitor_speed = 115200
Please note that:
- 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
- Add your desired Arduino sketch into the src directory e.g.
#include <Arduino.h>
#include "AudioTools.h"
using namespace audio_tools;
typedef int16_t sound_t; // sound will be represented as int16_t (with 2 bytes)
uint16_t sample_rate=44100;
uint8_t channels = 2; // The stream will have 2 channels
SineWaveGenerator<sound_t> sineWave(32000); // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<sound_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 the bluetooth
Serial.println("starting I2S...");
I2SConfig config = out.defaultConfig(TX_MODE);
config.sample_rate = sample_rate;
config.channels = channels;
config.bits_per_sample = 16;
out.begin(config);
// Setup sine wave
sineWave.begin(channels, sample_rate, 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.