LCd touch screen help

Hi all
My hardware is an Arduino mega, Itead tft lcd shield v1.1 and ITDb02-3.2 TFT screen. I am using a mac for the compiling etc
The sd card is supposed to be formatted in FAT16. to do this I have tried 2 methods. Fristly, opened disk utility, selected the device name, selected partition, created 1 partition and selected MS dos and selected apply.
After doing this I right clicked on the sd card and selected get info and it says in partition info it is "Fat16"
The second method was to drag out an ancient windows laptop and format it on that to FAT16. Both seemed to work okay.
I have dragged this old Arduino Mega out of storage to set up an arduino reef controller. It si not displaying correctly on my screen and I think it has something to do with the pin outs or similar. Or perhaps the chipset.

When I run this code

// UTFT_ViewFont (C)2012 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of the included fonts.
//
// This demo was made for modules with a screen resolution 
// of 320x240 pixels.
//
// This program requires the UTFT library.
//

// set up variables using the SD utility library functions:
#include <SD.h>
#include <tinyFAT.h>
#include <UTFT.h>
#include <UTouch.h>

Sd2Card card;
SdVolume volume;
SdFile root;

const int chipSelect = 53; 

int x, y;
int bg[] = {
  0, 0, 255};
int fg[] = {
  255, 255, 255};

// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];

// Uncomment the next line for Arduino 2009/Uno
//UTFT myGLCD(ITDB32S,19,18,17,16);   // Remember to change the model parameter to suit your display module!

// Uncomment the next line for Arduino Mega
UTFT     myGLCD(ITDB32S,38,39,40,41);   // Remember to change the model parameter to suit your display module!
UTouch   myTouch(6,5,4,3,2);

byte initres;
byte res;
byte input;

void setup()
{ 
START:
  // Initialize serial communication 
  Serial.begin(115200);
  Serial.println("press the ENTER button on your Touch Screen!");
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.setFont(SmallFont);
  myGLCD.print("Initializing SD card...", CENTER, 0);
  pinMode(chipSelect, OUTPUT);

  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    myGLCD.print("initialization failed. Things to check:", CENTER, 16);
    myGLCD.print("* is a card inserted?", CENTER, 32);
    myGLCD.print("* Is your wiring correct?", CENTER, 48);
    myGLCD.print("* Is your CS pin setting correct?", CENTER, 64);
    delay(5000);
    goto START;
  } 
  else {
    myGLCD.print("Wiring is correct and a card is present.", CENTER, 16); 


    String CT = "Card type: ";
    switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      CT = CT + " SD1";
      break;
    case SD_CARD_TYPE_SD2:
      CT = CT + " SD2";
      break;
    case SD_CARD_TYPE_SDHC:
      CT = CT + " SDHC";
      break;
    default:
      CT = CT + "Unknown";
    }
    myGLCD.print(CT, CENTER, 32); 

    // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
    if (!volume.init(card)) {
      myGLCD.print("Could not find FAT16/FAT32 partition.Make sure you've formatted the card", CENTER, 48);
      delay (5000);
      goto START;
    }
    else{
      // print the type and size of the first FAT-type volume
      myGLCD.print("Volume type is FAT "+(String)volume.fatType(), CENTER, 48);
      uint32_t volumesize;
      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
      myGLCD.print("Volume size (bytes): "+(String)volumesize, CENTER, 64);
      volumesize /= 1024;
      myGLCD.print("Volume size (Kbytes): "+(String)volumesize, CENTER, 80);
      volumesize /= 1024;
      myGLCD.print("Volume size (Mbytes): "+(String)volumesize, CENTER, 96);
      myGLCD.print("Files found on the card", CENTER, 112);
      myGLCD.print("Open the Serial Monitor", CENTER, 128); 
      myGLCD.print("and wait for instructions!", CENTER, 144);
      myGLCD.setFont(BigFont);
      myGLCD.setBackColor(bg[0], bg[1], bg[2]);

      initres=file.initFAT();
      if (initres!=NO_ERROR)
      {
        myGLCD.print("***** ERROR: ",CENTER,144);
        while (true) {
        };
      }
        drawButtons();  
    }
  }
}


