Demo Sketches for TFT-LCD


I really like this small 2.2" TFT-LCD that can be purchased very inexpensively from sites on eBay.  I started testing using a harness of jumper wires to connect an Arduino to the LCD but most of the photos are the result of testing interface boards designed by Wayne Chu.

The photos below are thumbnails; click on them to get the Hi-Res version.

I know of three Arduino libraries for the ILI9341:
The Adafruit library has only one font, 5x7, but it can be displayed in almost any size.  The larger sizes look rather blocky.  But that does make it easier to write a program.  It is the only library that supports println() where the cursor advances to the next line automatically.  It also has a feature of getting bitmaps from an SD card and displaying them on the TFT-LCD.
I found an instructables post that adds improved fonts to the Adafruit library.  .
Paul Stoffregen has written a highly optimized version for the Teensy 3.1.  And posted an Oshpark interface board.   Someone else forked that to add support for vertical scroll.  Here is a 18 second video.

The Universal uC Color Graphics Library has, by far, the largest collection of very attractive fonts.  Go to the Wiki at the website for an index.  But they require a lot of memory especially if you want to use more than one font in a sketch.  At the bottom of this page is a little subroutine that can be used in place of  println()

The UTFT was designed so that it could be used by almost any graphic display known.  But doing so makes the software large and slow.  It does have a few unique features and is worth a look.  Be sure to get the latest version for compatibility with Arduino 1.6.x  As of this time it is not compatible with SAMD21 used in Arduino ZERO (and M0).

If you own an Arduino Due check out this library.  Some of its features will work on AVR but not the high speed DMA.

There is another graphics library that supports ILI9341 called µGFX  They claim that "uGFX runs out of the box on Arduino. It also provides co-operative multi-tasking capabilities to Arduino."  It seems to be very complex; not for beginners.  If anyone knows of an example please let me know.

In summary I would say the Adafruit library is the best choice in most cases.  It is fast, flexible, and easy on memory requirements.

A note about the Universal uC Color Graphics Library:  I tested it on ten different displays and it worked on only seven of them.  Even though two displayed demos based on Adafruit library and demos based on UTFT library (one was completely defective).

This is the first sketch I wrote for the TFT-LCD.  It uses the Adafruit library.  This library has only one font but you can display it in different sizes.  This sketch is called ILI9341_text.  The sketch size is 10 K.
The Adafruit library has an example sketch that takes a bitmap file off an SD card and puts it on the TFT-LCD.  I expanded that a little to display a couple of dozen bitmap files.  I call the sketch TFT_Pro_Slide_Show.  It is 23 K

Copy the bitmaps from the folder in the ZIP file into a SD card.

Here is an example of some fonts in the Ucglib.h library.  The flash on the camera tends to wash out the color of the TFT LCD display.  The sketch is named TFT_Fonts1.  The sketch size is 65 K


The TFT-Pro and the TFT-ESP8266 boards have a MCP79412 RTC chip on board.  Here is a demo program to display time and date using that RTC.  The sketch is called TFT_Pro_RTC.  It uses the Adafruit library.  It is 14 K in size.

This is another sketch demonstrating some of the fonts in the Ucglib.h library.  The sketch is TFT_Fonts3  The sketch size is 75 K.

In this demo you push a button on the board and the colored block on the LCD will turn from red to green and the text will change from OFF to ON.  And the reverse, of course.  The sketch uses the Ucglib.h library and its size is 30 K.  It is called TFT_Pro_Pushbutton.

The on-board user push buttons switches will not be on newer versions of the board but the user can add his own on a breadboard.

These are some of the included fonts in the UTFT library.  They are called BigFont, SmallFont and SevenSegNumFont.

This sketch is named UTFT_ViewFont and is 32 K.

Here are a couple of Arial fonts in the library.

The sketch is called UTFT_Fonts4 and is 37 K in size.

The UTFT library doesn't have too many default fonts and they are mostly rather small.  The author does have another webpage with about four dozen other fonts that can be added to a sketch folder.

This sketch is 47 K in size.  It's called UTFT_FontsNew.

With the UTFT library you have the ability to print the text at any angle.  It's cute but I don't think that would be useful very often in real life.

This sketch is 32 K and is called UTFT_Textrotation_Demo

Here the temperature and humidity from a remote sensor are displayed as well as time & date from a RTC.  More information on the remote sensor system on this page.

In this photo data is obtained from the Weather Underground using the ESP8266.  The time & date are also obtained from that site unlike the photo above where the time comes from a RTC.

I ported the sketch above using the Universal uC Color Graphics Library .

The display is much prettier than when using the Adafruit library but it is about seven times slower and requires a lot more memory.

ucg_int_t y;    //  declare a global variable

void crlf(){
  y = y + ucg.getFontAscent() - ucg.getFontDescent();
  y = y + 1;
  ucg.setPrintPos(0, y );
Tetris game as described in this Hackaday post

Or go directly to the author's webpage

Bodmer discovered a hardware register in the ILI9341 that allows for fast scrolling,  Quoting his post:

The unique part of this project is that the sketch uses the built in hardware scrolling feature of the ILI9341 chip, this takes the processing burden off the Arduino AVR microcontroller and means that the display can keep up with serial text messages at 9600 baud

To the left are two clock sketches.  What they have is common is where they derive their time. It is set and maintained from the NTP (Network Time Protocol ) using an ESP8266.  In addition they use the Time.h and Timezone.h libraries.  The enables the nice formatting seen in the digital clock.  In both cases the time will change with changes in daylight saving time in your area.

The digital clock use Ucglib and is 50K.  It is called NTP_Digital_clk_tz

The analog clock is derived from another program by Bodmer and is 40K.  It's called NTP_Analog_clk_tz

The ESP8266 is programmed with a Arduino IDE sketch that is a slightly modified example.  I call it NTP_sync

In December 2015, Adafruit released a new version of their Adafruit_GFX.h library.  It now included a number of new fonts. The last time I looked it was Version 1.1.9

I call this sketch ILI9341_text_11  The sketch is written for ESP8266 but easily converted to AVR

I have almost the same sketch written in Energia for the TI LaunchPad.  Email me if you are interested in a copy.




Roger's Embedded Microcontrollers Home Page     

This page written by Roger Schaefer. Last updated April 17, 2017