3.5 TFT problems with SD card

I need to display photos from the sd card to TFT. I tried this code and having a problem with turn on (start) SD card. this is the message that appears
"Show RAW files on TFT with ID:0x9486
cannot start SD"

#include <SPI.h>            // f.k. for Arduino-1.5.2
#include <SD.h>             // Use the official SD library on hardware pins

#include <Adafruit_GFX.h>   // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#define SD_CS 10

void setup()
{
    uint16_t ID;
    Serial.begin(9600);
    Serial.print("Show RAW files on TFT with ID:0x");
    ID = tft.readID();
    Serial.println(ID, HEX);
    tft.begin(ID);
    bool good = SD.begin(SD_CS);
    if (!good) {
        Serial.print(F("cannot start SD"));
        while (1);
    }
}

void loop()
{
    tft.setRotation(2);
    showRAW(0, 0, "001.raw", 320, 480);
    tft.setRotation(0);
    showRAW(0, 0, "002.raw", 320, 480);
    tft.setRotation(1);
    showRAW(0, 0, "003.raw", 480, 320);
}


const int RAWPIXELS = 256;

uint8_t showRAW(int x, int y, const char *nm, int w, int h)
{
    uint8_t first = 1;
    int32_t n = (int32_t)w * h;  //size of RAW image in pixels
    uint8_t buf[RAWPIXELS * 2];      // size in bytes
    File inFile = SD.open(nm);
    if (!inFile) return 1;    //can't open
    tft.setAddrWindow(x, y, x + w - 1, y + h - 1);
    while (n > 0) {
        int cnt = RAWPIXELS;
        if (n < cnt) cnt = n;
        n -= cnt;
        inFile.read(buf, cnt * 2);
        tft.pushColors(buf, cnt, first);
        first = 0;
    }
    inFile.close();
    return 0;
}

The microSD on the Uno shield uses digital #10 - #13 for the SPI signals.

This is correct for Uno or Nucleo.

A Mega2560, Due, Zero, ... have hardware SPI bus on the 3x2 header and not on 10-13.

David.

Mr. David, I use Arduino UNO board. so I don't know where the problem.

Well, you have to plug the Uno shield into the Uno header sockets.
Then use a formatted microSD card. Plug it into the microSD holder.

I suggest that you always try the library examples first.
Please report any problems.

Note that current Mcufriend 3.5 inch shields are BADLY designed. There is no 3.3V regulator on the shield.

David.

what is the preferred format of microSD?
which example would I use to test the shield with microSD?

the shield works fine and prints word in the TFT screen with this code

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // LCD library
#include <TouchScreen.h> // Touchscreen Library
#include <MCUFRIEND_kbv.h> // Touchscreen Hardware-specific library
 
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
 
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
 
// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF
 
// Color definitions
#define ILI9341_BLACK       0x0000      /*   0,   0,   0 */
#define ILI9341_NAVY        0x000F      /*   0,   0, 128 */
#define ILI9341_DARKGREEN   0x03E0      /*   0, 128,   0 */
#define ILI9341_DARKCYAN    0x03EF      /*   0, 128, 128 */
#define ILI9341_MAROON      0x7800      /* 128,   0,   0 */
#define ILI9341_PURPLE      0x780F      /* 128,   0, 128 */
#define ILI9341_OLIVE       0x7BE0      /* 128, 128,   0 */
#define ILI9341_LIGHTGREY   0xC618      /* 192, 192, 192 */
#define ILI9341_DARKGREY    0x7BEF      /* 128, 128, 128 */
#define ILI9341_BLUE        0x001F      /*   0,   0, 255 */
#define ILI9341_GREEN       0x07E0      /*   0, 255,   0 */
#define ILI9341_CYAN        0x07FF      /*   0, 255, 255 */
#define ILI9341_RED         0xF800      /* 255,   0,   0 */
#define ILI9341_MAGENTA     0xF81F      /* 255,   0, 255 */
#define ILI9341_YELLOW      0xFFE0      /* 255, 255,   0 */
#define ILI9341_WHITE       0xFFFF      /* 255, 255, 255 */
#define ILI9341_ORANGE      0xFD20      /* 255, 165,   0 */
#define ILI9341_GREENYELLOW 0xAFE5      /* 173, 255,  47 */
#define ILI9341_PINK        0xF81F
 