void drawButtons()
{
  // Draw the ENTER buttons
  myGLCD.setColor(bg[0], bg[1], bg[2]);
  myGLCD.fillRoundRect (90, 180, 220, 230);
  myGLCD.setColor(fg[0], fg[1], fg[2]);
  myGLCD.drawRoundRect (90, 180, 220, 230);
  myGLCD.print("Enter", 115, 195);
  myGLCD.setBackColor (0, 0, 0);
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);  
}

// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
  myGLCD.setColor(255, 0, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  while (myTouch.dataAvailable()){
  }
  delay(20);

  root.openRoot(volume); 
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);  
  ListFiles();  
  myGLCD.setColor(fg[0], fg[1], fg[2]);
  myGLCD.drawRoundRect (x1, y1, x2, y2);  
}

void loop()
{
  if(Serial.available()){
    int ib = Serial.read();
    String is = (String)(char)ib;
    myGLCD.print("                  ",CENTER,160);
    myGLCD.print(is, CENTER,160);
  }
  if (myTouch.dataAvailable())
  {
    delay(10);
    int xt;
    int yt;
    myTouch.read();
    x=myTouch.getX();
    y=myTouch.getY();

    if (x>=90 && x<=220 && y >=180 && y<=230)  // Button: Enter
    {
      waitForIt(90, 180, 220, 230);      
    }
    else {
      if (y >= 5 && y <= 235 && x >= 5 && x <= 315){
        myGLCD.print("   ",260,160);
        int x1 = ((x-5)/72+1)*72-72+4;
        int x2 = x1 + 65;
        int y1 = ((y-5)/10+1)*10-10+5;
        int y2 = y1 + 10;
        myGLCD.print((String)((y-5)/10+1),260,160);
        myGLCD.print((String)((x-5)/72+1),280,160);
        myGLCD.setColor(255, 0, 0);
        myGLCD.drawRoundRect (x1, y1, x2, y2);        
        while(myTouch.dataAvailable()){    
        }
        delay(20);
        myGLCD.setColor(0, 255, 0);
        myGLCD.drawRoundRect (x1, y1, x2, y2);   
      }
    }
  }
}


void ListFiles(){
  int x = 5;
  int y = 5;
  String FN;
  String EX;
  myGLCD.clrScr();
  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.setFont(SmallFont);  

  res = file.findFirstFile(&file.DE);
  if (res==NO_ERROR)
  {
    EX = (String)file.DE.fileext;
    EX.trim();
    if(EX == "RAW"){
      myGLCD.print(file.DE.filename, x, y);
      myGLCD.drawRoundRect (x-1, y, x+64, y+10);
      y+=10;
    }
  }
  else
  {
    myGLCD.print("No files found...",CENTER,144);
  }
  while (res==NO_ERROR)
  {
    res = file.findNextFile(&file.DE);
    if (res==NO_ERROR)
    {
      EX = (String)file.DE.fileext;
      EX.trim();
      if(EX == "RAW"){
        myGLCD.print(file.DE.filename, x, y);
        myGLCD.drawRoundRect (x-1, y, x+64, y+10);
        y+=10;
        if (y > 230){
          y = 5;
          x+=72; 
        }      
      }
    }
  }
}
code]
I get the following message. "Initialising SD card... Wiring is correct and a card is present. Card typeL SD2 Fat16/Fat32 partition. make sure youve formatted"
Cannot see the whole message because I obviously have set up the screen aspect incorrectly.
What it is supposed to do is display the sd card contents on the screen and I have added several raw files which it cannot seem to read.

However when I run the controller code I intend to add which is as follows

///Code written by Steve Heitman
///based off original code written by 
///Nick Devan - Touch screen navagation code
///benjaf @ Github&theplantedtank - sunrise/sunset code
 
//#################    REVISION 5.5


//*******Included Libraries*******// 
#include <UTouch.h>
#include <avr/pgmspace.h>
#include <UTFT.h>
#include <tinyFAT.h>
#include <UTFT_tinyFAT.h>
#include <EEPROM.h>
#include <RTClib.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
const int chipSelect = 53; 
//********    Declare Touch/LCD/RTC    **********
UTFTtf  myGLCD(ITDB32S, 38, 39, 40, 41);   //sets LCD pins - change to your screen pin-out and aspect
UTouch  myTouch(6,5,4,3,2);     //sets touch pins - change to your set up (default is usually 6,5,4,3,2)
RTC_DS1307 RTC;
 
 
//********   Call Fonts    **********
extern uint8_t arial_bold[];
extern uint8_t Sinclair_S[];
extern uint8_t SevenSegmentFull[];

