Core2 for AWS IoT EduKit BSP 1.5.1

This library provides convenience functions to interact with the on-board speaker to play audio at 44100Hz sample rate at 16-bit depth on a mono (right) channel. The NS4168 amplifier powers the on-board speaker and communicates with the ESP32-D0WD microcontroller over I2S. The I2S bus requires that the initialization and use of the peripheral on the bus is assigned to a dedicated core. The reason for this is that I2S and I2C attaches an interrupt to one of 32 interrupt vectors available per core. Attempting to initialize or access the peripheral without affinity to a specific core will most likely cause a hard fault almost immediately or at some point in time. The amplifier and the microphone share a GPIO and therefore, only one of them can be used at one time. You must de-initialize one if you intend to use the other.

Circuit Block Diagram for the speaker powered by the NS4168 1w amplifier

To enable this feature using KConfig, use the command pio run --environment core2foraws --target menuconfig from within the root of the project directory in your PlatformIO terminal window and go to the menu Component Config --> Core2 for AWS features to set the features you want to enable.


The following example creates a FreeRTOS task that's pinned to Core 1, which intializes and enables the speaker and plays 32 bytes of a 16-bit 44100Hz sound buffer. Once done playing the very brief sound, it deinitializes and disables the speaker. The size of the sound buffer is too short to be recognized by human ears.

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "core2forAWS.h"
static const char *TAG = "EXAMPLE";
static void speaker_task(void *arg){
/* If the microphone was initialized, be sure to call Microphone_Deinit()
first. */
const unsigned char sound[32] = {0x01,0x00,0xff,0xff,0x01,0x00,0xff,
Speaker_WriteBuff((uint8_t*)sound, 32, portMAX_DELAY);
void app_main(void){
/* Usage of the speaker must be pinned to a specific core since I2S ISR
is assigned per core */
xTaskCreatePinnedToCore(speaker_task, "play_sound", 4096*2, NULL, 4, NULL, 1);
void Core2ForAWS_Init(void)
Initializes the power chip with default values, enables battery charging, and initializes all enabled...
Definition: core2forAWS.c:32
void Core2ForAWS_Speaker_Enable(uint8_t state)
Enables or disables the NS4168 speaker amplifier.
Definition: core2forAWS.c:153
Functions to initialize and access Core2 for AWS IoT EduKit hardware features.
#define TAG
Definition: i2c_device.c:10
esp_err_t Speaker_WriteBuff(uint8_t *buff, uint32_t len, uint32_t timeout)
Plays buffer through the speaker.
Definition: speaker.c:48
esp_err_t Speaker_Deinit()
De-initializes the speaker.
Definition: speaker.c:53
esp_err_t Speaker_Init()
Initializes the speaker over I2S. The I2S bus is initialized for output with a sample rate of 44100Hz...
Definition: speaker.c:12