TFT (ILI9341 ) & SD conflict

I have a project that need to use SD card and TFT display. I used a Mini Pro and a 2.2" TFT with

ILI9341 driver.

I found that both the Mini Pro and the TFT can work at 3.3 volt, they can connect directly and don’t

need 4050 as interface.

I followed the pin connections in :
http://www.seeedstudio.com/wiki/2.8''_TFT_Touch_Shield_V2.0

D4 : RESET (TFT), CS (SD)
D5 : CS (TFT)
D6 : D/C (TFT)
D7 : LED (TFT)
D11 : MOSI(TFT & SD)
D12 : MISO (TFT & SD)
D13 : SCK (TFT & SD)

I tried the TFTv2 library examples ( GitHub - gmtii/ili9341-arduino: ILI9341 2.2 LCD library ) and the Arduino SD

examples, they are all ok.

But When I tried to combined both SD codes & TFT codes together, it seems that SD or TFT cannot

used together at the same time.

e.g.

// --- The following codes work ok, it can serial out the text file and draw on TFT -----

#include <TFTv2.h>
#include <SPI.h>
#include <SD.h>

const int chipSelect = 4;

void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);

  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("Textfile.txt");

  // if the file is available, write to it:
  if (dataFile) 
  {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
    }
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  } 

    TFT_BL_ON;      // turn on the background light
    Tft.TFTinit();  // init TFT library
    
    Tft.drawChar('S',0,0,1,RED);                // draw char: 'S', (0, 0), size: 1, color: RED
    
    Tft.drawChar('E',10,10,2,BLUE);             // draw char: 'E', (10, 10), size: 2, color: BLUE
    
    Tft.drawChar('E',20,40,3,GREEN);            // draw char: 'E', (20, 40), size: 3, color: GREEN
    
    Tft.drawChar('E',30,80,4,YELLOW);           // draw char: 'E', (30, 80), size: 4, color: YELLOW
    
    Tft.drawChar('D',40,120,4,YELLOW);          // draw char: 'D', (40, 120), size: 4, color: YELLOW
    

    Tft.drawString("Hello",0,180,3,CYAN);       // draw string: "hello", (0, 180), size: 3, color: CYAN
    
    Tft.drawString("World!!",60,220,4,WHITE);    // draw string: "world!!", (80, 230), size: 4, color: 

WHITE
    

    dataFile.close();
  
}

void loop()
{
}

//-------------------------------- End of program --------------------------------------------------

But once I changed to display something to TFT, then run some SD functions , the TFT screen will be

erased and white screen. It seems that the problem is RESET(TFT) and CS(SD) are both connect to D4

and they have conflict !

//----------- conflict program ! -------------------------------------------------------------------------
void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);

  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
  

    TFT_BL_ON;      // turn on the background light
    Tft.TFTinit();  // init TFT library
    
    Tft.drawChar('S',0,0,1,RED);                // draw char: 'S', (0, 0), size: 1, color: RED
    
    Tft.drawChar('E',10,10,2,BLUE);             // draw char: 'E', (10, 10), size: 2, color: BLUE
    
    Tft.drawChar('E',20,40,3,GREEN);            // draw char: 'E', (20, 40), size: 3, color: GREEN
    
    Tft.drawChar('E',30,80,4,YELLOW);           // draw char: 'E', (30, 80), size: 4, color: YELLOW
    
    Tft.drawChar('D',40,120,4,YELLOW);          // draw char: 'D', (40, 120), size: 4, color: YELLOW
    

    Tft.drawString("Hello",0,180,3,CYAN);       // draw string: "hello", (0, 180), size: 3, color: CYAN
    
    Tft.drawString("World!!",60,220,4,WHITE);    // draw string: "world!!", (80, 230), size: 4, color: 

WHITE

  // if the file is available, write to it:
  if (dataFile) 
  {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
    }
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  } 
    dataFile.close();
  
}
//--------------------------------- End of Program ----------------------------------------------------

Does anyone know how to solve this problem ?

Thanks in advance !

please edit your post and put the code inside [ code] [ /code] tags like this:

code here

Hi KK959,

I have an screen with that chipset the ILI9341, mine is from elecfreaks trough dealextreme, i have tried all connections but I have not had any response from the times I tried. how you connected the screen, i imported the library from GitHub (UTFT v2) and tried the libraries from elecfreaks but it seems that code don´t says anything to my screen.

Please tell me how you do that.

Regards

