So far I used my arduino-audiokit library together with my AudioTools when I wanted to work with my AudioKit board. This library was a just quick and dirty adaptation of the drivers that were made available by the Espressif ADF framework to Arduino. But it had the following major drawbacks

  • it is complex and difficult to maintain with many layers and quite a lot of source code files in C
  • it is inflexible and you need to change a configuration file if you want to change the codec
  • it is inflexible if you need to adapt the pins e.g. for your custom board.

I finally took some time this week to write a new lean and flexible audio driver library that allows to select the codec in the Arduino Sketch and where you can define a new board with just a few lines of code!

Using a Predefined Board

Here is an example that shows how to set up the codec and I2S for a LyratV43 board:

#include "AudioTools.h"
#include "AudioLibs/I2SCodecStream.h"

I2SCodecStream i2s(LyratV43);

void setup() {
  // setup i2s and codec
  auto cfg = i2s.defaultConfig();
  cfg.sample_rate = 44100;
  cfg.bits_per_sample = 16;
  cfg.channels = 1;
  i2s.begin();

  // set volume
  i2s.setVolume(0.5);
}  

You can just specify the board in the constructor of the I2SCodecStream.

Defining Your Own Custom Codec Board

Here is one way to define your own board with your own pin assignments:

#include "AudioTools.h"
#include "AudioLibs/I2SCodecStream.h"

DriverPins my_pins;
AudioBoard my_board(AudioDriverES8388, my_pins);
I2SCodecStream i2s(my_board);

void setup() {
  // add i2c codec pins: scl, sda, port
  my_pins.addI2C(CODEC, 32, 22, 0x20);
  // add i2s pins: mclk, bclk, ws, data_out, data_in
  my_pins.addI2S(CODEC, 0, 27, 26, 25, 35);
  // add other pins: PA on gpio 21
  my_pins.addPin(PA, 21);

  // setup i2s and codec
  auto cfg = i2s.defaultConfig();
  cfg.sample_rate = 44100;
  cfg.bits_per_sample = 16;
  cfg.channels = 1;
  i2s.begin();

  // set volume
  i2s.setVolume(0.5);

}

You just define your board which consists of a driver implementation and add your custom pin definitions!

Further Information

Further information can be found in


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *