I can't get this base to work with the AtomS3R . The example on the website doesn't work due to an i2s conflict between new and legacy i2s drivers. I finally got the following program to run meaning I see the text on the display however I can't seem to hear anything. Not sure if it isn't recording or not playing back properly. Does anyone have recent working code for this pair? Thanks.
#include "M5Unified.h"
// Define buffer size (200KB for ESP32-S3)
#define RECORD_SIZE (1024 * 200)
static uint8_t *buffer = nullptr;
void setup()
{
auto cfg = M5.config();
// Enable external I2C for ES8311 codec on the audio base
cfg.external_imu = true;
M5.begin(cfg);
M5.Display.setFont(&fonts::FreeMonoBold9pt7b);
Serial.begin(115200);
// --------------------------
// Speaker Configuration (I2S Output)
// AtomS3R I2S pins: BCK=8, WS=6, DOUT=5
// --------------------------
auto spk_cfg = M5.Speaker.config();
spk_cfg.pin_data_out = 5;
spk_cfg.pin_bck = 8;
spk_cfg.pin_ws = 6;
spk_cfg.sample_rate = 44100;
spk_cfg.i2s_port = I2S_NUM_0;
spk_cfg.stereo = false; // Use mono for the base speaker
M5.Speaker.config(spk_cfg);
M5.Speaker.begin();
// --------------------------
// Microphone Configuration (I2S Input)
// AtomS3R I2S pins: BCK=8, WS=6, DIN=7
// --------------------------
auto mic_cfg = M5.Mic.config();
mic_cfg.pin_data_in = 7;
mic_cfg.pin_bck = 8;
mic_cfg.pin_ws = 6;
mic_cfg.sample_rate = 44100;
mic_cfg.i2s_port = I2S_NUM_1; // Use separate I2S port for input
M5.Mic.config(mic_cfg);
M5.Mic.begin();
// Set volume/gain
M5.Speaker.setVolume(50);
// For v0.2.14, set mic gain via config if needed (default works for most cases)
// mic_cfg.magnification = 2;
// Allocate recording buffer
buffer = (uint8_t *)malloc(RECORD_SIZE);
if (buffer == nullptr) {
Serial.println("Memory allocation failed!");
while (true) delay(1000);
}
Serial.println("Device ready! Press button to record/play");
M5.Display.println("Click to\nRecord & Play");
}
void loop()
{
M5.update();
if (M5.BtnA.wasClicked()) {
M5.Display.fillScreen(BLACK);
M5.Display.setCursor(0, 0);
// --------------------------
// Recording
// --------------------------
M5.Display.println("Recording...");
Serial.println("Start recording");
M5.Mic.record(buffer, RECORD_SIZE, 44100);
delay(3000);
// --------------------------
// Playback
// --------------------------
M5.Display.println("Playing...");
Serial.println("Start playing");
M5.Speaker.playRaw(buffer, RECORD_SIZE, 44100, false, 1);
while (M5.Speaker.isPlaying()) delay(10);
M5.Display.println("Done");
Serial.println("Done");
}
}