KK959:
But once I changed to display something to TFT, then run some SD functions , the TFT screen will be

erased and white screen. It seems that the problem is RESET(TFT) and CS(SD) are both connect to D4

and they have conflict !

Every time you access the SD card the screen will reset. Yes, that would be a problem.

KK959:
Does anyone know how to solve this problem ?

Move CS to a different pin

XarlyX:
I have an screen with that chipset the ILI9341, mine is from elecfreaks trough dealextreme, i have tried all connections but I have not had any response from the times I tried. how you connected the screen, i imported the library from GitHub (UTFT v2) and tried the libraries from elecfreaks but it seems that code don´t says anything to my screen.

They don't work on a 5V Arduino.

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

I’d move the TFT CS to pin 10, which is the one normally used for SPI, and leave
pin 4 as SD CS. It will then be compatible with the Due pinout (SPI is restricted to
pins 4 and 10 for CS).

MarkT:
I'd move the TFT CS to pin 10, which is the one normally used for SPI, and leave
pin 4 as SD CS. It will then be compatible with the Due pinout (SPI is restricted to
pins 4 and 10 for CS).

He said " It seems that the problem is RESET(TFT) and CS(SD) are both connect to D4 "

the VCC pin of my screen goes to the 3,3v arduino pin. so i think that my arduino also works sending +3.3 volts.

i have read all the arduino.cc posts referring to this screen and everyone says always the same

Screen only works with +3.3v

and all the pepole finally get the screen working correctly so where is my error mr. fungus?

i'm gonna remake my question
I have seen a group of youtube videos in where the users have the same screen and they show icons, photos or animations (of processing) and every time i make a question the response is the same "get the libraries from GitHUB and connect like this" in which results are the same a) a completely blue screen b) a full white screen.

please make to me a graphic of the connections and the code (like an example) for check that my screen is OK

Thx

XarlyX:
the VCC pin of my screen goes to the 3,3v arduino pin. so i think that my arduino also works sending +3.3 volts.

i have read all the arduino.cc posts referring to this screen and everyone says always the same

Screen only works with +3.3v

and all the pepole finally get the screen working correctly so where is my error mr. fungus?

Well ... it you follow the link I posted you might find out.

Hint: It's not just connecting VCC to 3.3V - that's the ONLY pin that can be connected to 5V (the screen has a voltage regulator on VCC)

Sorry Fungus but i don't understand you, in this link you have posted (which I have read over thirty times) all I see is that an user is using an IC so what I should be reading in the link

XarlyX:
Sorry Fungus but i don't understand you, in this link you have posted (which I have read over thirty times) all I see is that an user is using an IC so what I should be reading in the link

Maybe you should be using an IC as well.

Dear,
I had the same problem like you so I register account to reply but dont know why can not post on the forum.
The problem is SDCard library.
You should not use the example which declare
SDFile root;
Instead
File root.
CODE: havent check yet, hope this helps!

SdFile root; //this one will reset your lcd everytime!
File root2; // this one will not reset, but it flick your display, makes image quality is terrible. I havenot found and solution to fix yet.

void setup(void) {
if (!SD.begin(4)) {
Serial.println(“initialization failed!”);
return;
}
root2 = SD.open("/");
printDirectory(root2, 0);
}
void loop() {

}

