Can the esp32 be used for I2S via Bluetooth and SD at the same time?

Hi guys, for my project I need to use both the ESP32's Bluetooth and the .mp3 files on my micro SD to play them.
I use a MAX98357A, a mini SD module (3.3V - CS - MOSI -CLK - MISO -GND)
I don't need it to play at the same time but I do need the bluetooth to always be connected to the esp32 to play a sound and on the other hand when I press certain buttons it plays the audios saved on the SD.
My problem is that it causes interference when using the same I2S channel, in the same code it does not do both things, for example: it plays from the SD and it appears that I can connect the bluetooth but it does not allow me.
I also tried using 2 amplifiers, 1 for SD and one for bluetooth but still only one works.
I don't know if anyone else has this problem and has been able to solve it, can you please help me, I attached code; (at the moment do not implement the buttons in this code, just play the same audio /vaca.mp3)

// Include required libraries
#include "Arduino.h"
#include "Audio.h"
#include "SD.h"
#include "FS.h"
#include "BluetoothA2DPSink.h"

// microSD Card Reader connections
#define SD_CS          5
#define SPI_MOSI      23
#define SPI_MISO      19
#define SPI_SCK       18

// I2S Connections MAX98357A
#define I2S_DOUT      25
#define I2S_BCLK      26
#define I2S_LRC       27

// Create Audio and Bluetooth objects
Audio audio;
BluetoothA2DPSink bluetooth;

void setup() {
    // Set microSD Card CS as OUTPUT and set HIGH
    pinMode(SD_CS, OUTPUT);
    digitalWrite(SD_CS, HIGH);

    // Initialize SPI bus for microSD Card
    SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);

    // Start Serial Port
    Serial.begin(115200);

    // Start microSD Card
    if (!SD.begin(SD_CS)) {
        Serial.println("Error accessing microSD card!");
        while (true);
    }

    // Setup I2S
    audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);

    // Set Volume
    audio.setVolume(30);

    // Open music file
    audio.connecttoFS(SD, "/vaca.mp3");

    // Start Bluetooth
    i2s_pin_config_t configBT = {
        .mck_io_num = I2S_PIN_NO_CHANGE,
        .bck_io_num = I2S_BCLK,
        .ws_io_num = I2S_LRC,
        .data_out_num = I2S_DOUT,
        .data_in_num = I2S_PIN_NO_CHANGE
    };
    bluetooth.set_pin_config(configBT);
    bluetooth.start("ESP32_Audio");
}

void loop() {
    audio.loop();
}

Is it sock puppet season again? Word for translated word copy of a previous topic.

Sorry to the community, we thought it was separate from English to Spanish and that's why it was duplicated in another language. (I can't delete it)

1 Like

@pauvsaa19 ,

You cannot have the same topic twice, the language is irrelevant. The reason is you then have 2 lots of volunteers working for free each possibly unaware of the other and so wasting their time.

Please decide which topic you wish to keep and let me know.

Once you let me know I will reopen whichever topic you want to keep.

You may send me a personal message.

Thank you

The OP has requested he / she continue with this topic. Please note that @pauvsaa19 and @Lauracastellanos02 are working together.