ILI9341 TFT Touch Screen

From ProjectPages
Jump to: navigation, search

The Board

Connecting Up The TFT

For this project I used a 2.4" 240 x 320 TFT Touch screen with SD Card holder the I got on Ebay from this seller for £2.99. The first phase of the is project is to try out the colour display. I used a 3.3V 8MHz Arduino Pro Mini to drive the display - also sourced very cheaply on Ebay. I chose this board because, although the seller of this display claims that it will work at both 5v and 3.3v, the majority of these display will not. So, rather than have to use level shifters of resistor dividers, I made the whole project run at 3.3v.

Pin Connections

Pins 1 - 5 are for the touch screen and I will add these connections to this page once I have tried it out.

Pin Connections
ILI9341 Pin Name Arduino Mega 2560
1 T_IRQ
2 T_DO
3 T_DIN
4 T_CS
5 T_CLK
6 SDO(MISO) 12 50
7 LED VCC VCC
8 SCK 13 52
9 SDI(MOSI) 11 51
10 D/C 9 46
11 RESET 8 48
12 CS 10 53
13 GND GND GND
14 VCC VCC VCC

Code

First you need to download and install these two libraries from ADAFruit:

Then, in the Arduino IDE, open the 'graphicstest' example, which is in the ILI9341 library examples folder. The code says that the reset is optional, but, as before, I had to enable it to get my display to work.

So, add line 22 which defines the RESET Pin number and edit line 27 to add the RESET Pin parameter.

/***************************************************
  This is our GFX example for the Adafruit ILI9341 Breakout and Shield
  ----> http://www.adafruit.com/products/1651

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/


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

// For the Adafruit shield, these are the default.
#define TFT_RST 8
#define TFT_DC 9
#define TFT_CS 10

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

Video Demonstration

Adding SD Card Reading

Pin Connections

I have used Pin 4 for SD_CS (Chip Select). This is configurable in the code

Pin Connections
ILI9341 Pin Name Arduino
1 SD_CS 4
2 SD_MOSI 11
3 SD_MISO 12
4 SD_SCK 13

The Card

Code

You must complete the first section so you will have downloaded and installed these two libraries from ADAFruit:

Then, in the Arduino IDE, open the 'spitftbitmap' example, which is in the ILI9341 library examples folder. The code says that the reset is optional, but, as above, I had to enable it to get my display to work.

So, add line 22 which defines the RESET Pin number and edit line 27 to add the RESET Pin parameter. Then change line 46 to match the name of your bitmap file.

/***************************************************
  This is our Bitmap drawing example for the Adafruit ILI9341 Breakout and Shield
  ----> http://www.adafruit.com/products/1651

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/


#include <Adafruit_GFX.h>    // Core graphics library
#include "Adafruit_ILI9341.h" // Hardware-specific library
#include <SPI.h>
#include <SD.h>

// TFT display and SD card will share the hardware SPI interface.
// Hardware SPI pins are specific to the Arduino board type and
// cannot be remapped to alternate pins.  For Arduino Uno,
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.

#define TFT_RST 8
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

#define SD_CS 4

void setup(void) {
  Serial.begin(9600);

  tft.begin();
  tft.fillScreen(ILI9341_BLUE);
  
  Serial.print("Initializing SD card...");
  if (!SD.begin(SD_CS)) {
    Serial.println("failed!");
  }
  Serial.println("OK!");

  bmpDraw("i.bmp", 0, 0);
}

Serial Monitor Output

Serial Monitor Output

Video Demonstration

Links