Code: Select all
error: 'SD_SCK_MHZ' was not declared in this scope
I was also told that:
If anyone has any input or could point me in the right direction, that would be great."As for the SD.begin, note that I'm not using the Arduino SD class. Actually, you don't need to add any other imports. This is because SD is already included in AudioFileSourceSD.h".
I'm using the ESP8266Audio Library (which also works for ESP32).
https://github.com/earlephilhower/ESP8266Audio
- //Play MP3 files from SD Card
- #include <Arduino.h>
- #include "AudioFileSourceSD.h"
- #include "AudioGeneratorMP3.h"
- #include "AudioOutputI2S.h"
- #define SPI_SPEED SD_SCK_MHZ(4)
- // SD Card Pins
- #define SCK 18 // GPIO 18
- #define MISO 19 // GPIO 19
- #define MOSI 23 // GPIO 23
- #define CS 2 // GPIO 2
- // For amp hookup for speaker:
- // Audio Signal + : Analog Audio Out = Pin GPIO 25 / DAC1
- // Audio Signal - : Ground
- File dir;
- AudioOutputI2S *output = NULL;
- AudioFileSourceSD *source = NULL;
- AudioGeneratorMP3 *decoder = NULL;
- bool first = true;
- void setup()
- {
- Serial.begin(115200);
- Serial.println();
- delay(1000);
- audioLogger = &Serial;
- output = new AudioOutputI2S(0, 1); // Using Internal DAC1, Analog Audio on Pin 25
- source = new AudioFileSourceSD();
- decoder = new AudioGeneratorMP3();
- if (!SD.begin(CS, SPI_SPEED))
- {
- Serial.println("Problem starting SD");
- return;
- }
- Serial.println("SD initialised.");
- dir = SD.open("/");
- }
- void loop()
- {
- if ((decoder) && (decoder->isRunning()))
- {
- if (!decoder->loop())
- decoder->stop();
- }
- else
- {
- File file = dir.openNextFile();
- if (file)
- {
- if (!first)
- {
- source->close();
- if (source->open(file.name()))
- {
- Serial.printf_P(PSTR("Playing '%s' from SD card...\n"), file.name());
- decoder->begin(source, output);
- }
- else
- {
- Serial.printf_P(PSTR("Error opening '%s'\n"), file.name());
- }
- }
- else
- first = false;
- }
- else
- {
- Serial.println(F("Playback from SD card done\n"));
- delay(1000);
- }
- }
- #endif;
- }