[SOLVED] TTGO T8 SD Card???

I just bought TTGO T8 board.

The board installed with “Hello World” and SD Card initialization sketch. It prints “Hello World” text and SD card files list in Serial Monitor when turn it on for the first time.

The problem is now I can’t make SD card works anymore.

Board picture says the SD card CS Pin is GPIO 13 but doesn’t work. Already tried changing CS pin to GPIO 2, 4, 14, 15 but also doesn’t work.

#include <SPI.h>
#include <SD.h>

File root;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.print("Initializing SD card...");

  if (!SD.begin(13)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  root = SD.open("/");

  printDirectory(root, 0);

  Serial.println("done!");
}

void loop() {
  // nothing happens after setup finishes.
}

void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}

Anybody knows how to enable TTGO T8 SD card?

Thanks.

if (!SD.begin(13)) {

For ESP boards the pins defintions (D0, D1, D2, etc.) are not set to the corresponding integer values. So try

if (!SD.begin(D13)) {

pylon:
For ESP boards the pins defintions (D0, D1, D2, etc.) are not set to the corresponding integer values. So try

if (!SD.begin(D13)) {

Can't compile.

Arduino IDE shows error:

error: 'D13' was not declared in this scope

   if (!SD.begin(D13)) {

Arduino IDE: 1.8.8 (Windows 10), Board: "ESP32 Dev Module, Enabled, Default, QIO, 80MHz, 4MB (32Mb), 921600, None"

Please help...

Your board is an ESP32 and not an ESP8266 and Espressif managed to change that behavior again. Sorry for that.

According to the SPI example for the ESP32:

  //initialise hspi with default pins
  //SCLK = 14, MISO = 12, MOSI = 13, SS = 15

The print on the back of your board says something different. I guess it’s time to use your multimeter and check the connections. Check every signal to which pin it is connected.

pylon:
Your board is an ESP32 and not an ESP8266 and Espressif managed to change that behavior again. Sorry for that.

According to the SPI example for the ESP32:

  //initialise hspi with default pins

//SCLK = 14, MISO = 12, MOSI = 13, SS = 15




The print on the back of your board says something different. I guess it's time to use your multimeter and check the connections. Check every signal to which pin it is connected.

Already tried with multimeter but can’t find CS connection on any pin.

Then I did CS loop to all pins:

#include <SPI.h>
#include <SD.h>

void setup() {
  Serial.begin(115200);
  Serial.println("Initializing SD card...");
  
  for (int i=0; i < 6; i++){
      if (!SD.begin(i)) {
          Serial.print("PIN: ");
          Serial.print(i);
          Serial.println("  = FAILED!");
      } else {
          Serial.print("PIN: ");
          Serial.print(i);
          Serial.println("  = DONE............");
      }
      delay(5000);
  }

  for (int i=12; i < 40; i++){
      if (!SD.begin(i)) {
          Serial.print("PIN: ");
          Serial.print(i);
          Serial.println("  = FAILED!");
      } else {
          Serial.print("PIN: ");
          Serial.print(i);
          Serial.println("  = DONE............");
      }
      delay(5000);
  }
  
}

void loop() {
  // nothing happens after setup
}

But the result also no different, can’t find CS connection on any pin.

I guess to enable TTGO T8 SD card requires something special.

According to this page, TTGO T8 comes with its own micro-python firmware.

Maybe Arduino SD card library unable to enable the SD card but micro-python can do it.

Any other ideas?

Finally… it works… :slight_smile: :slight_smile: :slight_smile:

Change SD.h library with mySD.h library from GitHub - nhatuan84/esp32-micro-sdcard.

#include <SPI.h>
#include <mySD.h>

File root;
const int chipSelect = 13;

void setup()
{
  Serial.begin(115200);
  Serial.print("Initializing SD card...");
  pinMode(SS, OUTPUT);


  //SDClass::begin(uint8_t csPin, int8_t mosi, int8_t miso, int8_t sck) 
  if (!SD.begin(13, 15, 2, 14)) {
    Serial.println("initialization failed!");
    return;
  }
  
  Serial.println("initialization done.");

  root = SD.open("/");
  
  printDirectory(root, 0);
  
  Serial.println("done!");
}

void loop()
{
  // nothing happens after setup finishes.
}

void printDirectory(File dir, int numTabs) {
  // Begin at the start of the directory
  dir.rewindDirectory();
  
  while(true) {
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       //Serial.println("**nomorefiles**");
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print('\t');   // we'll have a nice indentation
     }
     // Print the 8.3 name
     Serial.print(entry.name());
     // Recurse for directories, otherwise print the file size
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
     }
     entry.close();
   }
}

Conclusion, nothing wrong with SD Card GPIO print on the back of the board.

The root of this issue cause by SD.h library which unable to detect TTGO SD card because it used custom CS, MOSI, MISO, SCK sequence.

Thanks a lot PYLON for the help.

I have the same problem but the solution i found is more easy.
I use the sketch [SD_Test] from:
[Archivo][Ejemplos][SD(Esp32)] (Sorry but i am spanish)
I only change this:

Serial.begin(115200);
if (!SD.begin()) {
Serial.println("Card Mount Failed");
return;
}

for this:

Serial.begin(115200);
SPI.begin(14, 2, 15, 13);
if (!SD.begin(13)) {
Serial.println("Card Mount Failed");
return;
}

and it works for me.