Elechouse TFT Display: SD card reading doesn't work (Arduino Due)

Hello, I am new to the forum so please bear with me.
I am using Arduino Due.

I am using UTFT_SdRaw_800x480_Demo with my elechouse 7" display with controller SSD1963. I am trying to read the card data but I keep getting this...

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

As it can be seen i am having a problem with initialising the sd card. I have tried using different chip select 4,10,52 and 53 but I am having no luck.

// UTFT_SdRaw_800x480_Demo
// Copyright (C)2015 Graham Lawrence (GHLawrence2000). All Rights reserved.
// web: https://github.com/ghlawrence2000/UTFT_SdRaw
//
// This program is a demo of how to use the functions provided by UTFT_SdRaw.
//
// This program requires the UTFT, UTouch, UTFT_Buttons and SdFat libraries.
//
#include <SPI.h>
// SdFat lib from here :-
// https://github.com/greiman/SdFat/archive/master.zip
#include <SdFat.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(EHOUSE70, 22,23,31,33);
//UTFT myGLCD(CTE50, 25, 26, 27, 28);
//UTFT myGLCD(CTE70, 25, 26, 27, 28);


// 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( 25, 26, 27, 29, 30);
//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 DUE & 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_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 GPS."));
  long mytime = millis();
  myFiles.load(0, 0, 240, 240, "wait4gps.RAW", 1 , 1);
  long mytime1 = millis() - mytime;
  cout << F("Time to draw 240x240 raw ") << mytime1 << F(" ms") << endl;
  myButtons.drawButton(butskip);
  while (wait == 2) {
    pressed_button = myButtons.checkButtons();
    if (pressed_button == butskip)
    {
      cout << F("Skip button detected (No GPS :( )\n");
      wait = true;
    }
  }
  char fname440[] = "SO11/SO100100.RAW";
  myGLCD.clrScr();
  mytime = millis();
  myFiles.load(20, 20, 440, 440, fname440, 1);
  mytime1 = millis() - mytime;
  cout << F("Time to draw 440x440 raw (no extra buffer) (non inverted colour) ") << mytime1 << F(" ms") << endl;
  delay(5000);
  myGLCD.clrScr();
  mytime = millis();
  myFiles.load(20, 20, 440, 440, fname440, 32, 0);
  mytime1 = millis() - mytime;
  cout << F("Time to draw 440x440 raw (32*buffer) (non inverted colour) ") << mytime1 << F(" ms") << endl;
  delay(5000);
  mytime = millis();
  myFiles.load(20, 20, 440, 440, fname440, 32, 1);
  mytime1 = millis() - mytime;
  cout << F("Time to draw 440x440 raw (32*buffer) (inverted colour) ") << mytime1 << F(" ms") << endl;
  delay(5000);
  myGLCD.clrScr();
  mytime = millis();
  myFiles.pan(20, 20, 440, 440, 0, 0, 4040, 4040, "SK45/SK45.RAW", 1);
  mytime1 = millis() - mytime;
  cout << F("Time to draw 440x440 portion from 4040x4040 raw image (inverted colour) ") << mytime1 << F(" ms") << endl;
  delay(5000);
  myGLCD.clrScr();
  int xad, yad;
  int xd = 0, yd = 0;
  int tmpx = 0, tmpy = 0;
  mytime = millis();
  for (int z = 0; z < 209; z++)
  {
    tmpy = (z / 19);
    tmpx = z - (tmpy * 19);
    xd = tmpx * 42;
    yd = tmpy * 42;
    tmpy = (z / 22);
    tmpx = z - (tmpy * 22);
    yad = (tmpy * 69) + 10;
    xad = (tmpx * 108) + 44;
    myFiles.pan(xd, yd, 42, 42, xad, yad, 2374, 696, "icons.raw");
  }
  mytime1 = millis();
  cout << F("time to draw 210 42x42 icons (ms) ") << (mytime1 - mytime) << endl;
  delay(5000);
  cout << F("Thanks for watching!") << endl;
  myGLCD.clrScr();
  myGLCD.setFont(BigFont);
  myGLCD.setColor(VGA_GREEN);
  myGLCD.print("Thanks for watching!", CENTER, 231);
}

void loop()
{
}

