SD Card Failure

I have a problem with accessing the SD card on this screen

I have it wired like this documentation suggests for uno.

Some definitions:

#define cs    10
#define dc    9
#define rst   8
#define sd_cs  4

The screen works fine, it's started, I can print whatever I like to it.

void setup() {

  TFTscreen.begin();
  TFTscreen.background(0, 0, 255);
  if (!SD.begin(sd_cs)) {
    buttonType = PrintText("SD Failure",buttonType,11,20,45,2,255,255,255);
    return;
  }  
  buttonType = PrintText("Success",buttonType,8,20,45,2,255,255,255);
}

However I get SD Failure printed to the screen, each and every time I run this.

Please note: Printext is a subroutine that sets the colour and executes TFTscree.text. This is old and proven to work, and "SD Failure" is displayed on teh screen every time.

The SD card is SanDisk 8GB

Any Ideas? Is there a limit to the SD card it can read? I bought the smallest I could find.

NB. I'm sure this is hardware related, as the TFTBitmapLogo example fails in the same manner.

Since my post got moved to this forum, I've read u on a lot of other people's problems.

  1. My wiring is as per the diagram posted. I am sure.
  2. I have downloaded the SD formatter V4.0 app and reformatted the card
  3. I have tried the Cardinfo example, and get the same result.

I'm at my wit's end. This is a brand new card, purchased specifically for the arduino.

I've downloaded and installed SdFat from github, and still get an error:

Can't access SD card. Do not reformat.
SD errorCode: 0X2,0X1F

I'm afraid I don't know what this means.

Is this the same lib as used here? http://arduino.cc/en/Tutorial/ReadWrite ?

 Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
   pinMode(10, OUTPUT);
   
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }

Then you need to define pin10 as an output..

I tried that. Looking at the wiring diagram, pin 10 is wired to LCD CS. As such, I'm sure it's already defined as an output anyhow. Does that wiring sound right though?

Yes I think so. Can you post the whole code?
By the way, I’m also Newbie. My Cardreader is working now. But I tried 4 SD-Cards, only 2 are working.
For these Problems I can recommend a Logicanalyzer to see what happens on the interface. It only costs around 10€ at ebay (8Channel 24Mhz Samplingrate) and is very helpful.

Sure.

It's here, TFTBitmapLogo

with explanations here

I'm running the sample code, as suggested by arduino here

No, the code you are uploading to the board. The file on your harddrive you are compiling.

What use is it to link to something that you are not compiling.

Peter, I AM compiling that code. I have abandoned my own code, until it starts to work.
I compile the following 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://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 line to be ready
  }

  // 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);
}

An exact copy of the example code, and I get an error. “Initializing SD card…failed!”
The code I originally posted was a cutdown version just to highlight the problem for me, and to remove all the serial debugging stuff.

FWIW, I went out and bought a 2GB MicroSD card, not MicroSDHC, and it made no difference.

If you really want my other code, it’s here.

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



#define cs    10
#define dc    9
#define rst   8
#define sd_cs  4

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

typedef enum {
  BTN_START,
  BTN_STOP , 
  BTN_CLEAN,
  BTN_UP   ,
  BTN_DOWN ,
  BTN_LEFT ,
  BTN_RIGHT,
  BTN_ENTER
} btnNames;

typedef struct {
  int analogVal;
} TBtnInfo;

TBtnInfo btnInfo[] = {
  [BTN_START] = {1020},
  [BTN_STOP ] = {127},
  [BTN_CLEAN] = {325},
  [BTN_UP   ] = {894},
  [BTN_DOWN ] = {698},
  [BTN_LEFT ] = {601},
  [BTN_RIGHT] = {512},
  [BTN_ENTER] = {417}
};

void dispCycleTime();
String PrintText(String text, String oldText, int chrLength, int x, int y, int fontSize, int r, int g, int b);

int state = 0;
unsigned long iCycleTime;
String sCycleTime;
String buttonType;
  
void setup() {

  // Put this line at the beginning of every sketch that uses the GLCD:
  
  
  TFTscreen.begin();
  TFTscreen.background(255, 0, 0);
  pinMode(10, OUTPUT);
  if (!SD.begin(sd_cs)) {
    buttonType = PrintText("SD Failure",buttonType,11,20,45,2,255,255,255);
    return;
  }  
  buttonType = PrintText("Success",buttonType,8,20,45,2,255,255,255);
}

void loop() {
  

  dispCycleTime();
}

String PrintText(String text, String oldText, int chrLength, int x, int y, int fontSize, int r, int g, int b)
{
  if (text != oldText)
  {
    TFTscreen.setTextSize(fontSize);
    char chr[chrLength];
    TFTscreen.stroke(0, 0, 0);
    oldText.toCharArray(chr, chrLength);
    TFTscreen.text(chr, x, y);
    TFTscreen.stroke(r, g, b);
    text.toCharArray(chr, chrLength);    
    TFTscreen.text(chr, x, y);
  }
  return text;
}

void dispCycleTime()
{
  if (cycleCount % 10000 == 0)
  {
    unsigned long now = micros();
    sCycleTime = PrintText(String((now - iCycleTime)/10000)+"us",sCycleTime,7,120,120,1,255,255,255);
    iCycleTime = now;
    
  }
}

Though as the example code is not working, I can’t see it being a software issue, which is why I said I’m sure it’s hardware related.
You’ll note in my original post I said I was also compiling TFTBitmapLogo

Ok that makes sense. But then I would check if and what the SD Card on MISO Port is answering and compare it with this site: How to Use MMC/SDC.
A working setup should look like this (see attachement) If you need more screenshots or Zooms let me know.

Hmm. Buy a CRO was not the answer I was hoping for, but I suppose at this point I have little hope. Thanks, I'll get back to you in a week, when I've been paid. Unfortunately this is not a job I can take to work and use their test gear.

Fixed.
CRO showed odd half level for a short period in CS
also lots of noise on MISO which I now understand is not used by the screen of course.

turns out there was a dry solder joint. I resoldered all suspect joints and voila! It now initialises.

Thanks to everybody for your help.

I found this very helpful. because while I don't have a 4 channel CRO (oscilloscope), I do have a loupe! Check the solder joints on the boards. I bought 5 Catalex boards and two had bad solder joints. The pins on the card reader had become bent before soldering causing the paste to not make good contact. Saved me hours of work! Another helpful hint, and most examples don't show this, make sure that if your data collection is transmitted to the SD card inside the loop() portion of the program, that your file is declared inside the header or global section of the program like this: File myfile; Then inside the setup() you can write something like: myfile = SD.open("datalog.txt", FILE_WRITE); without having scope problems. Note also, the word "File" is not all caps like many other C language program environs. Thanks again. Thought I was losing my mind :) Ah, there it is. :)