2.2 TFT SPI 240x320 white screen

Hello guys, i need help to make this display work. I tried everything but still nothing.

This is the display model
http://www.ebay.com/itm/2-2-inch-2-2-SPI-TFT-LCD-Display-module-240x320-ILI9341-51-AVR-STM32-ARM-PIC-/200939222521

I'm using Arduino UNO r3, library TFTv2 (ili9341).
This is my configuration:

MISO -Not connected
LED -20 ohms direct to 3.3v
ls SCK -Pin 13
ls MOSI -Pin 11
ls D/C -Pin 6
ls RESET -Pin 4
ls CS -Pin 5
GND -GND
VCC -3.3v
(ls: level shift 560, 1k Ohms)

If you look it's just a white screen, but if you look closer from a side you can see slightly senseless colored lines, actually the colors used in the example that i'm testing (drawCircle).
What's the reason of this behavior?
I used the CD4050BE but same result

Here's a video that i've just uploaded

ili9341.zip (593 KB)

You should have something like

void setup(void) {
  Serial.begin(9600);
  Serial.println(F("TFT LCD test"));



  tft.reset();

  uint16_t identifier = tft.readID();
    Serial.print(F("LCD driver chip: "));
    Serial.println(identifier, HEX);

If you don't, there are a number of examples that use it or something similar. Just my op, but run one of the sketches that identify the chip and make sure it describes the one that is supposed to be there. One in four displays I bought was broken and wouldn't return the right value no matter what you did. For the others, it would have trouble finding the identifier if there was a secondary problem with which pins were defined for functions.

There's a lot of different manufacturers that produce chips with similar capabilities but different commands and memory layouts. Seems like the eBay sellers are pretty loose in how they describe and support their devices. I wouldn't believe I actually had a ILI9341 chip until I saw it identified as such with the above code snippet.

what libraries should i include in that code? Sorry if i can't just identify, I'm still a little newbie

There are several good ones, I'm not sure which ones will have the right header but some good ones to google/install are
TFT-Shield-Example-Code-master
TFTSPS_07781
TFTSPS_61505
AdaLGDP4535TFTLCD
Adafruit_TFTLCD
UTFT

There's a lot of cross pollination that goes on. Examples may take the form of a different pin definition then run a demo from Adafruit.

http://www.rinkydinkelectronics.com/library.php
Is a great resource with some nice examples/demos.

There may be a demo on Youtube specific to your display. Usually they will have a link to the library and example code on github or some other repository. It may be worth a look there to see if someone has done some of the leg work.

This is the library that i'm using:

After a quick reading i found this:

INT8U TFT::readID(void)
{
    INT8U i=0;
    INT8U data[3] ;
    INT8U ID[3] = {0x00, 0x93, 0x41};
    INT8U ToF=1;
    for(i=0;i<3;i++)
    {
        data[i]=Read_Register(0xd3,i+1);
        if(data[i] != ID[i])
        {
            ToF=0;
        }
    }
    if(!ToF)                                                            /* data!=ID                     */
    {
        Serial.print("Read TFT ID failed, ID should be 0x09341, but read ID = 0x");
        for(i=0;i<3;i++)
        {
            Serial.print(data[i],HEX);
        }
        Serial.println();
    }
    return ToF;
}

That should identify my tft chip right? But i don't know how to call it.

Try this:

Yes, it does have some problems in my inexperienced experience. :slight_smile: It doesn't initialize the serial port.

I'll include a sketch by BUHOSOFT with the only change being DEBUG is enabled. It will probably crash badly on your system because of different expectations of screen size let alone colors. It should show your chip on the serial monitor i.e. open Tools>Serial Monitor or M You should have newline or carriage return set for it to work properly.

You will have to place all the #include files in your library if they aren't there already. Pretty easy to tell, you get an error and the compiler bails out.

I didn't notice a '#include SPI' but I think it is contained within the Adafruit libraries. I could be mistaken but I think Adafruit sacrificed some speed for compatibility by moving to SPI so things would work across a wider selection of displays and Arduino platforms.

// This sketch has been Refurbished by BUHOSOFT
// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.
#define DEBUG
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
// For the Arduino Uno, Duemilanove, Diecimila, etc.:
//   D0 connects to digital pin 8  (Notice these are
//   D1 connects to digital pin 9   NOT in order!)
//   D2 connects to digital pin 2
//   D3 connects to digital pin 3
//   D4 connects to digital pin 4
//   D5 connects to digital pin 5
//   D6 connects to digital pin 6
//   D7 connects to digital pin 7
// For the Arduino Mega, use digital pins 22 through 29
// (on the 2-row header at the end of the board).

// Assign human-readable names to some common 16-bit color values:
#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;

void setup(void) {
#ifdef DEBUG
  Serial.begin(9600);
  Serial.println(F("Rotation Test!"));
#endif // DEBUG
  tft.reset();

  uint16_t identifier = tft.readID();

if(identifier == 0x9325) {
#ifdef DEBUG
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {

    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x7575) {

    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {

    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {

    Serial.println(F("Found HX8357D LCD driver"));
    
#endif // DEBUG
    } else {
    #ifdef DEBUG
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.print(F("I try use ILI9341 LCD driver "));
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    #endif // DEBUG
    identifier = 0x9341;
  }

  tft.begin(identifier);

  tft.fillScreen(BLACK);
#ifdef DEBUG
  Serial.println(F("This is a test of the rotation capabilities of the TFT library!"));
  Serial.println(F("Press <SEND> (or type a character) to advance"));
#endif // DEBUG
}

void loop(void) {
  #ifndef DEBUG
  rotatePixel();
  #endif // DEBUG
  rotateLine();
  rotateFastline();
  rotateDrawrect();
  rotateFillrect();
  rotateDrawcircle();
  rotateFillcircle();
  rotateText();
}

void rotateText() {
  for (uint8_t i=0; i<4; i++) {
    tft.fillScreen(BLACK);
#ifdef DEBUG
    Serial.println(tft.getRotation(), DEC);
#endif // DEBUG
    tft.setCursor(0, 30);
    tft.setTextColor(RED);
    tft.setTextSize(1);
    tft.println("Hello World!");
    tft.setTextColor(YELLOW);
    tft.setTextSize(2);
    tft.println("Hello World!");
    tft.setTextColor(GREEN);
    tft.setTextSize(3);
    tft.println("Hello World!");
    tft.setTextColor(BLUE);
    tft.setTextSize(4);
    tft.print(1234.567);
#ifdef DEBUG
    while (!Serial.available());
    Serial.read();  Serial.read();  Serial.read();
#else
    delay(500);
#endif // DEBUG
    tft.setRotation(tft.getRotation()+1);
  }
}

void rotateFillcircle(void) {
  for (uint8_t i=0; i<4; i++) {
    tft.fillScreen(BLACK);
    #ifdef DEBUG
    Serial.println(tft.getRotation(), DEC);
    #endif // DEBUG
    tft.fillCircle(10, 30, 10, YELLOW);

#ifdef DEBUG
    while (!Serial.available());
    Serial.read();  Serial.read();  Serial.read();
#else
    delay(500);
#endif // DEBUG

    tft.setRotation(tft.getRotation()+1);
  }
}

void rotateDrawcircle(void) {
  for (uint8_t i=0; i<4; i++) {
    tft.fillScreen(BLACK);
    #ifdef DEBUG
    Serial.println(tft.getRotation(), DEC);
    #endif // DEBUG
    tft.drawCircle(10, 30, 10, YELLOW);

#ifdef DEBUG
    while (!Serial.available());
    Serial.read();  Serial.read();  Serial.read();
#else
    delay(500);
#endif // DEBUG

    tft.setRotation(tft.getRotation()+1);
  }
}

void rotateFillrect(void) {
  for (uint8_t i=0; i<4; i++) {
    tft.fillScreen(BLACK);
    #ifdef DEBUG
    Serial.println(tft.getRotation(), DEC);
    #endif // DEBUG
    tft.fillRect(10, 20, 10, 20, GREEN);

#ifdef DEBUG
    while (!Serial.available());
    Serial.read();  Serial.read();  Serial.read();
#else
    delay(500);
#endif // DEBUG

    tft.setRotation(tft.getRotation()+1);
  }
}

void rotateDrawrect(void) {
  for (uint8_t i=0; i<4; i++) {
    tft.fillScreen(BLACK);
    #ifdef DEBUG
    Serial.println(tft.getRotation(), DEC);
    #endif // DEBUG
    tft.drawRect(10, 20, 10, 20, GREEN);

#ifdef DEBUG
    while (!Serial.available());
    Serial.read();  Serial.read();  Serial.read();
#else
    delay(500);
#endif // DEBUG

    tft.setRotation(tft.getRotation()+1);
  }
}

void rotateFastline(void) {
  for (uint8_t i=0; i<4; i++) {
    tft.fillScreen(BLACK);
    #ifdef DEBUG
    Serial.println(tft.getRotation(), DEC);
    #endif // DEBUG
    tft.drawFastHLine(0, 20, tft.width(), RED);
    tft.drawFastVLine(20, 0, tft.height(), BLUE);

#ifdef DEBUG
    while (!Serial.available());
    Serial.read();  Serial.read();  Serial.read();
#else
    delay(500);
#endif // DEBUG

    tft.setRotation(tft.getRotation()+1);
  }
}

void rotateLine(void) {
  for (uint8_t i=0; i<4; i++) {
    tft.fillScreen(BLACK);
    #ifdef DEBUG
    Serial.println(tft.getRotation(), DEC);
    #endif // DEBUG
    tft.drawLine(tft.width()/2, tft.height()/2, 0, 0, RED);
#ifdef DEBUG
    while (!Serial.available());
    Serial.read();  Serial.read();  Serial.read();
#else
    delay(500);
#endif // DEBUG

    tft.setRotation(tft.getRotation()+1);
  }
}

void rotatePixel(void) {
  for (uint8_t i=0; i<4; i++) {
    tft.fillScreen(BLACK);
    #ifdef DEBUG
    Serial.println(tft.getRotation(), DEC);
    #endif // DEBUG
    tft.drawPixel(10,20, RED);
#ifdef DEBUG
    while (!Serial.available());
    Serial.read();  Serial.read();  Serial.read();
#else
    delay(500);
#endif // DEBUG

    tft.setRotation(tft.getRotation()+1);
  }
}

what's the configuration for the pins to make that code works?
My display only have: vcc, gnd, cs, rst, d/c, mosi, sck, led, miso.

I don't have the same display to test. I did look on your eBay link and your device does have some of the same signals. I'd guess other then the reset and maybe CS the sketch connections aren't used because you are using SPI rather then one of the parallel transfer modes. Anyway, from the sketch the pins are as attached if I didn't make a transcription error and attached it right.

There are quite a few Youtube videos with that particular device. Most of them are low resolution but you may be able to pick out what pins they are using or contact the author. This link is one of many
ili9341 video

tft connect.JPG

i've used plenty of those displays, always with a CD4050 as a level converter because I initially connected up a couple without it and fried them. I use a 39ohm resistor off the 5V line for the LED backlight. I don't use resistor dividers.

There's a 5V regulator on the back of the PCB so you can feed them 5V for Vcc. If you feed them 3.3V there's a pair of solder pads you connect at the regulator. I've always just used 5V for Vcc.

For the libraries, the two I use for those displays are on GitHub from Adafruit:

#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

#define _sclk 13
#define _miso 12
#define _mosi 11
#define _cs 10
#define _dc 9
#define _rst 8

Adafruit_ILI9341 tft = Adafruit_ILI9341(_cs, _dc, _rst);

void setup() {
tft.begin();
  tft.setRotation(1);
  tft.fillScreen(ILI9341_BLACK);
  tft.setCursor(40, 110);
  tft.setTextSize(2);
  tft.print(F("Hello World"));
}

Obviously with the 4050 in the circuit, the Arduino pins don't actually connect to the TFT. Someone else posted circuit wiring in the forum they use. It looks the same as what I use except for the 3.3V, I use 5V (but 3.3 for the 4050).

I've also used a lot of the 1.8" TFT displays that look like the one you linked to. I found those are 5V tolerant and that saves having to use a level converter.