TFT LCD Works, SD doesn't

Hello, I purchased a 3.2" TFT LCD with SD slot and a Mega shield for it. ( http://www.ebay.com/itm/261027696490?redirect=mobile) The ad for the screen says that the SD part is incompatible with Mega, the example software it came with has a few SD eamples, but they don't work, They compile on arduino 23 but nothing newer and returns MBR error on every SD card I've tried. Has anyone purchased one of these and gotten it to work? I am hoping to load pics from the sd card to display them on the lcd. When I get my computer fixed I will post some code.
Thanks
-Brad

The ad for the screen says that the SD part is incompatible with Mega ...

Many, if not most, non-commercial implementations of the SD card rely on an I2C interface. Due to the internal workings of the underlying microprocessors the I2C pins are different on the UNO and the MEGA which is what causes this incompatibility. It may be difficult, but probably not impossible, to modify the shield to make it work with the MEGA.

Don

Would i be better off purchasing a separate SD breakout? I would like to remotely mount the SD slot, as in on the other side of the enclosure. I am looking at this one ( http://www.amazon.com/SD-Micro-Card-Breakout-Module/dp/B0068EW7KS/ref=sr_1_1?ie=UTF8&qid=1350667582&sr=8-1&keywords=sd+breakout), Would I be able to load images straight from a separate SD breakout to the LCD? The shield doesn't use the analog pins so they are free, the I2C uses analog pins right? I would also like to store other data on the SD. Thanks
-Brad

Eugh, appalling documentation for what might be a great board, but how would you ever know?

I think you mean SPI, not I2C - SDcards and microSD cards have an SPI interface, but note they are both 3.3V, and need level conversion to work from 5V uController. This might be what is meant about SDcard not compatible with Mega. Can't tell what the pinout out is, and can't even see link to their site or any code!!

Without a schematic for the board and TFT module its hard to help alas...

I think you mean SPI, not I2C -

Yes, you are correct it is SPI not I2C. I think the rest of my interpretation is correct however.

Don

I can only give you generalized help on this subject, and only on part of it, since my use (so far) of an SD interface is negligible (as proven by the previous two posts).

Would i be better off purchasing a separate SD breakout?

A 'shield' is a specialized form of a 'breakout'. Breakouts, such as the one in your Amazon link, are more or less generic and typically quite flexible in terms of mounting. On the other hand you have to take care of making the proper interconnections. Shields are specifically designed to mate only with an Arduino and sometimes only with specific variations of the Arduino. You loose flexibility but you gain the advantage of knowing that the connections are secure and correct (if you use the appropriate Arduino).

...the I2C uses analog pins right?

I believe they do, but this is a moot point now since we are really concerned with the SPI pins!

Don

Shadow42:
Hello, I purchased a 3.2" TFT LCD with SD slot and a Mega shield for it. ( http://www.ebay.com/itm/261027696490?redirect=mobile) The ad for the screen says that the SD part is incompatible with Mega, the example software it came with has a few SD eamples, but they don't work, They compile on arduino 23 but nothing newer and returns MBR error on every SD card I've tried. Has anyone purchased one of these and gotten it to work? I am hoping to load pics from the sd card to display them on the lcd. When I get my computer fixed I will post some code.
Thanks
-Brad

I just bought a Seeed TFT shield to play with a few days ago and it takes up most of the UNO I/O pins (including pins 4 and 10 which SD card shields use). So I can't use the sketch that is supposed to display a BMP image on the TFT display.

I plan to try one of these boards:

(click pic for link)

...which is just a matrix of solder jumpers that allows you to map any pin to any pin.

For example, you need pin 4, but it's used (but pin A0 is free?) - just solder the proper jumper and A0 goes to pin 4.

A REALLY cool board would be something similar with a PLD instead of solder jumpers... just program the PLD to map any pin to any pin. (HEY maybe I should make one!) LOL!

Hope this helps.

-- Roger

OK so I've got my computer put back together, I played around with it a little more but still can't get the SD to work.

Here is the code that makes the TFT work (LCD and Touch part):

// ITDB02_Graph16_Demo (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of how to use the library with the
// ITDB02-3.2 module. This demo should also work with the
// ITDB02-2.4 module in 16bit mode, but this is untested.
//
// This demo is not made for the ITDB02-3.2WC module. Use
// ITDB02_Graph16_Demo_Widescreen instead.
//
// This program requires the ITDB02_Graph16 (16bit mode).
//
// It is assumed that the ITDB02 module is connected to a
// ITDB02 Shield, a ITDB02 Mega Shield or that you know how 
// to change the pin numbers in the setup.
//

#include <ITDB02_Graph16.h>

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

// Uncomment the next line for the ITDB02 Shield
//ITDB02 myGLCD(19,18,17,16);

// Uncomment the next line for the ITDB02 Mega Shield
ITDB02 myGLCD(38,39,40,41);

void setup()
{
  randomSeed(analogRead(0));
  
// Setup the LCD
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.setFont(SmallFont);
}

void loop()
{
  int buf[318];
  int x, x2;
  int y, y2;
  int r;

// Clear the screen and draw the frame
  myGLCD.clrScr();

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.fillRect(0, 226, 319, 239);
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print("*** Arduino - 240x320 Color Display ***", CENTER, 1);
  myGLCD.setColor(255, 128, 128);
  myGLCD.setBackColor(64, 64, 64);
  myGLCD.print("H.Karlsen", LEFT, 227);
  myGLCD.print("(C)2010", RIGHT, 227);
  myGLCD.setColor(255,255,0);
  myGLCD.print("*** welcom to arduino", CENTER, 227);

  myGLCD.setColor(0, 0, 255);
  myGLCD.drawRect(0, 14, 319, 225);

// Draw crosshairs
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.drawLine(159, 15, 159, 224);
  myGLCD.drawLine(1, 119, 318, 119);
  for (int i=9; i<310; i+=10)
    myGLCD.drawLine(i, 117, i, 121);
  for (int i=19; i<220; i+=10)
    myGLCD.drawLine(157, i, 161, i);

// Draw sin-, cos- and tan-lines  
  myGLCD.setColor(0,255,255);
  myGLCD.print("Sin", 5, 15);
  for (int i=1; i<318; i++)
  {
    myGLCD.drawPixel(i,119+(sin(((i*1.13)*3.14)/180)*95));
  }
  
  myGLCD.setColor(255,0,0);
  myGLCD.print("Cos", 5, 27);
  for (int i=1; i<318; i++)
  {
    myGLCD.drawPixel(i,119+(cos(((i*1.13)*3.14)/180)*95));
  }

  myGLCD.setColor(255,255,0);
  myGLCD.print("Tan", 5, 39);
  for (int i=1; i<318; i++)
  {
    myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180)));
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.drawLine(159, 15, 159, 224);
  myGLCD.drawLine(1, 119, 318, 119);