//*******   Declare 1-Wire for TEMP sensors  ********
#define ONE_WIRE_BUS 2               //sets sensor to pwm pin 2 - Change to your setup

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature tempsensors(&oneWire);

//DS18B20 sensor address' ******change these for your sensors*******
//link provided is a good sketch to get yours
//http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
//I added this link because I found this to be a much easier sketch to use than the Dallas Multiple Example when
//trying to find Address'on a 1 wire bus. 

 DeviceAddress tankTemp = { 0x28, 0x09, 0xD3, 0x07, 0x04, 0x00, 0x00, 0x80 };
 DeviceAddress sumpTemp = { 0x28, 0x48, 0x31, 0x2C, 0x04, 0x00, 0x00, 0x7F };
 DeviceAddress rSinkTemp = {0x28, 0x00, 0x2D, 0x47, 0x04, 0x00, 0x00, 0xF2 };
 DeviceAddress lSinkTemp = {0x28, 0x35, 0xF7, 0x2A, 0x04, 0x00, 0x00, 0x1A };
 
 float TANK;
 float SUMP;
 float SINK1;
 float SINK2;
 
//########################################################################################################
//###########################################      $Global Varibles      #############################[#VAR]
//########################################################################################################

//******************pH Variables*****************

long phReadInterval = 2000;
long previousMillisPH = 0;
int pHState = HIGH;

float pH_val;

//###   Touch Screen Varibles  ########################
int x, y;

//###   Screen Select Varibles  #######################

boolean home_screen = true;
boolean menu_screen = false;
boolean ledhome_screen = false;
boolean ledchannel_screen = false;
boolean ledevents_screen = false;
boolean clock_screen = false;
boolean tempgraph_screen = false;
boolean temphome_screen = false;
boolean ph_screen = false;
boolean settings_screen = false;
boolean outlet_screen = false;
boolean Enter_new_value = false;
boolean Enter_new_time = false;
boolean outlet_status = false;
boolean change_sunrise = false;
boolean change_moonmax = false;
boolean Enter_moon_value = false;

//###   Clock Varibles ################################

int Hours, Minutes, Seconds;
int Day;
int Month;
int Year;
int Weekday;
String Current_time;
boolean Daytime = true;
boolean Was_day;


//####Outlet Variables #########################

int OUTLETS[8] ={A8,A9,A10,A11,A12,A13,A14,A15};
int outletState = 0;

///### LED Variables ############################

const int Wht_Ch1 = 6;      //sets pwm pins for LED driver
const int RBlue_Ch1 = 7;
const int Blue_Ch1 = 8;
const int Wht_Ch2 = 9;
const int Blue_Ch2 = 11;
const int Wht_Ch3 = 12;
const int RBlue_Ch2 = 10;
const int UV_Ch1 = 13;      //change pins to your set-up if conflict

//#######Weather Strings###############

String Current_weather = "Sunny!";  //default strings...programs unfinished
String Coral_Accl = "off";

//###   Led Varibles ##################################
int White_max = 0;               //Dimming variables
int Blue_max = 0;
int RBlue_max = 0;
int UV_max = 0;
int change_max_bright = 0;

                                //EEPROM storage variables (address')
int whtsun = 0;                 //LEDs Max Bright
int rblsun = 1;                 
int blusun = 2;
int uvsun = 3; 
int savesunhour = 4;            //Sunrise Start time
int savesunmin = 5;
int savemoon = 6;


int Blue_Led_Brightness = 0;    //Print LEDs % variables
int RBlue_Led_Brightness = 0;
int White_Led_Brightness = 0;
int UV_Led_Brightness = 0;

//###################   Sunrise/SunSet Variables #########################
int RiseHour = 0;
int RiseMin = 0;
int change_start_time = 0;

const int CHANNELS = 8;
const int MAXPERIODS = 3;

const int Sunrise_Hr = 0;
const int Sunrise_Min = 1;
const int Sunset_Hr = 2;
const int Sunset_Min = 3;
const int SunLevel = 4;

