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

  1. //Play MP3 files from SD Card
  2.  
  3. #include <Arduino.h>
  4. #include "AudioFileSourceSD.h"
  5. #include "AudioGeneratorMP3.h"
  6. #include "AudioOutputI2S.h"
  7.  
  8. #define SPI_SPEED SD_SCK_MHZ(4)
  9. // SD Card Pins
  10. #define SCK 18  // GPIO 18
  11. #define MISO 19 // GPIO 19
  12. #define MOSI 23 // GPIO 23
  13. #define CS 2    // GPIO 2
  14.  
  15. // For amp hookup for speaker:
  16. // Audio Signal + : Analog Audio Out = Pin GPIO 25 / DAC1
  17. // Audio Signal - : Ground
  18.  
  19. File dir;
  20. AudioOutputI2S *output = NULL;
  21. AudioFileSourceSD *source = NULL;
  22. AudioGeneratorMP3 *decoder = NULL;
  23. bool first = true;
  24.  
  25. void setup()
  26. {
  27.   Serial.begin(115200);
  28.   Serial.println();
  29.   delay(1000);
  30.  
  31.   audioLogger = &Serial;
  32.   output = new AudioOutputI2S(0, 1); // Using Internal DAC1, Analog Audio on Pin 25
  33.   source = new AudioFileSourceSD();
  34.   decoder = new AudioGeneratorMP3();
  35.  
  36.   if (!SD.begin(CS, SPI_SPEED))
  37.   {
  38.     Serial.println("Problem starting SD");
  39.     return;
  40.   }
  41.   Serial.println("SD initialised.");
  42.   dir = SD.open("/");
  43. }
  44.  
  45. void loop()
  46. {
  47.   if ((decoder) && (decoder->isRunning()))
  48.   {
  49.     if (!decoder->loop())
  50.       decoder->stop();
  51.   }
  52.   else
  53.   {
  54.     File file = dir.openNextFile();
  55.     if (file)
  56.     {
  57.       if (!first)
  58.       {
  59.         source->close();
  60.         if (source->open(file.name()))
  61.         {
  62.           Serial.printf_P(PSTR("Playing '%s' from SD card...\n"), file.name());
  63.           decoder->begin(source, output);
  64.         }
  65.         else
  66.         {
  67.           Serial.printf_P(PSTR("Error opening '%s'\n"), file.name());
  68.         }
  69.       }
  70.       else
  71.         first = false;
  72.     }
  73.     else
  74.     {
  75.       Serial.println(F("Playback from SD card done\n"));
  76.       delay(1000);
  77.     }
  78.   }
  79. #endif;
  80. }

MicroController
Posts: 1708
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: No registered users and 113 guests