Cheap TFT 2.2 Inch Display on Arduino (ILI9340C or ILI9341)

251K10482

Intro: Cheap TFT 2.2 Inch Display on Arduino (ILI9340C or ILI9341)

I ordered a 240 x 320 pixel 2.2 inch TFT LCD display off of ebay for £3.86 which is dirt cheap compared to similar displays from some of the western companies. The only problem was that there wasn't a guide to how to get it working! When I figured it out I thought I'd make an Instructable for anyone with the same issues. It actually turned out to be quite simple. This tutorial doesn't show you how to use the SD card functionality.

The Ethics:
A couple of users have complained that I am using adafruit libraries and I am not supporting adafruit. I'd like to point out that adafruit provide their libraries under The MIT License, which amoungst other things says:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute...

You can look up the entire license if you are interested.

I understand this to mean that adafruit are perfectly happy for their code to be edited to drive cheap chinese displays, and there is no point going to the effort of writing my own code to drive it. If you have an issue with the ethics, I'd like to point out that my behavior is perfectly legal so please keep your rant elsewhere. Thankyou.

STEP 1: Parts List

2.2" Serial 240x320 SPI TFT LCD Module Display ILI9340C

An Arduino compatible microcontroler - I use a Breadboard Arduino

Something to convert to 3.3V logic - I power my breadboard Arduino with 3.3V

My setup is a little like this although I ordered my components separately.

STEP 2: Install the Correct Libraries

Luckily for us, Adafruit have a very similar display that they have written libraries for. I have the display which is powered by the ILI9340 driver so I installed that library so I assume if you have a display with the ILI9341 driver it works exactly the same with the other library that I linked. I haven't seen any other drivers used but if you do, I recommend searching the Adafruit libraries on github.

You also need to install the Adafruit GFX library regardless of what driver the display uses.

Instructions on how you do this are on the github pages linked.

https://github.com/adafruit/Adafruit-GFX-Library

https://github.com/adafruit/Adafruit_ILI9340

https://github.com/adafruit/Adafruit_ILI9341

EDIT:

My arduino IDE updated and it didn't like having hyphens/underscores in folder names of libraries. If you are getting an error message complaining about these characters try removing them from the folder names (but not the names of the .h and .cpp files).

STEP 3: Wire It Up and Upload the Example Sketch

There is an example sketch included with the ILI9340/1 library called graphics test. You have to wire the display up in accordance to the pin definitions there.

Originally When I wrote this Instructable I wrote:

I'd like to emphasize that this display uses 3.3V logic, and will not work if you use 5V. This is information that I found on some forum somewhere and using it I got my display to work

However:
I now have multiple of these displays from different sellers (and perhaps different factories). I have noticed that some of them also behave using 5V logic.

As labeled on my display module, the connections are

SCK - Arduino Pin 13
SDO(MISO) - Arduino Pin 12
SDI(MOSI) - Arduino Pin 11
CS - Arduino Pin 10
D/C - Arduino Pin 9
RESET - Arduino Pin 8
LED - 3.3V / 5V
VCC - 3.3V / 5V
GND - GND

Upload the example sketch and give it a go, the sketch shows you well how to control the display.

You may have to fiddle with the voltages for your particular model. There are various options you have here -potential dividers on each pin, level shifters, or simply powering your arduino with a 3.3v supply (this is perhaps the hackiest and can be slightly temperamental). See the comments for details.

Also, there is information about how to use the library on adafruits website.

A datasheet can be found here

You may do what you like with this Instructable, without having to contact me first.

65 Comments

Hello, I worked with the 2.2 inch SPI LCD again.

I connected the 3,3V LCD with an Arduino Uno R3 5V. I used a resistor divider as a levelshifter.

LCD 3.3V #

|

Arduino Pins 5V #-----|4k7|----#----|10k|-----# GND

I am also planning to try it, not yet tried it, Actually my CC2500 projects use the scheme. I was just wondering why are people not using the same. Thank you for the confidence

Thank you for this! I remember trying this origionally and ended up using a 3.3v source instead because for some reason it didn't work. Clearly I made some kind of mistake.

I am using the 2.2 TFT w/ILI 9340C. I got it to work just fine but I can only do text character. How can I display a variable, like a sensor value?

#include "SPI.h"

#include "Adafruit_GFX.h"

#include "Adafruit_ILI9340.h"

#if defined(__SAM3X8E__)

#undef __FlashStringHelper::F(string_literal)

#define F(string_literal) string_literal

#endif

// These are the pins used for the UNO