/******************* UI details */
#define BUTTON_X 52
#define BUTTON_Y 150
#define BUTTON_W 80
#define BUTTON_H 45
#define BUTTON_SPACING_X 26
#define BUTTON_SPACING_Y 30
#define BUTTON_TEXTSIZE 3
 
// Define pins for resistive touchscreen
#define YP A2  // must be an analog pin, use "An" notation!
#define XM A3  // must be an analog pin, use "An" notation!
#define YM 8   // can be a digital pin
#define XP 9   // can be a digital pin
 
// Define touchscreen pressure points
#define MINPRESSURE 10
#define MAXPRESSURE 1000
 
// Define touchscreen parameters
// Use test sketch to refine if necessary
#define TS_MINX 130
#define TS_MAXX 905
 
#define TS_MINY 75
#define TS_MAXY 930
 
#define STATUS_X 10
#define STATUS_Y 65
 
//Define LED outputs
#define RED_LED 51
#define GRN_LED 49
#define BLU_LED 47
 
// Define button state variables
boolean RED_state = 0;
boolean GRN_state = 0;
boolean BLU_state = 0;
 
// Define button array object
Adafruit_GFX_Button buttons[3];
 
// Define arrays with button text and colors
char buttonlabels[3][5] = {"R"};
uint16_t buttoncolors[6] = {ILI9341_RED, ILI9341_GREEN, ILI9341_BLUE};
 
// Define object for TFT (LCD)display
MCUFRIEND_kbv tft;
 
// Define object for touchscreen
// Last parameter is X-Y resistance, measure or use 300 if unsure
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
 
void setup(void) {
 
  Serial.begin(9600);
  Serial.println(F("TFT LCD test"));
 
  pinMode(RED_LED, OUTPUT);
  pinMode(GRN_LED, OUTPUT);
  pinMode(BLU_LED, OUTPUT);
 
 
  tft.reset();
 
  uint16_t identifier = tft.readID();
  if (identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if (identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if (identifier == 0x4535) {
    Serial.println(F("Found LGDP4535 LCD driver"));
  } else if (identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if (identifier == 0x9341) {
    Serial.println(F("*Found ILI9341 LCD driver"));
  } else if (identifier == 0x7783) {
    Serial.println(F("Found ST7781 LCD driver"));
  } else if (identifier == 0x8230) {
    Serial.println(F("Found UC8230 LCD driver"));
  }
  else if (identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else if (identifier == 0x0101)
  {
    identifier = 0x9341;
    Serial.println(F("Found 0x9341 LCD driver"));
  } else if (identifier == 0x9481)
  {
    Serial.println(F("Found 0x9481 LCD driver"));
  }
  else if (identifier == 0x9486)
  {
    Serial.println(F("Found 0x9486 LCD driver"));
  }
  else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    identifier = 0x9486;
  }
 
  // Setup the Display
  tft.begin(identifier);
  Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
  tft.setRotation(0);
  tft.fillScreen(BLACK);

}
 
void loop(void) {
 
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);
 
  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
 tft.setCursor(30,100);
 tft.setTextColor(0x07E0,0x0000);
 tft.setTextSize(3);
 tft.println(" hello"); 
  tft.setCursor(10,150);
 tft.setTextColor(0xFFE0,0x0000);
 tft.setTextSize(3);
 tft.println(" hi "); 
  tft.setCursor(10,200);
 tft.setTextColor(0x780F,0x0000);
 tft.setTextSize(3);
 tft.println(" welcome"); 
  tft.setCursor(10,250);
 tft.setTextColor(0xF800,0x0000);
 tft.setTextSize(3);
 tft.println(" good"); 
  tft.setCursor(30,300);
 tft.setTextColor(0xFD20,0x0000);
 tft.setTextSize(3);
 tft.println(" wow ");  
 
      delay(100); // UI debouncing
    
 
}

.

so the problem is the SDcard not detected by the Arduino.

by the way, I use this circuit :
https://ram-e-shop.com/?s=lcd&product_cat=0&post_type=product

and if there is any way to display an image on TFT without using a microSD card?

Please follow my advice. i.e. run all the library examples.

Make notes on paper.
e.g. things that you do not understand
e.g. example that does not work.
e.g. example that you would like to modify.

Then ask questions on the Public Forum i.e. here.
Quote example by name.

A regular Mcufriend Uno shield plugs into the Uno. Each male pin mates with a female socket as Nature intended.

If you are unsure, post a photo of your mated Shield.

David.