Sd card Initializing fail

I am trying to display an image from sd on a 1.8 tft all the sd pins seem to be connected. I get this message on serial monitor "Initializing SD card...failed" when I run this code

/*

 Arduino TFT Bitmap Logo example

 This example reads an image file from a micro-SD card
 and draws it on the screen, at random locations.

 In this sketch, the Arduino logo is read from a micro-SD card.
 There is a .bmp file included with this sketch.
 - open the sketch folder (Ctrl-K or Cmd-K)
 - copy the "arduino.bmp" file to a micro-SD
 - put the SD into the SD slot of the Arduino TFT module.

 This example code is in the public domain.

 Created 19 April 2013 by Enrico Gueli

 http://www.arduino.cc/en/Tutorial/TFTBitmapLogo

 */

// include the necessary libraries
#include <SPI.h>
#include <SD.h>
#include <TFT.h>  // Arduino LCD library

// pin definition for the Uno
#define sd_cs  4
#define lcd_cs 10
#define dc     9
#define rst    8

// pin definition for the Leonardo
//#define sd_cs  8
//#define lcd_cs 7
//#define dc     0
//#define rst    1

TFT TFTscreen = TFT(lcd_cs, dc, rst);

// this variable represents the image to be drawn on screen
PImage logo;


void setup() {
  // initialize the GLCD and show a message
  // asking the user to open the serial line
  TFTscreen.begin();
  TFTscreen.background(255, 255, 255);

  TFTscreen.stroke(0, 0, 255);
  TFTscreen.println();
  TFTscreen.println(F("Arduino TFT Bitmap Example"));
  TFTscreen.stroke(0, 0, 0);
  TFTscreen.println(F("Open serial monitor"));
  TFTscreen.println(F("to run the sketch"));

  // initialize the serial port: it will be used to
  // print some diagnostic info
  Serial.begin(9600);
  while (!Serial) {
    // wait for serial port to connect. Needed for native USB port only
  }

  // clear the GLCD screen before starting
  TFTscreen.background(255, 255, 255);

  // try to access the SD card. If that fails (e.g.
  // no card present), the setup process will stop.
  Serial.print(F("Initializing SD card..."));
  if (!SD.begin(sd_cs)) {
    Serial.println(F("failed!"));
    return;
  }
  Serial.println(F("OK!"));

  // initialize and clear the GLCD screen
  TFTscreen.begin();
  TFTscreen.background(255, 255, 255);

  // now that the SD card can be access, try to load the
  // image file.
  logo = TFTscreen.loadImage("arduino.bmp");
  if (!logo.isValid()) {
    Serial.println(F("error while loading arduino.bmp"));
  }
}

void loop() {
  // don't do anything if the image wasn't loaded correctly.
  if (logo.isValid() == false) {
    return;
  }

  Serial.println(F("drawing image"));

  // get a random location where to draw the image.
  // To avoid the image to be draw outside the screen,
  // take into account the image size.
  int x = random(TFTscreen.width() - logo.width());
  int y = random(TFTscreen.height() - logo.height());

  // draw the image to the screen
  TFTscreen.image(logo, x, y);

  // wait a little bit before drawing again
  delay(1500);
}

I dont know if something is wrong with the sd or it is something else

I am using a Kingston 512mb sd card

What happens when you try an example from the SD library by itself. Isolate the SD card.

it shows this message in serial monitor " Initializing SD card...initialization failed. Things to check:

  • is a card inserted?

  • is your wiring correct?

  • did you change the chipSelect pin to match your shield or module?"

My crystal ball is having a hard time resolving "it".

Can you answer these three questions?

@beesarecute are we to assume that you are using an Arduino UNO?

Are the TFT screen and SD combined onto a shield, or are they separate boards?

If separate boards, which SD module are you using?

Have you been able to get the SD card working at all?

For each new device I find/write and example "device prove out code" for the SD this was my code (see below).

Also..

For the Arduino library we'll be discussing, and nearly every other SD library, the card must be formatted FAT16 or FAT32. Some only allow one or the other.

I formatted my card using: SD Card assoc formatter.

Code:

/*
  SD card read/write
  Mod 01 make file name a string and iterate until we find a unused file name.
  Mod 02 add capability to increment filename.
  Rev 03 tested successfully on Arduino M0

  SD card attached to SPI bus on ICSP Header.
  SD Board power = 5V (for large board with EEPROM)

  based on code created: Nov 2010 by David A. Mellis, 9 Apr 2012 by Tom Igoe
  This code is in the public domain.

driver has a 512 byte buffer then write to SD

Closing the file forces any buffered data to be written to the SD and also updates
the file's directory entry.

If you don't close the file, you will lose all data written the file since it was opened,
not just the last buffer, since the directory entry will not be updated.
*/

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

// *** SD Card declarations **************************************************
// ***************************************************************************

#define SDCARD_CS_PIN 9

uint16_t fileNumb = 900;
char dataFile[8];
bool SD_Error = false;

File myFile;			// create instance of a "File" class

void setup() {
  SerialUSB.begin(115200);
  delay (2000);
// Initializing SD card....

  SPISettings mySetting(1000000,MSBFIRST, SPI_MODE0);
  if (!SD.begin(SDCARD_CS_PIN))
    {SerialUSB.print("initialization failed");
     SD_Error = true;
    }

// loop until we find a file that doesn't already exist.......
  do
    {
     itoa(fileNumb, dataFile, 10);  // (value, Array, base)
     const char *extension = ".csv";
     strcat(dataFile, extension);  // syntax  strcat(dest, source)
     ++fileNumb;
    } while (SD.exists(dataFile));


SerialUSB.print("READY TO OPEN FILE FOR WRITING   = ");
SerialUSB.println(dataFile);
  myFile = SD.open(dataFile, FILE_WRITE);   // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
SerialUSB.println(myFile);
  // if the file opened okay, write to it:
  if (myFile) {
    myFile.println("data from boiler");     // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    SerialUSB.println("data from boiler");
    //SerialUSB.print(" data written to file:   ");
    myFile.close();                         // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 SerialUSB.println(dataFile);
    }
  else {
    // if the file didn't open, print an error:
    SD_Error = true;
    }
  SerialUSB.print("SD_Error = ");
  SerialUSB.print(SD_Error);
}
void loop() {
  // nothing happens after setup
}

I run a slightly modified version of your code and the serial monitor tells me this " ha$?tinitialization failedREADY TO OPEN FILE FOR WRITING = 900.csv
0
SD_Error = 1"
I am unsure what the error means

it means the initialization failed.

I could have terminated the program after:

  SPISettings mySetting(1000000,MSBFIRST, SPI_MODE0);
  if (!SD.begin(SDCARD_CS_PIN))
    {SerialUSB.print("initialization failed");
     SD_Error = true;
    }

But I let it continue. For no particular reason.

What board are you using? What pins do you have connected? It the TFT display connected? (should not be).

I am using an arduino uno with the sd slot on the back of the tft
sd_cs 4
sd_mosi 11
sd_miso 12
sd_sck 13

I would consider reformatting the SD card. My original experience was with a card formatted using the SD association formatter (see post six). I don't know if formatting differently could cause your issue or not. At the moment I don't have hardware to test this. I do remember reading one post that suggested I should not format with a PC.

UPDATE: The SD association formatter runs from a PC but formats per the SD assoc spec. Formats differently than the OS format function.