// for Due/Mega/Leonardo use the hardware SPI pins (which are different)

#define _sclk 13

#define _miso 12

#define _mosi 11

#define _cs 10

#define _dc 9

#define _rst 8

// Using software SPI is really not suggested, its incredibly slow

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

// Use hardware SPI

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

int sensorPin = A0;

int sensorValue ;

char sensorPrintout[4];

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

while (!Serial);

Serial.println("Adafruit 2.2\" SPI TFT Test!");

tft.begin();

Serial.print(F("Text "));

Serial.println(testText());

delay(3000);

}

void loop() {

// put your main code here, to run repeatedly:

String sensorValue = String(analogRead(sensorPin));

sensorValue.toCharArray(sensorPrintout, 4);

}

unsigned long testText() {

tft.fillScreen(ILI9340_WHITE);

unsigned long start = micros();

tft.setCursor(1, 2);

tft.setTextColor(ILI9340_BLACK); tft.setTextSize(3);

tft.println("LOVE YOU LANA");

tft.setCursor(120, 2);

tft.setTextColor(ILI9340_RED); tft.setTextSize(2);

tft.println(sensorPrintout);

return micros() - start;

}

i havent tried this and im not entirely sure its the issue... that said school and experience has me thinking its a variable type issue. try something like tft.println(String(your_var_name_here));

WHITE SCREEN

Put a 100ohm resistor in series on the
power supply to the display. You need to limit the current. Make sure
you use the voltage dividers to the data pins.

TO USE HARDWARE SPI

The include file calls for

// Use hardware SPI (you have to add the TFT_RST here.)

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

SDI - 11

SDO -12

SCK -13

You can move the others around

My screen shows blank white, but if you look hard enough, you can see lines of color where the graphics test is supposed to be happening. Do you have a fix for this?

Put a 100ohm resistor in series on the power supply to the display. You need to limit the current. Make sure you use the voltage dividers to the data pins.

I also could not get the SPI mode to work until I defined the damn reset. I had to dig thru the library to figure that out.

// Use hardware SPI
TFT_ILI93XX tft = TFT_ILI93XX(TFT_CS, TFT_DC, TFT_RST); //reset has to be defined with library.

It should work with this plug and play shield don't you think?

The ILI9341 is supported in Great Cow Basic which compiles for mega328..ie uno

Hi.

I've found a cct. diagram of this unit. Seems the little jumper on the back of the board should be shorted with a blob of solder for 3v3 operation. As it's an LDO regulator, you might just get away with it...
( One of the sellers has a file 2.25.zip. The schematic is in that.)

-Andy

Great man!! you got the answer! Im powering with 3v3 from arduino and jumpered the J1 ! works excelent!!

Thanks for that one, your post got my attention. Then i did hook up vcc to 5 volt. Voila its working.

The Adafruit GFX library has been tested to work on current versions of Windows. You are setting it up incorrectly.

You wired it up incorrectly and there is a reset pin on the model he is referring to.

I still have not get to work the TFT, I have always a white Screen...

My connections are:

All connections are wiring with a voltage divider (less VCC & LED):

arduino pin (5V signals) ----1k----display pin (Approx. 3.3V) ----1k8----GND

TFT----------Arduino UNO:

VCC---------3.3V

GND--------GND

CS----------PIN10

RESET -----PIN8

D/C---------PIN9

SDI(MOSI)-PIN11

SCK---------PIN13

LED---------47ohms----3.3V

SDO(MISO)-PIN12

I'm starting to think is a current issue... Any Suggestions? Or maybe another library?

my pinout is starting at pin1 vcc,gnd,gnd,nc,nc,led,clk,sdi,rs,rst.cs, i have no clue as to what clk rs would get connected to ?here are the specks on the ldc :

Size: 2.2 inch
Module Size: 67x40x4 mm
Active Area: 47.5x36.5 mm
Resolution: 240 x 320 (RGB)
Interface: 4-Wire SPI
Color Depth: 262K/65K
LED Numbers: 4 LEDs
Driver IC: ILI9340C

Just need 5 IO port (analog SPI), or direct hardware SPI (fast), you can drive the input voltage support 5V/3.3V, ILI9341 drive
Suitable for beginners who are new to touch the color screen, LCD lovers who pursuit display effect and the microcontroller enthusiasts learners
Support serial SPI mode
It has PCB backplane with power IC, SD card socket
Need 4 IOs from your MCU only
Dot Matrix: QVGA 240*320 Dots
Interface 4-Wire SPI

More Comments