error: 'SD_SCK_MHZ' was not declared in this scope

CobaltEcho
Posts: 7
Joined: Sun Aug 13, 2023 10:35 pm

error: 'SD_SCK_MHZ' was not declared in this scope

Postby CobaltEcho » Sun Aug 20, 2023 1:54 pm

I'm newer to coding and this is on of my first real projects (ESP32 Dev), I've figured a bunch of stuff out, but I'm banging my head agasinst the wall on this one! I can't seem to get rid of the error:

Code: Select all

error: 'SD_SCK_MHZ' was not declared in this scope
It'd (supposedly) defined on line 8 of the main code (below), and called on line 36.

I was also told that:
"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".
If anyone has any input or could point me in the right direction, that would be great.

I'm using the ESP8266Audio Library (which also works for ESP32).
https://github.com/earlephilhower/ESP8266Audio

Code: Untitled.cpp Select all


//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;
}

MicroController
Posts: 2694
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: error: 'SD_SCK_MHZ' was not declared in this scope

Postby MicroController » Mon Aug 21, 2023 3:40 pm

You can try and #include "SdSpiDriver.h", or just use the actual desired value in Hz...

Who is online

Users browsing this forum: Qwantbot, RathiSonika and 3 guests