int sunValue[CHANNELS] = {0, 0, 0, 0, 0, 0, 0, 0};
int sunMatrix[CHANNELS][MAXPERIODS][5];


//####################Moon Phase variables########################

float LC = 29.53059;
double AG;

int MI;
int MoonMax;
int MoonLow = 0;

//*****************************************************************************************************
//*****************************************************************************************************
//*******************************************      $Setup      ********************************[#SETUP]
//*****************************************************************************************************
//*****************************************************************************************************

void setup(){

  myGLCD.InitLCD(PORTRAIT);                           //Initiate LCD Screen
  myGLCD.clrScr();
  file.initFAT(SPISPEED_VERYHIGH);                    //Initiate SD Card for FAT16 Lib
  Wire.begin();
  RTC.begin();                                        //Initiate Real Time Clock
  
  myTouch.InitTouch(PORTRAIT);                        //Initiate Touch Screen for Portriat
  myTouch.setPrecision(PREC_HI);

  tempsensors.begin();                                  //Begin Dallas 1-Wire Temperature 
   
  tempsensors.setResolution(tankTemp, 10);              //sets DS18B20 sensors resolution
  tempsensors.setResolution(rSinkTemp, 10);
  tempsensors.setResolution(lSinkTemp, 10);
  tempsensors.setResolution(sumpTemp, 10);
  
  
   for (int on=0; on<8; on++) pinMode(OUTLETS[on], OUTPUT);        //array sets outlet box pins as outputs
 
   for (int on=0; on<8; on++) digitalWrite(OUTLETS[on], LOW);     //array sets outlet pins HIGH/ON
   
 //RTC.adjust(DateTime(__DATE__, __TIME__));            //Sets clock to current upload time - Uncomment for 1 upload, and then re-comment 
  
  White_max = EEPROM.read(whtsun);
  RBlue_max = EEPROM.read(rblsun);
  Blue_max = EEPROM.read(blusun);
  UV_max = EEPROM.read(uvsun);
  RiseHour = EEPROM.read(savesunhour);
  RiseMin = EEPROM.read(savesunmin);
  MI = EEPROM.read(savemoon);
  
  Serial.begin(9600);
  Serial3.begin(38400);

  boolean home_screen = true;
  Home_Screen();
}


/code]

I get a black screen and only when I have pushed my sd card down to release it and pushed it in again do I get an image on the screen however it is not the image I am supposed to get. 
I have read several things about the lcd screen and am starting to get confused. People have had many issues with incorrect wiring, chip select ids, different lcd pins, different touch pins and I am going around in circles.
If anyone can see anything that sheds some light on my problem please help.

I have cut the code to reduce the size

Using Pin output 53(for mega) and 53 also for CS seems to indicate running the example codes that it is working as far as initialising the sd card.
I get card initialized, wiring is correct, card type is SD2 but then I get an error about formatting and the contents cannot be read.
Perhaps I have the pins wrong?

For mega it should be SCK_PIN 52, MISO_PIN 50, MOSI_PIN 51, SS_PIN 53 I believe
Can someone assist me to physically test the wiring is correct perhaps?

To learn about pins, inspect the file Arduino/hardware/arduino/variants/mega/pins_arduino.h where you can see:

Code:
static const uint8_t SS = 53;
static const uint8_t MOSI = 51;
static const uint8_t MISO = 50;
static const uint8_t SCK = 52;

I investigate, that we can use predefined constants instead of numbers:

http://forum.arduino.cc/index.php?topic=200126.30

raschemmel:

To learn about pins, inspect the file Arduino/hardware/arduino/variants/mega/pins_arduino.h where you can see:

Code:
static const uint8_t SS = 53;
static const uint8_t MOSI = 51;
static const uint8_t MISO = 50;
static const uint8_t SCK = 52;

I investigate, that we can use predefined constants instead of numbers:

Serial SPI - 2.2" TFT LCD - ILI9341 - Displays - Arduino Forum

What is your advice for me? To redefine some pins, to read the above thread for clues or to use a different library and perhaps import it a different way?
I have read the thread referenced which was all about getting a non functioning different sized TFT lcd screen working, nothing to do with the sd card issue I have however perhaps the answer lies somewhere within it?
Thanks for the reply.