ANYONE??? PLEASE???

On due you can use any cs
I use SdFat.h
with
// cs for the sd card reader (
the other pins to miso, mosi and clk of spi bus)
const uint8_t SD_CS = 11;

But i had to remove the three cms resistors (bypass with solder) on the lcd board from the sd lines.

Not sure if it is the reason because i made so many try before succeed.

Good luck

.... and try SPI_HALF_SPEED

Hi @karawin, Thank you for responding. I am using 42 as my cs now because the screen data sheet says that sd_cs is 42, i also tried Half speed but the error was still there, I want make sure I have exhausted all my options before I play with the hardware on the lcd screen(cms restistors).

Here is what my code looks like now

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

const uint8_t chipSelect = 42;
// file system object
SdFat sd;
// print stream
ArduinoOutStream cout(Serial);

int wait = 2;

// 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(EHOUSE70, 22,23,31,33);
//UTFT myGLCD(CTE50, 25, 26, 27, 28);
//UTFT myGLCD(CTE70, 25, 26, 27, 28);


// 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( 25, 26, 27, 29, 30);
//UTouch  myTouch( 6, 5, 4, 3, 2);

UTFT_SdRaw myFiles(&myGLCD);
UTFT_Buttons  myButtons(&myGLCD, &myTouch);
int butskip;
int x;
int y;
void setup()
{ int pressed_button;
// pinMode(42, OUTPUT);
// digitalWrite(42, HIGH); 
 // Open serial communications and wait for port to open:
 Serial.begin(115200);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for DUE & Leonardo only
 }
 Serial.println(F("Initialising SD card..."));
 bool mysd = 0;
 // see if the card is present and can be initialized:
 while (!mysd)
 {
  // pinMode(10, OUTPUT);
   //digitalWrite(10, HIGH);
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);
  pinMode(52, OUTPUT);
  digitalWrite(52, HIGH);
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH); 
 // pinMode(42, OUTPUT);
 // digitalWrite(42, HIGH);
   if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
   //  Serial.println(sd.begin(42,SPI_HALF_SPEED));
     Serial.println(chipSelect);
     Serial.println(F("Card failed, or not present"));
     Serial.println(F("Retrying...."));
     delay(10);
   }
   else
   {
     mysd = 1;
     Serial.println(F("Card initialised."));
   }
 }
}

Right. Its a wired shield. Not my case.

Hmmm... Do you think buying an external sd card reader might solve my problem? Do you knw how I can test to see if my SPI bus is working?

You should be able to run any <SD.h> or <SdFat.h> examples without the TFT, Touch or anything else.
All you need is the SD_CS = 42. I am assuming that you do not have a Font chip.

I would just start with Cardinfo.ino

There should be no wiring difficulties with the SD. The Due has 3.3V logic. Your Adapter routes to the Due SPI header.

Different flavours of SdFat.h may not like some SD formats.

David.

Hi @david_prentice, I tried using the cardinfo.ino, but I get this error now.

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?

I noticed that my hardware folder doesn't have /arm directory in it, I believe that arduino due needs the arm directory.

Please let me know if you have this directory under your hardware folder.

/home/hemil/arduino-1.6.7/hardware

I went and bought new sd card, still the same error, I tried to write high on pin42 using

pinMode(42,OUTPUT);
digitalWrite(42,HIGH);
val = digitalRead(42);

but the value still reads to be 0 at 42, do you think my due is bad?

With or without shield connected?

Have you uncommented this line in "libraries\UTFT\hardware\arm\HW_ARM_defines.h"?

// ElecHouse TFT LCD/SD Shield for Arduino Due
// -------------------------------------
// Uncomment the following line if you are using this shield
#define EHOUSE_DUE_SHIELD 1
//
// For this shield: RS=22, WR=23, CS=31, RST=33
//****************************

@Karawin, with the shield connect
@c0rsalr, yes I did uncomment the line.

Thank you both.

The issue was that the MISO was some how shorted to the GND. I checked the MISO to GND using multimeter leads and ran a continuity test.
I went on and tried the same configurations with one of my friends due , uploaded the code and voila. It was working on my friends due but not mine. I ordered a new due and it should be arriving wednesday. This took me hours and hopefully this helps people in the future.

Regards
hp