// Draw a moving sinewave
  x=1;
  for (int i=1; i<(318*20); i++) 
  {
    x++;
    if (x==319)
      x=1;
    if (i>319)
    {
      if ((x==159)||(buf[x-1]==119))
        myGLCD.setColor(0,0,255);
      else
        myGLCD.setColor(0,0,0);
      myGLCD.drawPixel(x,buf[x-1]);
    }
    myGLCD.setColor(0,255,255);
    y=119+(sin(((i*1.1)*3.14)/180)*(90-(i / 100)));
    myGLCD.drawPixel(x,y);
    buf[x-1]=y;
  }

  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some filled rectangles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        myGLCD.setColor(255,0,255);
        break;
      case 2:
        myGLCD.setColor(255,0,0);
        break;
      case 3:
        myGLCD.setColor(0,255,0);
        break;
      case 4:
        myGLCD.setColor(0,0,255);
        break;
      case 5:
        myGLCD.setColor(255,255,0);
        break;
    }
    myGLCD.fillRect(70+(i*20), 30+(i*20), 130+(i*20), 90+(i*20));
  }

  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some filled, rounded rectangles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        myGLCD.setColor(255,0,255);
        break;
      case 2:
        myGLCD.setColor(255,0,0);
        break;
      case 3:
        myGLCD.setColor(0,255,0);
        break;
      case 4:
        myGLCD.setColor(0,0,255);
        break;
      case 5:
        myGLCD.setColor(255,255,0);
        break;
    }
    myGLCD.fillRoundRect(190-(i*20), 30+(i*20), 250-(i*20), 90+(i*20));
  }
  
  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some filled circles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        myGLCD.setColor(255,0,255);
        break;
      case 2:
        myGLCD.setColor(255,0,0);
        break;
      case 3:
        myGLCD.setColor(0,255,0);
        break;
      case 4:
        myGLCD.setColor(0,0,255);
        break;
      case 5:
        myGLCD.setColor(255,255,0);
        break;
    }
    myGLCD.fillCircle(100+(i*20),60+(i*20), 30);
  }
  
  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some lines in a pattern
  myGLCD.setColor (255,0,0);
  for (int i=15; i<224; i+=5)
  {
    myGLCD.drawLine(1, i, (i*1.44)-10, 224);
  }
  myGLCD.setColor (255,0,0);
  for (int i=224; i>15; i-=5)
  {
    myGLCD.drawLine(318, i, (i*1.44)-11, 15);
  }
  myGLCD.setColor (0,255,255);
  for (int i=224; i>15; i-=5)
  {
    myGLCD.drawLine(1, i, 331-(i*1.44), 15);
  }
  myGLCD.setColor (0,255,255);
  for (int i=15; i<224; i+=5)
  {
    myGLCD.drawLine(318, i, 330-(i*1.44), 224);
  }
  
  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,225);