void printDirectory(File dir, int numTabs) {
while (true) {

File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print(’\t’);
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}

KK959:
I have a project that need to use SD card and TFT display. I used a Mini Pro and a 2.2" TFT with

ILI9341 driver.

I found that both the Mini Pro and the TFT can work at 3.3 volt, they can connect directly and don’t

need 4050 as interface.

I followed the pin connections in :
http://www.seeedstudio.com/wiki/2.8''_TFT_Touch_Shield_V2.0

D4 : RESET (TFT), CS (SD)
D5 : CS (TFT)
D6 : D/C (TFT)
D7 : LED (TFT)
D11 : MOSI(TFT & SD)
D12 : MISO (TFT & SD)
D13 : SCK (TFT & SD)

I tried the TFTv2 library examples ( GitHub - gmtii/ili9341-arduino: ILI9341 2.2 LCD library ) and the Arduino SD

examples, they are all ok.

But When I tried to combined both SD codes & TFT codes together, it seems that SD or TFT cannot

used together at the same time.

e.g.

// --- The following codes work ok, it can serial out the text file and draw on TFT -----

#include <TFTv2.h>
#include <SPI.h>
#include <SD.h>

const int chipSelect = 4;

void setup()
{
// Open serial communications and wait for port to open:
 Serial.begin(9600);

Serial.print(“Initializing SD card…”);
 // make sure that the default chip select pin is set to
 // output, even if you don’t use it:
 pinMode(10, OUTPUT);
 
 // see if the card is present and can be initialized:
 if (!SD.begin(chipSelect)) {
   Serial.println(“Card failed, or not present”);
   // don’t do anything more:
   return;
 }
 Serial.println(“card initialized.”);
 
 // open the file. note that only one file can be open at a time,
 // so you have to close this one before opening another.
 File dataFile = SD.open(“Textfile.txt”);

// if the file is available, write to it:
 if (dataFile)
 {
   while (dataFile.available()) {
     Serial.write(dataFile.read());
   }
 }  
 // if the file isn’t open, pop up an error:
 else {
   Serial.println(“error opening datalog.txt”);
 }

TFT_BL_ON;      // turn on the background light
   Tft.TFTinit();  // init TFT library
   
   Tft.drawChar(‘S’,0,0,1,RED);                // draw char: ‘S’, (0, 0), size: 1, color: RED
   
   Tft.drawChar(‘E’,10,10,2,BLUE);             // draw char: ‘E’, (10, 10), size: 2, color: BLUE
   
   Tft.drawChar(‘E’,20,40,3,GREEN);            // draw char: ‘E’, (20, 40), size: 3, color: GREEN
   
   Tft.drawChar(‘E’,30,80,4,YELLOW);           // draw char: ‘E’, (30, 80), size: 4, color: YELLOW
   
   Tft.drawChar(‘D’,40,120,4,YELLOW);          // draw char: ‘D’, (40, 120), size: 4, color: YELLOW

Tft.drawString(“Hello”,0,180,3,CYAN);       // draw string: “hello”, (0, 180), size: 3, color: CYAN
   
   Tft.drawString(“World!!”,60,220,4,WHITE);    // draw string: “world!!”, (80, 230), size: 4, color:

WHITE

dataFile.close();
 
}

void loop()
{
}

//-------------------------------- End of program --------------------------------------------------




But once I changed to display something to TFT, then run some SD functions , the TFT screen will be 

erased and white screen. It seems that the problem is RESET(TFT) and CS(SD) are both connect to D4 

and they have conflict !


//----------- conflict program ! -------------------------------------------------------------------------
void setup()
{
// Open serial communications and wait for port to open:
 Serial.begin(9600);

Serial.print(“Initializing SD card…”);
 // make sure that the default chip select pin is set to
 // output, even if you don’t use it:
 pinMode(10, OUTPUT);
 
 // see if the card is present and can be initialized:
 if (!SD.begin(chipSelect)) {
   Serial.println(“Card failed, or not present”);
   // don’t do anything more:
   return;
 }
 Serial.println(“card initialized.”);

TFT_BL_ON;      // turn on the background light
   Tft.TFTinit();  // init TFT library
   
   Tft.drawChar(‘S’,0,0,1,RED);                // draw char: ‘S’, (0, 0), size: 1, color: RED
   
   Tft.drawChar(‘E’,10,10,2,BLUE);             // draw char: ‘E’, (10, 10), size: 2, color: BLUE
   
   Tft.drawChar(‘E’,20,40,3,GREEN);            // draw char: ‘E’, (20, 40), size: 3, color: GREEN
   
   Tft.drawChar(‘E’,30,80,4,YELLOW);           // draw char: ‘E’, (30, 80), size: 4, color: YELLOW
   
   Tft.drawChar(‘D’,40,120,4,YELLOW);          // draw char: ‘D’, (40, 120), size: 4, color: YELLOW

Tft.drawString(“Hello”,0,180,3,CYAN);       // draw string: “hello”, (0, 180), size: 3, color: CYAN
   
   Tft.drawString(“World!!”,60,220,4,WHITE);    // draw string: “world!!”, (80, 230), size: 4, color:

WHITE

// if the file is available, write to it:
 if (dataFile)
 {
   while (dataFile.available()) {
     Serial.write(dataFile.read());
   }
 }  
 // if the file isn’t open, pop up an error:
 else {
   Serial.println(“error opening datalog.txt”);
 }
   dataFile.close();
 
}
//--------------------------------- End of Program ----------------------------------------------------





Does anyone know how to solve this problem ? 

Thanks in advance !