Thank you! That's right note! The answer is no - and that is the reason for the failure. The display started working after I've changed the definition:

Code:

#define TFTcs  53
#define TFTsclk 76 //HW SPI
#define TFTmosi 75 //HW SPI
#define TFTdc  49
#define TFTrst  48

So then you read this ?
Were you not asking if the pins were correct ?
Are these the same pins in your post ?

Yes I think so. I wasn't redefining any I was referring directly to hardware pins as I wanted to check them physically.

Yeah, your right. You're using a Mega so those pins should be correct.
The other guy was using a DUE.

I don't know why you are getting format error and SD card errors but you might want to isolate the problem
by running ONLY SD code using serial print statements to monitor the test. You have stated you have
errors but you have not stated that your SD card works by itself or not, have you ? (did I miss that ?)
If I understand correctly, the TFT, SD & touch are all in the same shield or unit or are any of them
separate ? Normally a person posting would post the link where they got the device (TFT whatever) so
people know what they are talking about . My question is :
Is there ANY circumstance under which the SD card works correctly , regardless of whether anything
else works ?

Hi again
You are correct and I didnt make my first post very clear.
The LCD panel, etc all seem to be working correctly.
Using examples from the UTFT library all seem to work.
Touch seems to work although calibration looks like it will be tricky but thats for later to sort out.

So indeed the SD card function is the only thing I cannot make work.
I cannot successfully run any SD or SDFAT examples without getting errors.

The TFT and SD are one device bought from here
http://www.google.co.nz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0CC8QFjAB&url=http%3A%2F%2Fstore.iteadstudio.com%2Findex.php%3Fmain_page%3Dproduct_info%26products_id%3D54&ei=nfvWUoWmA8-UiQfp6YDYBw&usg=AFQjCNGh23hq0Z9yiT3HfAWMhqV-9uYObg&bvm=bv.59568121,bs.1,d.dGI
And the shield with integrated RTC which is basically a 5v to 3.3v level shifter for the screen and connects directly to the mega is from here
http://imall.iteadstudio.com/im120717001.html

I cannot successfully run any SD or SDFAT examples without getting errors.

You do mean you removed everything EXCEPT the SD code , correct ?

ts a pretty good product Review by Reuben
Price
Value
Quality
I have managed to access the LCD, SD card and touch screen.
However the pin-out on the PCB is wrong !!
It should be this way:

1 2
3 4
.. ..
39 40

Itead, please correct the silk-screen !! (Posted on 4/24/13)

http://imall.iteadstudio.com/display/tft-lcm/im120419005.html

Yes I saw that also. Wasnt very explanatory. Thats the only info that you can see isn't it?
PIN out should be
12
34
....
39 40
didnt tell me much unfortunately.
I have had a hardware engineer from itead also trying to help me but he refused to help me physically test the poins and seemed to think it was software related. In the end his only suggestion was for me to manually wire it to an uno I have here and try again(the sd only that is)
I tried his suggestion and started getting avrdude errors which I guess means I have bootloader issues although it seemed to be working the last time I used it.

You saw the connector pinout under "Description" tab , right ?

What size SD card are you using?

The library supports FAT16 formatted SD cards up to 2GB in size. 4GB FAT16 formatted SD cards does not work. Long filenames are not supported. Keep your filenames compliant with the old 8.3 standard.

You might also like to try formatting the card from the program available from the SD Association - https://www.sdcard.org/downloads/formatter_4/

Good info.
Thanks.

Here's the pinout

pinout.docx (16.3 KB)

ANOTHER PINOUT diagram

3-2_TFT.jpg

raschemmel:
You saw the connector pinout under "Description" tab , right ?

Yes I did however none of the pinout diagrams are numbered.
also the partial "review" is useless because you cannot tell what is wrong with the pcb layout and what he is suggesting is correct.

Magicj:
What size SD card are you using?

The library supports FAT16 formatted SD cards up to 2GB in size. 4GB FAT16 formatted SD cards does not work. Long filenames are not supported. Keep your filenames compliant with the old 8.3 standard.

You might also like to try formatting the card from the program available from the SD Association - https://www.sdcard.org/downloads/formatter_4/

Thanks. That is how I formatted mine and my sd card is FAT 16 less than 2GB
Should also point out that it needs to be a non SDHC card also