Skip to content
Johan Cronje edited this page Aug 26, 2014 · 26 revisions

TFT_22_ILI9225

Introduction

This is a library for the ILI9225 TFT display products, forked from the screen_4D_22_library library.

This library works with the ILI9225 based 2.2" 176x220 TFT LCD shields commonly found on eBay. Note that there is a commonly available 2.2" 240x320 TFT module very similar in appearance but using the ILI9341 driver.

Front Back

Installation

  • Click the Download ZIP button on the right to download TFT_22_ILI9225-master.zip
  • Extract the ZIP file to the library folder your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if it's your first library.
  • Rename the uncompressed folder from TFT_22_ILI9225-master to TFT_22_ILI9225
  • Restart the Arduino IDE

Connecting TFT to an Arduino

TFT Pin TFT Pin Label Description Arduino Pin (Uno) Arduino Pin Label
1 VCC +5V Supply
2 GND Ground
3 GND Ground
4 NC No Connection
5 NC No Connection
6 LED LED Backlight 3 Can be any open digital pin or directly to +5V
7 CLK CLK 13 SCK
8 SDI SDI 11 MOSI
9 RS RS 9 Can be any open digital pin
10 RST Reset 8 Can be any open digital pin
11 CS CS 10 SS

Method Reference

begin
		/// Initialization
		void begin(void);
clear
		/// Clear the screen
		void clear(void); 
invert
		/// Invert screen
		/// @param	flag true to invert, false for normal screen
		void invert(boolean flag);
setBacklight
		/// Switch backlight on or off
		/// @param	flag true=on, false=off
		void setBacklight(boolean flag); 
setDisplay
		/// Switch display on or off
		/// @param	flag true=on, false=off
		void setDisplay(boolean flag);  
setOrientation
		/// Set orientation
		/// @param	orientation orientation, 0=portrait, 1=right rotated landscape, 2=reverse portrait, 3=left rotated landscape
		void setOrientation(uint8_t orientation);  
getOrientation
		/// Get orientation
		/// @return	orientation orientation, 0=portrait, 1=right rotated landscape, 2=reverse portrait, 3=left rotated landscape
		uint8_t getOrientation(void); 
fontX
		/// Font size, x-axis
		/// @return	horizontal size of current font, in pixels
		uint8_t fontX(void);
fontY
		/// Font size, y-axis
		/// @return	vertical size of current font, in pixels
		uint8_t fontY(void); 
maxX
		/// Screen size, x-axis
		/// @return	horizontal size of the screen, in pixels
		/// @note	240 means 240 pixels and thus 0..239 coordinates (decimal)
		uint16_t maxX(void);
maxY
		/// Screen size, y-axis
		/// @return	vertical size of the screen, in pixels
		/// @note	220 means 220 pixels and thus 0..219 coordinates (decimal)
		uint16_t maxY(void);
drawCircle
		/// Draw circle
		/// @param	x0 center, point coordinate, x-axis
		/// @param	y0 center, point coordinate, y-axis
		/// @param	radius radius
		/// @param	color 16-bit color
		void drawCircle(uint16_t x0, uint16_t y0, uint16_t radius, uint16_t color);  
fillCircle
		/// Draw solid circle
		/// @param	x0 center, point coordinate, x-axis
		/// @param	y0 center, point coordinate, y-axis
		/// @param	radius radius
		/// @param	color 16-bit color
		void fillCircle(uint8_t x0, uint8_t y0, uint8_t radius, uint16_t color); 
setBackgroundColor
		/// Set background color
		/// @param	color background color, default=black
		void setBackgroundColor(uint16_t color = COLOR_BLACK);  
drawLine
		/// Draw line, rectangle coordinates
		/// @param	x1 top left coordinate, x-axis
		/// @param	y1 top left coordinate, y-axis
		/// @param	x2 bottom right coordinate, x-axis
		/// @param	y2 bottom right coordinate, y-axis
		/// @param	color 16-bit color
		void drawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 
drawRectangle
		/// Draw rectangle, rectangle coordinates
		/// @param	x1 top left coordinate, x-axis
		/// @param	y1 top left coordinate, y-axis
		/// @param	x2 bottom right coordinate, x-axis
		/// @param	y2 bottom right coordinate, y-axis
		/// @param	color 16-bit color
		void drawRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color); 