// Draw some random circles
  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=32+random(256);
    y=45+random(146);
    r=random(30);
    myGLCD.drawCircle(x, y, r);
  }

  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some random rectangles
  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(316);
    y=16+random(207);
    x2=2+random(316);
    y2=16+random(207);
    myGLCD.drawRect(x, y, x2, y2);
  }

  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some random rounded rectangles
  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(316);
    y=16+random(207);
    x2=2+random(316);
    y2=16+random(207);
    myGLCD.drawRoundRect(x, y, x2, y2);
  }

  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(316);
    y=16+random(209);
    x2=2+random(316);
    y2=16+random(209);
    myGLCD.drawLine(x, y, x2, y2);
  }

  delay(2000);
  
  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

  for (int i=0; i<10000; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    myGLCD.drawPixel(2+random(316), 16+random(209));
  }

  delay(2000);

  myGLCD.fillScr(0, 0, 255);
  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRoundRect(80, 70, 239, 169);
  
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print("That's it!", CENTER, 93);
  myGLCD.print("Restarting in a", CENTER, 119);
  myGLCD.print("few seconds...", CENTER, 132);
  
  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 255);
  myGLCD.print("Runtime: (msecs)", CENTER, 210);
  myGLCD.printNumI(millis(), CENTER, 225);
  
  delay (10000);
}

Here is the SD Example Code given, it compiles in arduino 23 and runs but just displays "File Not Found..." for all images (The raw images were included with the download and are on the root directory of the SD card)

// _320x240_Landscape (C)2011 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of the loadBitmap()-function.
//
// This program requires the ITDB02_Graph16 v4.1 or higher, 
// as well as the tinyFAT library.
//
// It is assumed that the ITDB02 module is connected to a
// ITDB02 Mega Shield or that you know how to change the
// pin numbers in the setup.
//
// This demo requires the ITDB02-3.2 (240x320) module.
//
// The files PIC301.RAW to PIC310.RAW must be present in
// on the root folder of a FAT16 formatted SDcard in the
// module cardslot.
//

#include <tinyFAT.h>
#include <ITDB02_Graph16.h>
#include <ITDB02_tinyFAT16.h>

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

ITDB02tf myGLCD(38,39,40,41);

// List of filenames for pictures to display
char* files[]={"PIC301.RAW", "PIC302.RAW", "PIC303.RAW", "PIC304.RAW", "PIC305.RAW", "PIC306.RAW", "PIC307.RAW", "PIC308.RAW", "PIC309.RAW", "PIC310.RAW"}; // 320x240

int displaysize_x=320;
int displaysize_y=240;
int pixsize_x=320;
int picsize_y=240;
boolean display_rendertime=false;  // Set this to true if you want the rendertime to be displayed after a picture is loaded
boolean display_filename=true;  // Set this to false to disable showing of filename

word res;
long sm, em;

void setup()
{
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.clrScr();
  file.initFAT();
  myGLCD.setColor(255,255,255);
  myGLCD.setFont(SmallFont);
}

void loop()
{
  
  for (int i=0; i<(sizeof(files)/sizeof(*files)); i++)
  {
    sm=millis();
    res=myGLCD.loadBitmap((displaysize_x/2)-(pixsize_x/2), (displaysize_y/2)-(picsize_y/2), pixsize_x, picsize_y, files[i]);
    em=millis();
    if (res!=0)
    {
      if (res==0x10)
      {
        myGLCD.print("File not found...", 0, 0);
        myGLCD.print(files[i], 0, 14);
      }
      else
      {
        myGLCD.print("ERROR: ", 0, 0);
        myGLCD.printNumI(res, 56, 0);
      }
      delay(3000);
      myGLCD.clrScr();
    }
    else
    {
      if (display_rendertime==true)
      {
        myGLCD.print("Rendertime (secs):", 0, 0);
        myGLCD.printNumF(float((em-sm)/1000.0), 2, 160,0);
      }
      if (display_filename==true)
      {
        myGLCD.print(files[i], CENTER, displaysize_y-12);
      }
      delay(3000);
    }
  }
}

I have tried 4 different SD cards: a 32M Canon, 2G SanDisk, 2G Elite Pro, 4G Kingston (Tried each formatted as FAT under Windows).

I would like to put images on the SD card that will be displayed as menus, then have the touches act accordingly. I ordered that SD Breakout board, in the picture there appears to be a 5V-3.3V switch, would it still need some kind of conversion? I will try to post more info on the shield later. Sorry for the length but there is a lot here. Thanks
-Brad

Hello.
I have the same problem but i resolved in a "hardware" way.
I use this shield : "TFT LCD Mega Shield V1.2"
http://www.ebay.com/itm/3-2-TFT-LCD-Shield-V1-2-Arduino-Mega-2560-1280-R3-A082-/261070125371
and TFT3.2 320*240 ,"HY-TFT320_262K".
I use "UTFT tinyFAT" library
Demo_Landscape (C)2012 Henning Karlsen
web: Electronics - Henning Karlsen
So, after some test with diverse libraries still not work,so i take an oscilloscope and i look at SD card pins.
The "MOSI" and "SCK" are switched.I made the modification by inversion of pins "51" with "52" at the solder side of the "TFT LCD Mega Shield V1.2".
I works with a classic 2Gb SD card.With an old 512 Mb card don't work because, i think, is an 5 Volt card.
No i try to learn C++ programming. :slight_smile:
73!

I suggest leaving some eBay feedback (!).

BTW there are no 5V cards, 3.3V is the highest (cards may negotiate and drop down to lower
voltage for native mode for SDHC and SDXC cards, but 3.3V will always work for SPI)