As you might know from my last posts I am currently extending my Arduino Audio Tools library to support the AI Thinker Audio Kit which is based on the ES8388 audio chip.
.

Originally I was of the opinion that the program logic for reading of the GPIO pins and the processing of the related actions should belong into a specific Arduino sketch and should not be part of an Audio Framework.

The Audio Kit made me revise this because I think that an Arduino Sketch should be as concise as possible. Therefore I have created the AudioActions class that has been integrated into the AudioKit.

Audio Kit

Since the Audio Kit does not have any display, I think to use TTS is a good choice to feed back information to the user.

Here is the example:

Arduino Sketch

#include "flite_arduino.h"
#include "AudioTools.h"
#include "AudioDevices/ESP32AudioKit/AudioKit.h"

using namespace audio_tools;

AudioKitStream kit;
Flite flite(kit);

void button1(){
  flite.say("Button One");  
}
void button2(){
  flite.say("Button Two");  
}
void button3(){
  flite.say("Button Three");  
}
void button4(){
  flite.say("Button Four");  
}

// Arduino setup
void setup(){
  Serial.begin(115200);

  auto cfg = kit.defaultConfig();
  cfg.bits_per_sample = 16;
  cfg.channels = 1;
  cfg.sample_rate = 8000;
  kit.begin(cfg);

  // Assign pins to methods
  kit.addAction(PIN_KEY1, button1);
  kit.addAction(PIN_KEY2, button2);
  kit.addAction(PIN_KEY3, button3);
  kit.addAction(PIN_KEY4, button4);

  // example with actions using lambda expression
  auto down = []() { flite.say("Volume down"); kit.volumeDown(); };
  kit.addAction(PIN_KEY5, down);
  auto up = []() { flite.say("Volume up"); kit.volumeUp();  };
  kit.addAction(PIN_KEY6, up);

  // we are ready to process actions now
  flite.say("The application has started. Please push a button to select the function");

}

// Arduino Loop
void loop() {
  kit.processActions();
}

You just need to define you handler methods (button1, button2…) and assign them to the GPIO pins. The PIN_KEY5 and PIN_KEY6 have been predefined in the AudioKitStream to handle the volume. But you can overwrite this with your own methods – as demonstrated in the sketch.

I think it could not be easier then this!

Source Code

The source code for this example can also be found on Github. Please note that this example was working at the time of publishing. If you want to try it out please use this (potentially updated) example.

Dependencies

You need to install the following libraries:

Final Comments

I was quite happy with the AudioKit so far, but after some more trials I noted that the Kit has quite some design bugs: One of them is that there are pin conflicts: When the SD card is activated the key 1 and key 2 do not work any more!


7 Comments

Facu · 30. May 2022 at 0:15

Hi, I would like to ask about the DIP switches of the board, I have been trying to figure out the purpose of these DIP switches, I guess that are used to control the SD card or the JTAG.
Thank you for your work, it’s amazing!

    pschatzmann · 30. May 2022 at 12:33

    You find the use at the legend which is printed on the right of the switches. In a nutshell is defines how gpio13 and gpio15 are used.
    In a nutshell it is basically for choosing to use the SD drive or JTAG.

Ondrej · 25. March 2022 at 13:01

Hi!

I want to create a small application with a ESP32 Audio kit as is on th epicture at the top.

I’m confused, how to approach the arduino sketch.
I updated the boards definitions on version 2.0.2, but i don’t know, which board to choose.

After that, I want to play specific short mp3 sound based on input signal, like a pulse.

Would be someone so kind and help me setup the arduino project?

Thank you, very much.

    pschatzmann · 25. March 2022 at 13:20

    If you have an AI Thinker Audiokit 2.2 I suggest that you look at the Number next to the V2.2 and make an educated guess. If the selected number is not working try the other 2…

Qiang · 24. March 2022 at 1:55

Could you share the specs of resistor or capacitor above the buttons? My board has some empty slots above some of the buttons and four buttons not working…

Trixole · 17. March 2022 at 2:08

I know this is probably out of topic, but how can I use an I2C LCD with the board together? I tried many things to get it to work but I can’t get the headphone output and the LCD to work at the same time!

    pschatzmann · 17. March 2022 at 10:35

    I have never tried, but I think that I can recall having read that the issue might be with the pullup resistors.
    I suggest that you try to use some external pullup resistors and double check with the board_pins_config.c and board_def.h for the pin conflits.

Leave a Reply

Avatar placeholder

Your email address will not be published.