TTGO-T-display + SD card

dmitry.tereschenko
Posts: 3
Joined: Sun Feb 16, 2020 6:51 pm

Re: TTGO-T-display + SD card

Postby dmitry.tereschenko » Wed Feb 19, 2020 6:33 pm

Thanx, a lot :) It would be great :)
It's a part of a program too, I just dont understand how it should be. Here is the code (part)
I think that the problem is in SD.begin()

after uploading code, the screen doesn't work and I get Card Mount Failed in Monitor

Code: Select all


#include <TFT_eSPI.h>

#include "FS.h"
#include "SD.h"

#include <SPI.h>
#include <Wire.h>

#define HSPI_MISO   26
#define HSPI_MOSI   15
#define HSPI_SCLK   13
#define HSPI_SS     2
#define SDSPEED 27000000

SPIClass * hspi = NULL;

void setup() {
Serial.begin(115200);
hspi = new SPIClass(HSPI);
hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS);
pinMode(HSPI_SS, OUTPUT);

//
if(!SD.begin())  //SD.begin(HSPI_SCLK, *hspi, SDSPEED)
    {      Serial.println("Card Mount Failed");
           return;   }
     else Serial.println("SD ok");
}


froussel
Posts: 21
Joined: Fri Jul 13, 2018 7:13 am

Re: TTGO-T-display + SD card

Postby froussel » Wed Feb 19, 2020 8:25 pm

I commented on the parts I used.
It's a bit far in my memory and I don't have too much time to dive back into it
You should be able to do it otherwise I would watch more

Code: Select all


#include <TFT_eSPI.h>
#include "FS.h"
#include "SD.h"
#include <SPI.h>
#include <Wire.h>

/*
 SPIClass spiSD(HSPI);

#define SCK 13
#define MISO 17
#define MOSI 15
#define SS 2
 */
 
#define HSPI_MISO   26
#define HSPI_MOSI   15
#define HSPI_SCLK   13
#define HSPI_SS     2
#define SDSPEED 27000000

SPIClass * hspi = NULL;

void setup() {
Serial.begin(115200);
hspi = new SPIClass(HSPI);
hspi->begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, HSPI_SS);
pinMode(HSPI_SS, OUTPUT);

/*
   spiSD.begin(SCK,MISO,MOSI,SS);                         
   if(!SD.begin( 2, spiSD, SDSPEED))
    {      Serial.println("Card Mount Failed");
           return;   }
     else Serial.println("SD ok");        
 */
//
if(!SD.begin())  //SD.begin(HSPI_SCLK, *hspi, SDSPEED)
    {      Serial.println("Card Mount Failed");
           return;   }
     else Serial.println("SD ok");
}
If you have a code that works, place it below so others can take advantage of it

dmitry.tereschenko
Posts: 3
Joined: Sun Feb 16, 2020 6:51 pm

Re: TTGO-T-display + SD card

Postby dmitry.tereschenko » Mon Feb 24, 2020 3:01 pm

Finally, I've made it :)
After a lot of search on the internet I've found this site:
http://www.iotsharing.com/2017/05/how-t ... dcard.html

and this library
https://github.com/nhatuan84/esp32-micro-sdcard

The main part is that my SD card board use 5v

And it works :)
Code is from example

Code: Select all


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

#define HSPI_MISO   26
#define HSPI_MOSI   27
#define HSPI_SCLK   25
#define HSPI_CS     32

Sd2Card card;

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
pinMode(HSPI_CS, OUTPUT); //HSPI SS

while (!card.init(SPI_HALF_SPEED, HSPI_CS, HSPI_MOSI, HSPI_MISO, HSPI_SCLK)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }
}

void loop() {
  // put your main code here, to run repeatedly:
}
P.S. I still don't understand why SD library doesn't work

Who is online

Users browsing this forum: No registered users and 1 guest