Serial SPI - 2.2" TFT LCD - ILI9341

I got 2.2’ TFT LCD: TFT01-2.2SP, but I am not able find proper wiring for Arduino Mega 2560. Has anyone of you this TFT working?

Description:
    Operating Voltage: 5v/3.3v
    material: plastic
    Quantity: 1PC
    Size : 67mmX40mm/2.63''x1.57''
    Color : as show the picture
    Congroller: ILI9341
    Resolution: QVGA 240*320 Dots
    Package includes:
     1pc X  2.2 Inch SPI TFT LCD Serial Port Module

I tried connect as follows

VCC - +5V
GND - GND
#define _cs   53 //SS
#define _rst  42 //RESET
#define _dc   43 //D/C
#define _mosi 51 //SDI(MOSI)
#define _sclk 52 //SCK
LED - +3.3V
#define _miso 50 //SDO(MISO)

Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _mosi, _sclk, _rst, _miso);

Also I tried Seeed Studio library, but I do not understand this

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)

#define TFT_CS_LOW  {DDRE |= 0x08;PORTE &=~ 0x08;}
#define TFT_CS_HIGH {DDRE |= 0x08;PORTE |=  0x08;}
#define TFT_DC_LOW  {DDRH |= 0x08;PORTH &=~ 0x08;}
#define TFT_DC_HIGH {DDRH |= 0x08;PORTH |=  0x08;}
#define TFT_BL_OFF  {DDRH |= 0x10;PORTH &=~ 0x10;}
#define TFT_BL_ON   {DDRH |= 0x10;PORTH |=  0x10;}
#define TFT_RST_OFF {DDRD |= 0x10;PORTD |=  0x10;}
#define TFT_RST_ON  {DDRD |= 0x10;PORTD &=~ 0x10;}

#define YP A2   // must be an analog pin, use "An" notation!
#define XM A1   // must be an analog pin, use "An" notation!
#define YM 54   // can be a digital pin, this is A0
#define XP 57   // can be a digital pin, this is A3

#elif defined(__AVR_ATmega32U4__)

#define TFT_CS_LOW  {DDRC |= 0x40;PORTC &=~ 0x40;}
#define TFT_CS_HIGH {DDRC |= 0x40;PORTC |=  0x40;}
#define TFT_DC_LOW  {DDRD |= 0x80;PORTD &=~ 0x80;}
#define TFT_DC_HIGH {DDRD |= 0x80;PORTD |=  0x80;}
#define TFT_BL_OFF  {DDRE |= 0x40;PORTE &=~ 0x40;}
#define TFT_BL_ON   {DDRE |= 0x40;PORTE |=  0x40;}
#define TFT_RST_OFF {DDRD |= 0x10;PORTD |=  0x10;}
#define TFT_RST_ON  {DDRD |= 0x10;PORTD &=~ 0x10;}

#define YP A2   // must be an analog pin, use "An" notation!
#define XM A1   // must be an analog pin, use "An" notation!
#define YM 18   // can be a digital pin, this is A0
#define XP 21   // can be a digital pin, this is A3

#else
#define TFT_CS_LOW  {DDRD |= 0x20;PORTD &=~ 0x20;}
#define TFT_CS_HIGH {DDRD |= 0x20;PORTD |=  0x20;}
#define TFT_DC_LOW  {DDRD |= 0x40;PORTD &=~ 0x40;}
#define TFT_DC_HIGH {DDRD |= 0x40;PORTD |=  0x40;}
#define TFT_BL_OFF  {DDRD |= 0x80;PORTD &=~ 0x80;}
#define TFT_BL_ON   {DDRD |= 0x80;PORTD |=  0x80;}
#define TFT_RST_OFF {DDRD |= 0x10;PORTD |=  0x10;}
#define TFT_RST_ON  {DDRD |= 0x10;PORTD &=~ 0x10;}


#define YP A2   // must be an analog pin, use "An" notation!
#define XM A1   // must be an analog pin, use "An" notation!
#define YM 14   // can be a digital pin, this is A0
#define XP 17   // can be a digital pin, this is A3

