Go Down

Topic: 3.2" TFT LCD Shield + Display w SD Socket for Arduino Mega 2560, SD Problem (Read 15087 times) previous topic - next topic


Yes, but even when i put
Code: [Select]
pinMode(53, OUTPUT);
  if (!SD.begin(53)) {
    Serial.println("initialization failed!");
  Serial.println("initialization done.");

It's not working, but i realized something in the library says
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4

But in my case the pins are:


Do i have the change this? How do i change this?



The code you posted the first time did you alter that or is that the actual code that was given to you?
My GitHub:


here try this.
Code: [Select]
  SD card test
This example shows how use the utility libraries on which the'
SD library is based in order to get info about your SD card.
Very useful for testing a card when you're not sure whether its working or not.

The circuit:
  * SD card attached to SPI bus as follows:
** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
** CS - depends on your SD card shield or module.
Pin 4 used here for consistency with other Arduino examples

created  28 Mar 2011
by Limor Fried
modified 16 Mar 2011
by Tom Igoe
// include the SD library:
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 4; // if 4 dont work try 10, else try 8, NOT 53   

void setup()
  Serial.print("\nInitializing 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(53, OUTPUT);     // change this to 53 on a mega

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    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?");
  } else {
   Serial.println("Wiring is correct and a card is present.");

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
    case SD_CARD_TYPE_SD2:

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize *= 512;                            // SD card blocks are always 512 bytes
  Serial.print("Volume size (bytes): ");
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);

void loop(void) {
My GitHub:


That the code given to me, i tried all the pins, 4 , 10 and 8, even 53 but none worked, i still thinking that maybe there is something to do in the MOSI, CLK and MIMO pins.



My GitHub:


Last thing, did the code you get come in a folder with other files in it? Im looking for something .h and .CPP.
if it did not then I can no longer help you, I have done everything I can think of.
My GitHub:


ok, thanks for this, i'm using the arduino SD example: WriteRead, i'm Attaching all the library whithin the examples in it.

Thanks a lot.


The problem more than likely is that it is a 1.0 sainsmart variant ~ equivalent  shield. The wiring to the cs meso and mosi pins is wrong on the shield. The good news is that if you can solder it is fixable by removing 4 resistors and "flying" four wires on the shield to make the correct connections. instructions that are pretty good are here, http://www.sainsmart.com/vanilla/discussion/41/fixed-v1-0-version-of-sainsmart-tft-lcd-adjustable-shield-for-arduino-mega-2560/p1.
Then set the cs pin to 53. and it will work with the sd library just fine. the other pins are called by spi internally and are always the same depending on which duino you have.

Go Up