Paying a tone with the ESPMUSE LUXE

Hi, I’m trying to figure out how to play a tone with the ESPMUSE LUXE.
Taking inspiration from the factory tests, I have created this minimal working example… but the speaker makes no sound at all:

#include <driver/i2s.h>
#include "Arduino.h"

#define BLOCK_SIZE 128

void setup()
{ // Start Serial communication
    Serial.begin(115200);

    delay(3000);
    Serial.println("Hello World!");
    // Configure I2S peripheral
    const i2s_config_t i2s_config = {
        .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_TX), // Receive, transfer
        .sample_rate = 44100,
        .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
        .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
        .communication_format = I2S_COMM_FORMAT_I2S,
        .intr_alloc_flags = ESP_INTR_FLAG_LEVEL2,
        .dma_buf_count = 4,
        .dma_buf_len = BLOCK_SIZE};

    i2s_pin_config_t pin_config = {
        .bck_io_num = 5,    // BCKL
        .ws_io_num = 25,    // LRCL
        .data_out_num = 26, // DOUT
        .data_in_num = 35   // DIN
    };

    i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
    i2s_set_pin(I2S_NUM_0, &pin_config);
}

void loop()
{
    // Generate a simple sine wave
    const int sample_count = 44100 * 2; // Number of audio samples (approximately 2 seconds)
    const float frequency = 440.0;      // Frequency of the sine wave (Hz)
    const float amplitude = 0.8;        // Amplitude of the sine wave (0.0 to 1.0)
    const float volume = 15;            // Volume factor (adjust as needed)

    const float increment = frequency / 44100.0 * 2.0 * 3.14159;
    float angle = 0.0;

    int16_t samples[BLOCK_SIZE];

    for (int i = 0; i < sample_count; i += BLOCK_SIZE)
    {
        for (int j = 0; j < BLOCK_SIZE; j++)
        {
            float value = sin(angle);
            int16_t sample = static_cast<int16_t>(value * amplitude * INT16_MAX * volume);
            samples[j] = sample;

            angle += increment;
        }

        // Play the generated samples
        size_t bytes_written = 0;
        esp_err_t err = i2s_write(I2S_NUM_0, samples, BLOCK_SIZE * sizeof(int16_t), &bytes_written, portMAX_DELAY);

        if (err != ESP_OK)
        {
            Serial.printf("I2S write error: %d\n", err);
        }
        else
        {
            Serial.printf("Bytes written: %d\n", bytes_written);
        }
    }

    Serial.println("Sine wave playback complete");

    delay(9000);
}

Are the i2s config values wrong?

Any help would be appreciated!

Hi!

On the LUXE you have a ES8388 codec Involved so there are I2C commands to start playing, set the volume and so

check

right, thanks I overlooked that I should actually use I2C!

I tried to run the code proposed here instead but also without any luck.

#include "FS.h"
#include "SD.h"
#include "SPI.h"
#include <SDCard.h>
#include "Audio.h"

// Digital I/O used
#define I2S_DOUT 25
#define I2S_BCLK 27
#define I2S_LRC 26

#define SD_CS 13
#define SPI_MOSI 15
#define SPI_MISO 2
#define SPI_SCK 14

Audio audio;

void listDir(fs::FS &fs, const char *dirname, uint8_t levels)
{
  Serial.printf("Listing directory: %s\n", dirname);

  File root = fs.open(dirname);
  if (!root)
  {
    Serial.println("Failed to open directory");
    return;
  }
  if (!root.isDirectory())
  {
    Serial.println("Not a directory");
    return;
  }

  File file = root.openNextFile();
  while (file)
  {
    if (file.isDirectory())
    {
      Serial.print("  DIR : ");
      Serial.println(file.name());
      if (levels)
      {
        listDir(fs, file.name(), levels - 1);
      }
    }
    else
    {
      Serial.print("  FILE: ");
      Serial.print(file.name());
      Serial.print("  SIZE: ");
      Serial.println(file.size());
    }
    file = root.openNextFile();
  }
}

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

  // Initialize SD card
  SPIClass spi = SPIClass(VSPI);

  spi.begin(SPI_SCK, SPI_MISO, SPI_MOSI, SD_CS);

  if (!SD.begin(SD_CS, spi))
  {
    Serial.println("Error: SD card initialization failed.");
    return;
  }

  delay(2000);

  uint8_t cardType = SD.cardType();

  if (cardType == CARD_NONE)
  {
    Serial.println("No SD card attached");
    return;
  }

  Serial.print("SD Card Type: ");
  if (cardType == CARD_MMC)
  {
    Serial.println("MMC");
  }
  else if (cardType == CARD_SD)
  {
    Serial.println("SDSC");
  }
  else if (cardType == CARD_SDHC)
  {
    Serial.println("SDHC");
  }
  else
  {
    Serial.println("UNKNOWN");
  }

  uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  Serial.printf("SD Card Size: %lluMB\n", cardSize);

  listDir(SD, "/", 0);
  Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
  Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));

  delay(1000);

  audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
  audio.setVolume(21); // 0...21

  audio.connecttoSD("/320k_test.mp3");

  delay(2000);
}

void loop()
{
  Serial.println("Playing sample 1");
  audio.loop();

}

After the 3 time stepping into audio.loop() it fails with Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.:

