ILI9341 TFT Touch Screen
For this project We used a 2.4" 240 x 320 TFT Touch screen with SD Card holder. The first phase of the is project is to try out the colour display. We can use a 3.3V 8MHz Arduino Pro Mini to drive the display.
Pins 1 - 5 are for the touch screen and we will add these connections to this page once I have tried it out.
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 |
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, we 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | /*************************************************** This is our GFX example for the Adafruit ILI9341 Breakout and Shield 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); |
I have used Pin 4 for SD_CS (Chip Select). This is configurable in the code
ILI9341 | Pin Name | Arduino |
---|---|---|
1 | SD_CS | 4 |
2 | SD_MOSI | 11 |
3 | SD_MISO | 12 |
4 | SD_SCK | 13 |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | /*************************************************** This is our Bitmap drawing example for the Adafruit ILI9341 Breakout and Shield 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); } |