Pages: [1] 2   Go Down
Author Topic: 3.2" TFT LCD Shield + Display w SD Socket for Arduino Mega 2560, SD Problem  (Read 6563 times)
0 Members and 1 Guest are viewing this topic.
Brasil - Uberlândia
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I have a 3.2" TFT LCD Shield + Touch Panel Display w SD Socket for Arduino Mega 2560 A080, this one http://www.aliexpress.com/snapshot/203506212.html, and I believe that the documentation to this shield id this one: http://iteadstudio.com/store/images/produce/Shield/Shields/ITDB02ArduinoMEGAsheild2.0/ITDB02%20Arduino%20MEGA%20shield%202.0.pdf

The LCD is working fine with the examples, using the library made by Henning (http://henningkarlsen.com/electronics/library.php?id=51),  but I can't connect to the SD card, I’m trying to use the SD examples that come which the Arduino just to see if it works, and I’m changing the CS PIN to 53, but yet i get the message "initialization failed. Things to check:” ...

The code is below, I think is something really stupid, but I can’t figure it out.


Code:
/*
  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 9 Apr 2012
 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 = 53;   

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  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
 pinMode(4, OUTPUT);
 digitalWrite(4, HIGH);
 pinMode(42, OUTPUT);
digitalWrite(42, HIGH);
digitalWrite(53, LOW);




  // 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?");
    return;
  } 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:
      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");
  }

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


  // 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);
  Serial.println();
 
  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.println(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);

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


void loop(void) {
 
}
Thanks for your time and attention.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What pin is the microSD card slave select pin? I think I would put it on digital pin 49.

The Mega2560 SPI data lines are:
MISO -> pin 50
MOSI -> pin 51
SCK -> pin 52

Then I would try this in setup:
Code:
if(!SD.begin(49)) Serial.println("SD fail");
else Serial.println("SD ok");
Logged

Brasil - Uberlândia
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What pin is the microSD card slave select pin? I think I would put it on digital pin 49.

The Mega2560 SPI data lines are:
MISO -> pin 50
MOSI -> pin 51
SCK -> pin 52

Then I would try this in setup:
Code:
if(!SD.begin(49)) Serial.println("SD fail");
else Serial.println("SD ok");



You mean like this:
Code:
#include <SD.h>

File myFile;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.println("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);
   pinMode(53, OUTPUT);

   //digitalWrite(53, LOW);
   //digitalWrite(10, HIGH);

   
  if(!SD.begin(49)) Serial.println("SD fail");
else Serial.println("SD ok");
 
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);
 
  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
// close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
 
  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");
   
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
  // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }
}

void loop()
{
// nothing happens after setup
}

No the problem still persist...

Thanks
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No. I mean like this:
Code:
#include <SD.h>

void setup() {
  Serial.begin(9600);

  // I have a w5100 connected, so I disable it here.
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);

  Serial.print("Starting SD...");

  if(!SD.begin(49)) Serial.println("failed");
  else Serial.println("ok");
}

void loop() {
}
I bent D4 so it would not insert into the Arduino, then jumpered D4 to D49. I uploaded the code, powered down the Arduino for a few seconds, then ran that code.
Quote
Starting SD...ok
Logged

Brasil - Uberlândia
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, i did the same, not working yet.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using a Mega2560 with an ethernet shield to test. I bent D4 on the shield so the SD slave select would not connect there, then jumpered that to D49. That hardware setup works fine.

Are you certain the SPI lines are connected from the TFT to the Mega correctly? That would be the difference. I use the ICSP connector for the SPI data lines, not pins 50-52.
Logged

Brasil - Uberlândia
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using the shield, I tried the jump but it did not worked, I have an Ethernet shield as well and the SD card works, but I need to use the SD Card in the LCD, because I’m not using the Ethernet shield in this project. i think that maybe is something in the software that i must change, but i don't now what.

Thanks
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you certain the SPI data lines are connected correctly from the TFT to the Mega?
MISO -> 50
MOSI -> 51
SCK -> 52
Logged

Brasil - Uberlândia
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, i checked over here, the lines are correct.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 140
Posts: 5873
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I took a look at the hardware on the TFT, and I see no logic converters for the inputs to the SD like on the ethernet shield. Otherwise, I'm not sure what is happening.
Logged

Brasil - Uberlândia
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, but I dont think they would do the place to put de SD CARD and everthing else if not to let it working, thats why i think the change i need to do is on the Software... but i'm not sure.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 86
Posts: 3466
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

question, what is your chipselect at, 53 or 4.
Make it 4 and change pinMode(10, output) to 53 AND DONT MAKE IT LOW OR HIGH,
digitalWrite(53,LOW or HIGH) take this out of your code.

if all else fails, either update your software or downgrade it, it might just be a bug somewhere in the SD.h file.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Brasil - Uberlândia
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

question, what is your chipselect at, 53 or 4.
Make it 4 and change pinMode(10, output) to 53 AND DONT MAKE IT LOW OR HIGH,
digitalWrite(53,LOW or HIGH) take this out of your code.

if all else fails, either update your software or downgrade it, it might just be a bug somewhere in the SD.h file.

No i update to version 1.0.2, and the problem persists, i made the SD chip select 4, and yet nothing, what else can this be?

Thanks
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 86
Posts: 3466
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When you bought the TFT did it come with any websites you can go to, custom libraries, examples, anything at all?

You may need to contact the seller and ask if he/ she knows where to get the correct code that works for that shield.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Queens, New York
Offline Offline
Faraday Member
**
Karma: 86
Posts: 3466
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quick question, there should be a little switch on the I/O shield, is that set to 5V or 3.3V, because according to the hardware page you provided, it says to have it set to 5V to work for the ARD mega 2560.

also your CS should be set to 53, my mistake.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Pages: [1] 2   Go Up
Jump to: