Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[arduino code examples for AS]-06 how to play MP3 file by SD Card
#1
Code:
/*
  ESP32 SD I2S Music Player
  esp32-i2s-sd-player.ino
  Plays MP3 file from microSD card
  Uses MAX98357 I2S Amplifier Module
  Uses ESP32-audioI2S Library - https://github.com/schreibfaul1/ESP32-audioI2S
*/

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

// microSD Card Reader connections
#define SD_CS         13
#define SPI_MOSI      12
#define SPI_MISO      10
#define SPI_SCK       11

// I2S Connections
#define I2S_DOUT      8
#define I2S_BCLK      7
#define I2S_LRC       6

// Create Audio object
Audio audio;

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(50);
   
    // Open music file
    audio.connecttoFS(SD,"/music.mp3");
   
}

void loop()
{
    audio.loop();   
}
place music.mp3 file on your SD card, make sure SD card is FAT32 format. when board power on, will auto play the MP3 file.
arduino ino file download:
.zip   AS-mp3.zip (Size: 760 bytes / Downloads: 21)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:
.zip   AS-mp3.ino.merged.zip (Size: 878.75 KB / Downloads: 24)
arduino IDE compile setting:    
Reply


Messages In This Thread
[arduino code examples for AS]-06 how to play MP3 file by SD Card - by admin - 10-22-2024, 01:12 AM

Forum Jump:


Users browsing this thread:
1 Guest(s)