#endif

specifically that part

#define TFT_CS_LOW  {DDRE |= 0x08;PORTE &=~ 0x08;}
#define TFT_CS_HIGH {DDRE |= 0x08;PORTE |=  0x08;}
#define TFT_DC_LOW  {DDRH |= 0x08;PORTH &=~ 0x08;}
#define TFT_DC_HIGH {DDRH |= 0x08;PORTH |=  0x08;}
#define TFT_BL_OFF  {DDRH |= 0x10;PORTH &=~ 0x10;}
#define TFT_BL_ON   {DDRH |= 0x10;PORTH |=  0x10;}
#define TFT_RST_OFF {DDRD |= 0x10;PORTD |=  0x10;}
#define TFT_RST_ON  {DDRD |= 0x10;PORTD &=~ 0x10;}

What are these pins?

This looks like a kind of pin-mapping for the connection of the TFT. As i saw in the datasheet you need 2 power sources ?, and the whole thing is driven bei SPI.

SDO: Serial clock output LED: 3.4V Power Supply pin SCL: Serial clock input SDA / SDI: Serial data input DC: Data / Command selection RST: Reset, Low level active CS: Chip Selection, Low level active GND: Ground VDD33: 3.3V Power Supply pin UTFT Support

GND & Vcc is for the circuit, LED is power for led.

Did you connect RESET and is this HIGH or LOW ?

Am I missing something ?
I don’t see any SPI transfer commands.
Where is the rest of you code.
All I see is definitions.
Can you please photograph your interface so we can see where all the wires go ?

I know, what are functions of the pins on the board, but I'm confused about how they are named in libraries and examples

For example: UTFT(byte model, int RS, int WR,int CS, int RST, int SER=0); means what? RS - ? WR - ? CS - CS RST - RESET SER - ? Edit: this was for paralel interface, for serial is syntax obvious: UTFT(model,SERIAL_DATA_INPUT_MOSI,SERIAL_CLOCK_SCLK,CHIP_SELECT_CS,RESET, REGISTER_SELECT_DC);

raschemmel: Am I missing something ?

I use libraries and only modify PINS in the examples to test. So rest of code I do not post deliberately. https://github.com/adafruit/Adafruit_ILI9340 http://www.seeedstudio.com/wiki/2.8%27%27_TFT_Touch_Shield_V2.0

I'll take some photographs and publish them.

That’s fine but we need to know exactly which example you are running. Just telling us you’re using
this or that library doesn’t tell us which example you are trying to run with that library.
Also, you are forcing us to chase down libraries and examples which takes time.
What we need is the code for the example pasted in (or uploaded) and the library (uploaded)
That gives us everything we need , right here, right now.
Then a statement:
Tried to run “Hello World” from Seeed Studio (see attached)
Here’s my definitions and photos.

My latest attempt. I found ili9341 library on github for exactly same display. I investigate pin assignment for MEGA2560 and (may be wrong) here is:

{DDRE |= 0x08;PORTE &=~ 0x08;} //D5? CS
{DDRH |= 0x08;PORTH &=~ 0x08;} //D6? DC
{DDRH |= 0x10;PORTH &=~ 0x10;} //D7 backlight
{DDRD |= 0x10;PORTD &=~ 0x10;} //D4? RESET

My actual wiring is now:
SDO(MISO) - MISO
LED - D7
SCK - SCK
SDI(MOSI) - MOSI
D/C - D6
RESET - D4
CS - D5
GND - GND
VCC - +5V

Every example I run, serial monitor shows:

Read TFT ID failed, ID should be 0x09341, but read ID = 0x000

so it is obvious that the SPI communication is not working (only turning backlight on/off is working)

Attached ZIP file contains library and examples. I made no modifications.
The photo shows my bowl of spaghetti.

ili9341-arduino-master.zip (589 KB)

Ok , please bear with me . I need to ask you something just to make sure it is not the issue. Exactly how did you install the library? Did you unzip it somewhere and copy it the library directory or did you unzip it DIRECTLY to the My Documents\Arduino\Libraries folder using the winzip explorer window?