Full output:

rst:0xc (SW_CPU_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13132
load:0x40080400,len:3036
entry 0x400805e4
[    10][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
SD Card Type: SDHC
SD Card Size: 30436MB
Listing directory: /
  FILE: test.txt  SIZE: 0
  FILE: life.wav  SIZE: 169086
  FILE: foo.txt  SIZE: 13
  FILE: 320k_test.mp3  SIZE: 9610227
Total space: 30424MB
Used space: 9MB
Connect to SD file /320k_test.mp3
[ 13420][V][ssl_client.cpp:324] stop_ssl_socket(): Cleaning SSL connection.
info        Reading file: 320k_test.mp3
1
info        ID3 version=3
ID3 framesSize=4342
info        ID3 framesSize=4342
info        ID3 normal frames
id3data     Title: No Cover Song [Abseed Remix]
id3data     Year: 2010
id3data     Comment: engVocals by : Deep SpiritMusic by : MTBD & Dj PaPa Br��n (Abseed)Copyright: Abcd 2010Official Release : Abcd lease : Abcd 
id3data     BeatsPerMinute: 143
id3data     Comment: sveE-Mail : Abseed_music@hotmail.coo
id3data     Album: 
id3data     Publisher: Magnus L�nberg, Johannes Bruun
id3data     Artist: Deep Spirit
Playing sample 1
[ 15534][I][Audio.cpp:692] loop(): bcw = 1600
[ 15534][I][Audio.cpp:693] loop(): m_inBuffwindex = 0
[ 15534][I][Audio.cpp:694] loop(): m_inBuffsize = 1600
[ 15538][I][Audio.cpp:695] loop(): m_inbuffrindex = 0
[ 15542][I][Audio.cpp:696] loop(): m_inBuff = 1073524221
[ 15547][I][Audio.cpp:700] loop(): res = 1600
info        stream ready
info        stream ready
info        syncword found at pos 0
info        SampleRate=44100
info        Channels=2
info        BitsPerSample=16
info        Bitrate=320000
Playing sample 1
[ 15614][I][Audio.cpp:692] loop(): bcw = 1044
[ 15614][I][Audio.cpp:693] loop(): m_inBuffwindex = 556
[ 15614][I][Audio.cpp:694] loop(): m_inBuffsize = 1600
[ 15618][I][Audio.cpp:695] loop(): m_inbuffrindex = 1044
[ 15623][I][Audio.cpp:696] loop(): m_inBuff = 1073524221
[ 15628][I][Audio.cpp:700] loop(): res = 1044
info        stream ready
Playing sample 1
[ 15654][I][Audio.cpp:692] loop(): bcw = 1045
[ 15654][I][Audio.cpp:693] loop(): m_inBuffwindex = 555
[ 15654][I][Audio.cpp:694] loop(): m_inBuffsize = 1600
[ 15658][I][Audio.cpp:695] loop(): m_inbuffrindex = 1045
[ 15663][I][Audio.cpp:696] loop(): m_inBuff = 1073524221
[ 15668][I][Audio.cpp:700] loop(): res = 1045
info        stream ready
Playing sample 1
[ 15693][I][Audio.cpp:692] loop(): bcw = 1045
[ 15693][I][Audio.cpp:693] loop(): m_inBuffwindex = 555
[ 15693][I][Audio.cpp:694] loop(): m_inBuffsize = 1600
[ 15697][I][Audio.cpp:695] loop(): m_inbuffrindex = 1045
[ 15702][I][Audio.cpp:696] loop(): m_inBuff = 1073524221
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x400e1a8f  PS      : 0x00060c30  A0      : 0x800dbc6a  A1      : 0x3ffb2530  
A2      : 0x800e2658  A3      : 0x000000ff  A4      : 0x00003d5b  A5      : 0x0000f9c0  
A6      : 0x3ffd4600  A7      : 0x3ffcadfd  A8      : 0x800e2658  A9      : 0x00000000  
A10     : 0x3beb0000  A11     : 0xf9c00000  A12     : 0x3ffd4600  A13     : 0x00060c23  
A14     : 0x00060c20  A15     : 0x00000001  SAR     : 0x0000000a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x800e2658  LBEG    : 0x40084475  LEND    : 0x4008447d  LCOUNT  : 0x00000027  


Backtrace:0x400e1a8c:0x3ffb25300x400dbc67:0x3ffb2550 0x400dbf81:0x3ffb2570 0x400dc025:0x3ffb2590 0x400dc431:0x3ffb25c0 0x400dc45e:0x3ffb25e0 0x40100296:0x3ffb2600 0x40100c3e:0x3ffb2620 0x40101be6:0x3ffb2640 0x40103a0f:0x3ffb2680 0x400ed6aa:0x3ffb26b0 0x40086f6d:0x3ffb26d0 0x40086eb1:0x3ffb26f0 0x4012520e:0x3ffb2710 0x401252a1:0x3ffb2750 0x4012424f:0x3ffb2770 0x400db8c3:0x3ffb2790 0x400d75f2:0x3ffb27b0 0x400db34b:0x3ffb2800 0x400e2655:0x3ffb2820 

Is there anything I’m doing wrong? The issue seems to be too much data loaded into memory?

pls show me your compiling options in Arduino