fillRectangle
		/// Draw solid rectangle, rectangle coordinates
		/// @param	x1 top left coordinate, x-axis
		/// @param	y1 top left coordinate, y-axis
		/// @param	x2 bottom right coordinate, x-axis
		/// @param	y2 bottom right coordinate, y-axis
		/// @param	color 16-bit color
		void fillRectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
drawPixel
		/// Draw pixel
		/// @param	x1 point coordinate, x-axis
		/// @param	y1 point coordinate, y-axis
		/// @param	color 16-bit color
		void drawPixel(uint16_t x1, uint16_t y1, uint16_t color);  
drawText
		/// Draw ASCII Text (pixel coordinates)
		/// @param	x point coordinate, x-axis
		/// @param	y point coordinate, y-axis
		/// @param	s text string
		/// @param	color 16-bit color, default=white
		void drawText(uint16_t x, uint16_t y, String  s, uint16_t color = COLOR_WHITE);
setColor
		/// Calculate 16-bit color from 8-bit Red-Green-Blue components
		/// @param	red red component, 0x00..0xff
		/// @param	green green component, 0x00..0xff
		/// @param	blue blue component, 0x00..0xff
		/// @return	16-bit color
		uint16_t setColor(uint8_t red, uint8_t green, uint8_t blue);
splitColor
		/// Calculate 8-bit Red-Green-Blue components from 16-bit color
		/// @param	rgb 16-bit color
		/// @param	red red component, 0x00..0xff
		/// @param	green green component, 0x00..0xff
		/// @param	blue blue component, 0x00..0xff
		void splitColor(uint16_t rgb, uint8_t &red, uint8_t &green, uint8_t &blue);
drawTriangle
		/// Draw triangle, triangle coordinates
		/// @param	x1 corner 1 coordinate, x-axis
		/// @param	y1 corner 1 coordinate, y-axis
		/// @param	x2 corner 2 coordinate, x-axis
		/// @param	y2 corner 2 coordinate, y-axis
		/// @param	x3 corner 3 coordinate, x-axis
		/// @param	y3 corner 3 coordinate, y-axis
		/// @param	color 16-bit color
		void drawTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color); 
fillTriangle
		/// Draw solid triangle, triangle coordinates
		/// @param	x1 corner 1 coordinate, x-axis
		/// @param	y1 corner 1 coordinate, y-axis
		/// @param	x2 corner 2 coordinate, x-axis
		/// @param	y2 corner 2 coordinate, y-axis
		/// @param	x3 corner 3 coordinate, x-axis
		/// @param	y3 corner 3 coordinate, y-axis
		/// @param	color 16-bit color
		void fillTriangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t x3, uint16_t y3, uint16_t color);
setFont
		/// Set current font
		/// @param	font Font name
		void setFont(uint8_t* font);
drawChar
		/// Draw single character (pixel coordinates)
		/// @param	x point coordinate, x-axis
		/// @param	y point coordinate, y-axis
		/// @param	ch ASCII character
		/// @param	color 16-bit color, default=white
		uint16_t drawChar(uint16_t x, uint16_t y, uint16_t ch, uint16_t color = COLOR_WHITE);

Standard Fonts

Font Name Width (pixels) Height (pixels) Offset (start char) Number of chars
Terminal6x8 6 8 32 96
Terminal11x16 11 16 32 96
Terminal12x16 12 16 32 96
Trebuchet_MS16x21 16 21 46 13

Font can be added with GLCD Font Creator (Windows only unfortunately)

  • Export the C font file from GLCD Font Creator & save it to your sketch directory.
  • Change the datatype to:
    const uint8_t FontName[] PROGMEM = {
  • Add 4 bytes between the definition & first character definition data line (width, height, offset, characters):
    const uint8_t FontName[] PROGMEM = {
        0x06, 0x08, 0x20, 0x60,  // width = 6, height = 8, offset = 32 (space), characters = 96 (32 - 127)***
        0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // Code for char  
  • Add a external reference in your Arduino sketch pointing to the font:
    extern uint8_t FontName[];

Color Reference

Colors
Clone this wiki locally