Next, exactly how did you launch the program ? Did you use Files\Open My Documents\Arduino[library directory][filename] ? or did you use Sketch\add file\My Documents\Arduino[library directory][filename] ? or did you use Files\Examples[select program using drop down mouse menus ? then click on RUN =>

Read this: http://arduino.cc/en/Guide/Libraries

Adding libraries and running examples is not problem. During test I have only one library in Arduino folder, because tested libraries may collide. I know about it and it is not my problem. Problem is SPI communication - or display may be faulty.

So far everything looks OK (hardware, wiring and sketch) so it COULD be that the tft is damaged/didn't work

Did you see any feedback from the display, i.e. power led, bg light on or something like this ?

Backlight is working. Setting D7 to high or low turns backlight on or off. The display is a little more heated.

Although PCB contains a voltage regulator 5V -> 3V, I suspect that the 5V I/O data signals coming from Arduino the chip ILI9341 can not handle. The datasheet says: ILI9341 can operate with 1.65V ~ 3.3V I/O interface voltage.

You might want to try one of these: OKI-78SR-3.3/1.5-W36-C 4.95W 24Vin 3.3Vout (That's P(W) = I(A)V(V) => **4.95W/3.3V=[u]1.5A[/u]* available at Mouser: Mouser P/N: 580-OKI78SR3.31.536C

http://www.mouser.com/ProductDetail/Murata/OKI-78SR-33-15-W36-C/?qs=%2fha2pyFadug1ZrXHkIky7LtoJCPWCweGXaSSyT98oJvt1QArCaucX9tJYw9tEMiA

Firstly that chip is 3.3V logic only, DO NOT connect 5V signals to it or you may fry it.

The LED pin should not be connected directly to 3.3V, it needs about 30 ohms to 5V or about 5 ohms to 3.3V (its directly driving some white LEDs in parallel that need about 60mA)

[quote]I know, what are functions of the pins on the board, but I'm confused about how they are named in libraries and examples

For example:
UTFT(byte model, int RS, int WR,int CS, int RST, int SER=0);
means what?

RS - ?
WR - ?
CS - CS
RST - RESET
SER - ?[/quote]

Could you clarfy this statement please ?
Specifically what are the question marks supposed to mean ?
For example , do they mean that you don't know that RS means ROW SELECT
or that CS means COLUMN SELECT, which is probably why they use WR , because CS which
normally on SPI means CHIP SELECT.  Quite honestly I'm just guessing here. If this were not
a display then my above statement/question wouldn't make any sense. 
SER- quite frankly the only thing that comes to mind for this is SERIAL.

In the following: 
[codeAdafruit_ILI9340(uint8_t CS, uint8_t RS, uint8_t [b]MOSI[/b], uint8_t [b]SCLK,[/b]           uint8_t RST, uint8_t [b][b]MISO[/b][/b]);
  Adafruit_ILI9340(uint8_t CS, uint8_t RS, uint8_t RST);]

for SPI you need SCK- check MISO- check MOSI- check SS- ? I don't see it.

I guess what I'm confused about is why are you talking about what they are named in the libraries ? You said you were using example code but why do care what they are named in the libraries ? I've never actually READ the code in a library and I have one parallel LCD, one SPI LCD, numerous shields and a 6-digit seven segment LCD and they're all working . But they weren't always. Most of them did not work at all when I first tried to test them until I found out I was not installing libraries correctly and then all of a sudden everything worked. I am assuming the only code you look at is the example and you're talking about libraries but not actually reading them. So in short, do you mean you don't know what they are called in the example program which is, (I presume) the only thing you are actually editing ? You gave us an example above. Can you tell us the filename it came from and a link to the entire example program code or upload the code and follow it with what you are not clear on as you have done above ?

For example: UTFT(byte model, int RS, int WR,int CS, int RST, int SER=0); means what?

Note that SER is the only one assigned a value. Do you think it could mean Arduino pin-0 = SERIAL input as in RX ?

Optional parameters get a default value using that syntax

MarkT:
Firstly that chip is 3.3V logic only…

I thought so and it was confirmed. Today I received Arduino DUE, I use same wiring as above and it success! Display is working.

I use MultiLCD library and I modify included TFThello.INO example:

#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <MultiLCD.h>

#define OFFSET 12
#define WIDTH 48
#define HEIGHT 48
#define XBORDER 14
#define YBORDER 6

static const PROGMEM uint8_t smile[48 * 48 / 8] = {
  0x00,0x00,0x00,0x00,0x00,0x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x87,0xC7,0xE1,0xF0,0xF8,0xFC,0xFF,0xFF,0xFF,0x7F,0x3F,0x0F,0x03,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x1F,0x3F,0x3F,0x7F,0x7F,0x7E,0xFE,0xFE,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFE,0xFE,0x7E,0x7F,0x7F,0x3F,0x3F,0x1F,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
};

LCD_ILI9341 lcd; /* for 2.2" SPI TFT module */

int mydelay = 200;

void setup()
{
  Serial.begin(115200);
  lcd.begin();
};

void loop()
{
  lcd.backlight(true);
  lcd.clear();
  lcd.setTextColor(255, 255, 0);

  int lastX, lastY;
  for(int X = XBORDER;X < (320 - WIDTH); X = X + WIDTH + OFFSET){
    lcd.draw(smile, X, YBORDER, WIDTH, HEIGHT);
    lastX = X;
    delay(mydelay);
  };
  for(int Y = HEIGHT + OFFSET;Y < (240 - HEIGHT); Y = Y + HEIGHT + OFFSET){
    lcd.draw(smile, lastX, Y, WIDTH, HEIGHT);
    lastY = Y;
    delay(mydelay);
  };
  for(int X = lastX - WIDTH - OFFSET;X >= 0; X = X - WIDTH - OFFSET){
    lcd.draw(smile, X, lastY, WIDTH, HEIGHT);
    lastX = X;
    delay(mydelay);
  };
  for(int Y = lastY - HEIGHT - OFFSET;Y >=YBORDER; Y = Y - HEIGHT - OFFSET){
    lcd.draw(smile, lastX, Y, WIDTH, HEIGHT);
    lastY = Y;
    delay(mydelay);
  };
  int curX = XBORDER + WIDTH + OFFSET;
  int curY = 6;
  lcd.setTextColor(255, 255, 255);
  lcd.setCursor(curX, curY);
  lcd.setFont(FONT_SIZE_SMALL);
  lcd.print("Hello, world!");
  curY++;
  delay(mydelay);

  lcd.setTextColor(255, 0, 255);
  lcd.setCursor(curX, curY);
  lcd.setFont(FONT_SIZE_MEDIUM);
  lcd.print("Hello, world!");
  curY++;
  curY++;
  delay(mydelay);

  lcd.setTextColor(255, 0, 0);
  lcd.setCursor(curX, curY);
  lcd.setFont(FONT_SIZE_SMALL);
  lcd.printLong(1234567890);
  curY++;
  delay(mydelay);

  lcd.setTextColor(0, 255, 0);
  lcd.setCursor(curX, curY);
  lcd.setFont(FONT_SIZE_MEDIUM);
  lcd.printLong(1234567890);
  curY++;
  curY++;
  delay(mydelay);

  lcd.setTextColor(0, 0, 255);
  lcd.setCursor(curX, curY);
  lcd.setFont(FONT_SIZE_LARGE);
  lcd.printLong(12345678);
  curY++;
  curY++;
  delay(mydelay);

  lcd.setTextColor(0, 255, 255);
  lcd.setCursor(curX, curY);
  lcd.setFont(FONT_SIZE_XLARGE);
  lcd.printLong(12345678);

  delay(5000);
  lcd.backlight(false);
  delay(mydelay);
  mydelay = 0;
};

Congrats XD So, what do you think whats he problem with the other board ?

Did you also had a look here ? http://forum.arduino.cc/index.php?topic=181679.0