Loading images from SD Card

Hi,
I got a problem in loading image from SD card.
The message showed up while compiling.

Initialising SD card...
Card failed, or not present
Retrying....

But everything works fine in Mega2560 with the same TFT LCD and shield module.
http://www.elecfreaks.com/store/32-tft-lcd-screen-module-tft0132-p-113.html
http://www.elecfreaks.com/store/lcd-tft01-mega-shield-v10-p-214.html

The library I used is UTFT_SdRaw.
And the sketch is modified from the SdRaw_320x240 examples.
Because the limitation of speed in changing frames, I hope to make it work on Due.

#include <SPI.h>
// SdFat lib from here :-
// https://github.com/greiman/SdFat/archive/master.zip
#include <SdFat.h>
//#include <SdStream.h>
#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_Buttons.h>
#include <UTFT_SdRaw.h>
extern uint8_t SmallFont[];
extern uint8_t BigFont[];

#define SD_CHIP_SELECT  53  // SD chip select pin
// file system object
SdFat sd;
// print stream
ArduinoOutStream cout(Serial);

int wait = 2, pressed_button;

// Initialize display
// ------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield            : <display model>,19,18,17,16
// Standard Arduino Mega/Due shield            : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Due       : <display model>,25,26,27,28
// Teensy 3.x TFT Test Board                   : <display model>,23,22, 3, 4
// ElecHouse TFT LCD/SD Shield for Arduino Due : <display model>,22,23,31,33
//
// Remember to change the model parameter to suit your display module!

UTFT myGLCD(SSD1289, 38, 39, 40, 41);




// Initialize touchscreen
// ----------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield            : 15,10,14, 9, 8
// Standard Arduino Mega/Due shield            :  6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due       :  6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due (JP10):  6, 5,32, 3, 2
// Teensy 3.x TFT Test Board                   : 26,31,27,28,29
// ElecHouse TFT LCD/SD Shield for Arduino Due : 25,26,27,29,30
//
//UTouch  myTouch( 6, 5, 32, 3, 2);
UTouch  myTouch( 6, 5, 4, 3, 2);

UTFT_SdRaw myFiles(&myGLCD);
UTFT_Buttons  myButtons(&myGLCD, &myTouch);

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.println(F("Initialising SD card..."));
  bool mysd = 0;
  // see if the card is present and can be initialized:
  while (!mysd)
  {
    if (!sd.begin(SD_CHIP_SELECT, SPI_SIXTEENTH_SPEED)) {//SPI_FULL_SPEED
      Serial.println(F("Card failed, or not present"));
      Serial.println(F("Retrying...."));
    }
    else
    {
      mysd = 1;
      Serial.println(F("Card initialised."));
    }
  }
  Serial.println(F("Initialising LCD."));
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(SmallFont);
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);
  myButtons.setTextFont(BigFont);
  int butskip = myButtons.addButton( 85,  219 , 70,  20, "Skip");
  Serial.println(F("LCD initialised."));
  // ////////////////////////////////////////////////////////////////////////////////
  //             Wait for GPS screen  or skip button
  ///////////////////////////////////////////////////////////////////////////////////
  Serial.println(F("Initialising LCD."));
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(SmallFont);
  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_MEDIUM);
  myButtons.setTextFont(BigFont);
  //int butskip = myButtons.addButton( 130,  100 , 70,  20, "Show");
  Serial.println(F("LCD initialised."));

}

void loop()
{
    char fname240[] = "SK45/fish.RAW";
    myGLCD.clrScr();
    myFiles.load(0, 0, 320, 240, fname240, 1);
    delay(5000);
    char fname320[] = "SK45/scene.RAW";
    myFiles.load(0, 0, 320, 240, fname320, 1);
    delay(5000);
}

Any command is appreciated.

Gary

UTFT_SdRaw works great on DUE, you are aware you cannot use the same shield from the Mega on the DUE?

Regards,

Graham

Well...actually I didn't know that.
Because I used the same TFT LCD and shield for couple examples in UTFT library, and everything looks fine until this try.
Anyway, could you kindly please show me how to make it work in your library with DUE?
Is hardware wiring or software modifying necessary?
Thanks for the help.

Gary

I have tried to connect my TFT-LCD to DUE directly according to the following website.
http://www.dimdim.gr/2013/01/3-2-tft-pinout-connection-to-arduino-mega-or-due/
But it still show error in initializing SD card....
Any suggestion?

Gary

Hello Gary_chien,

Unless you are in a hurry, I'd recommend you to implement your project one step at a time.
It is very hard to know what is going on when you put several entities together with which you are not too familiar. For example, and as you mentioned, begin trying to read the SD card. As ghlawrence2000 said, even though the foot prints of Mega and Due looks similar, they are different. The SPI pins of Due are located in the 2x3 connector (most of the AVR board’s pins for MOSI, MISO and SCK correspond to 11, 12 and 13 respectively). Use a simple demo SD card code to read the card. Then, you can move with the next task like the LCD, touch section, etc... Regards

-p

That really help me from the hints.
After rewiring SPI of SD card as following website, Sdraw demo works fine on DUE.

The SPI are different in MEGA and DUE, even if their pins looks like the same.
So wiring without the shield is necessary.
That's what I have learned from ghlawrence2000 and Palliser.
Thank you guys for those helpful suggestions!!

Gary