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 !