Tutorial – Arduino and ILI9325 colour TFT LCD modules

Learn how to use inexpensive ILI9325 colour TFT LCD modules in chapter fifty of a series originally titled “Getting Started/Moving Forward with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.

Introduction

Colour TFT LCD modules just keep getting cheaper, so in this tutorial we’ll show you how to get going with some of the most inexpensive modules we could find. The subject of our tutorial is a 2.8″ 240 x 320 TFT module with the ILI9325 LCD controller chip. If you look in ebay this example should appear pretty easily, here’s a photo of the front and back to help identify it:

There is also the line “HY-TFT240_262k HEYAODZ110510″ printed on the back of the module. They should cost less than US$10 plus shipping. Build quality may not be job number one at the factory so order a few, however considering the cost of something similar from other retailers it’s cheap insurance. You’ll also want sixteen male to female jumper wires to connect the module to your Arduino.

Getting started

To make life easier we’ll use an Arduino library “UTFT” written for this and other LCD modules. It has been created by Henning Karlsen and can be downloaded from his website. If you can, send him a donation – this library is well worth it. Once you’ve downloaded and installed the UTFT library, the next step is to wire up the LCD for a test.

Run a jumper from the following LCD module pins to your Arduino Uno (or compatible):

  • DB0 to DB7 > Arduino D0 to D7 respectively
  • RD > 3.3 V
  • RSET > A2
  • CS > A3
  • RW > A4
  • RS > A5
  • backlight 5V > 5V
  • backlight GND > GND

Then upload the following sketch – Example 50.1. You should be presented with the following on your display:

If you’re curious, the LCD module and my Eleven board draws 225 mA of current. If that didn’t work for you, double-check the wiring against the list provided earlier. Now we’ll move forward and learn how to display text and graphics.

Sketch preparation

You will always need the following before void setup():

and in void setup():

with the former command, change orientation to either LANDSCAPE to PORTRAIT depending on how you’ll view the screen. You may need further commands however these are specific to features that will be described below. The function .clrScr() will clear the screen.

Displaying Text

There are three different fonts available with the library. To use them add the following three lines before void setup():

When displaying text you’ll need to define the foreground and background colours with the following:

Where red, green and blue are values between zero and 255. So if you want white use 255,255,255 etc. For some named colours and their RGB values, click here. To select the required font, use one of the following:

Now to display the text use the function:

where text is what you’d like to display, x is the horizontal alignment (LEFT, CENTER, RIGHT) or position in pixels from the left-hand side of the screen and y is the starting point of the top-left of the text. For example, to start at the top-left of the display y would be zero. You can also display a string variable instead of text in inverted commas.

You can see all this in action with the following sketch – Example 50.2, which is demonstrated in the following video:

Furthremore, you can also specify the angle of display, which gives a simple way of displaying text on different slopes. Simply add the angle as an extra parameter at the end:

Again, see the following sketch – Example 50.2a, and the results below:

Displaying Numbers

Although you can display numbers with the text functions explained previously, there are two functions specifically for displaying integers and floats.

You can see these functions in action with the following sketch – Example 50.3, with an example of the results below:

example50p3

Displaying Graphics

There’s a few graphic functions that can be used to create required images. The first is:.

which is used the fill the screen with a certain colour. The next simply draws a pixel at a specified x,y location:

Remember that the top-left of the screen is 0,0. Moving on, to draw a single line, use:

where the line starts at x1,y1 and finishes at x2,y2. Need a rectangle? Use:

where the top-left of the rectangle is x1,y1 and the bottom-right is x2, y2. You can also have rectangles with rounded corners, just use:

instead. And finally, circles – which are quite easy. Just use:

where x,y are the coordinates for the centre of the circle, and r is the radius. For a quick demonstration of all the graphic functions mentioned so far, see Example 50.4 – and the following video:

Displaying bitmap images

If you already have an image in .gif, .jpg or .png format that’s less than 300 KB in size, this can be displayed on the LCD. To do so, the file needs to be converted to an array which is inserted into your sketch. Let’s work with a simple example to explain the process. Below is our example image:

jrt3030

Save the image of the puppy somewhere convenient, then visit this page. Select the downloaded file, and select the .c and Arduino radio buttons, then click “make file”. After a moment or two a new file will start downloading. When it arrives, open it with a text editor – you’ll see it contains a huge array and another #include statement – for example:

cfile

Past the #include statement and the array into your sketch above void setup(). After doing that, don’t be tempted to “autoformat” the sketch in the Arduino IDE. Now you can use the following function to display the bitmap on the LCD:

Where x and y are the top-left coordinates of the image, width and height are the … width and height of the image, and name is the name of the array. Scale is optional – you can double the size of the image with this parameter. For example a value of two will double the size, three triples it – etc. The function uses simple interpolation to enlarge the image, and can be a clever way of displaying larger images without using extra memory. Finally, you can also display the bitmap on an angle – using:

where angle is the angle of rotation and cx/cy are the coordinates for the rotational centre of the image.

The bitmap functions using the example image have been used in the following sketch – Example 50.5, with the results in the following video:

Unfortunately the camera doesn’t really do the screen justice, it looks much better with the naked eye.

What about the SD card socket and touch screen?

The SD socket didn’t work, and I won’t be working with the touch screen at this time.

Conclusion

So there you have it – an incredibly inexpensive and possibly useful LCD module. Thank you to Henning Karlsen for his useful library, and if you found it useful – send him a donation via his page.

LEDborder

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other –  and we can all learn something.

The following two tabs change content below.

John Boxall

Founder, owner and managing editor of tronixstuff.com.

Leave a Reply

  1. Hi John,
    that looks really good for its price, I am building a robot controller for outdoor use, and I had planned to use 2 lcd displays ( white on blue backlit background ) but testing it outdoors yesterday you could hardly see the writing.
    This unit looks very bright, but of course its pictured indoors.
    Do you think its brighter than a bog standard LCD?

    Well done with the articles, very informative !
    John

    • Thanks. It’s nothing over a normal LCD, so indoor use only I’m afraid.
      OLEDs may be better, but I haven’t seen a component-level one to experiment with yet.

    • Yes John, it’s much brighter than the bog standard LCD. 3.3V worked great for me. Thanks guys. J smith

  2. Thanks for the tutorial, really interesting. I’ve ordered one.
    I noticed that it has an SD card slot and an SPI interface, have you tried these at all?

  3. Salut,
    the UTFT library is absolutely worth a donation. Henning has written a superb peace of code. I use it with several TFT without issues and of course, I have done my donation (I suggest 5 Euro/TFT you use ;^)
    Ciao! Mathias

  4. Many thanks for the tutorial,I have been meaning to try one of these for a while,so you have prompted me to buy one. Ordered from ebay £7 from Hong Kong..

    John D

  5. Hi John:
    Thanks so much for your article. First of all, a newbie, so please bear with me.
    I am not using Arduino – using a PIC16F877 instead, but the exact display you are using!
    I have not been able to find any documentation re the pinouts for the display except the ILI9325 Data Sheet. Unfortunately this does not give me a clue where the Backlight pin is on the display. I can’t figure out where the touchscreen x, y+ etc are or what PEN_Q, DOUT etc are used for!
    Do you know where I can get some data on the actual display?
    A search for “HY-TFT240_262k HEYAODZ110510″ only comes up with your article!

  6. Do you know if this works with an arduino nano v3. I have connected as per instructions above and downloaded the sketch with utft pins set to 24,23,22,21 but I do not get any text displayed , just backlit.

  7. The LCD arrived this morning and works fine.

    I tried the Touch library but the resultant code is more then 32K so they won’t work, :-(.

    • Hi, I figured out how to make the code smaller by un-commenting the defines for other chipsets , in the memorysaver.h file, now the program to claibrate the touch screen loads but there is no touch working. Does yours?

    • Hi, tried the UTouch library and the examples in there but this but does not work for me. Also tried on Mega 2560 and does not work on that one either.

      Gus

      • @Gus,
        Did you connect the 6 way connector to the Arduino before trying the touch function, I didn’t DOH!, I thought it all worked through the data connections, I just realised my error.

        I’ll connect them up and try again.

      • I didn’t RTFM. Forgot to connect the pins for the Utouch functions. “myTouch(6,5,4,3,2);”
        But I’m having mixed results. The calibration example works and recognizes the stylus input. Then I copied the CAL_X, CAL_Y and CAL_S value to UTouchCD.h
        After that the button example did not recognize anything. Also tried LANDSCAPE and PORTRAIT mode. When Serial.print X and Y values it does show values.

        I will play again later today.

  8. John;

    Very timely post, I was researching new and better LCD displays for my project and just happened to stop by here to see what was new and found your tutorial on the color displays. Ordered two (both worked), and grabbed the UTFT library. Henning was most helpful when I had download difficulties, but it all got sorted out.

    Everyone, if you use this library, please consider sending Henning a donation, the UTFT library is excellent, well written, and well documented with many example sketches. It really does some amazing things.

    Now awaiting the delivery of my new Mega2560, as I got so involved in writing code that my Duemilanove ran out of flash memory. 32k seemed like so much space such a short time ago…

  9. Hey John,
    Thank you for the post! Do you have any advice on moving the data pins? I’m trying to to grab a .bmp file from the Uno Wireless/SD shield but there is a conflict with pin 4 (needed for the SDCS).

  10. Did anyone actually ever get the UTFT ibrary to work on a Mega2560? I have had absolutely no success attempting to run either the UTFT examples or the sketches presented here on a Mega. All I get is a white screen, in spite of wiring and re-wiring the LCD to the proper pins on the board.

  11. I finally got the screen and the touch working with my UNO, I got the calibration data wrong at first, typos!
    I’m thinking of doing a pcb for the display, which would be better, a shield for the UNO or a pcb containing its own smd 328p (extra IO)?

    • Nice work. If you were going to manufacture something, give it the option of being 5V/3.3V compatible so the Due can use it and also people with the little computer… I thinks it’s called a Raspberry Pi?

  12. Hi John,
    on the manual of the ili9325 they wrote to use pin DB10-DB17 for 8bit, you are using DB0-DB7.
    is there any difference?
    thanks,

  13. Hello!
    I have tried this with the exact same TFT screen. All I have got is a white screen(backlight). I have checked the wirings, it looks ok for me. Do you have any idea what the problem is?

    Z

  14. hello, srry, i am using the same lcd from the picture and also i am using an arduino mega, but all that i get is a white screen, the libary only work with arduino uno?

  15. Hi, John!
    Two month ago I changed display on my Samsung E1080 mobile phone and I’ve bought 3 spare displays for the mobile.
    Now I have two absolutely new displays and I want to use them with Arduino.
    Displays are marked on the top side as 4535A; on the back side as FPC4535A-V3-F
    Displays dimention – 128х128 px.
    Colors – 65535.
    I asked Samsung for help but I was refused. No datasheet was found over internet. Can you give me advise how to use the displays?
    Thank you!

  16. Hello , I have a little problem , followed all the steps you described on their website , but when I compile the program the following error appears :

    In file included from example50p3.ino : 3 :
    C : \ Users \ Luana \ Documents \ Arduino \ libraries \ UTFT / UTFT.h : 150:42 : error : hardware / avr / HW_AVR_defines.h : No such file or directory
    ( now I checked and the library , this file exists . )
    example50p3.ino : 4:9 : error : macro names must be identifiers
    In file included from example50p3.ino : 3 :
    C : \ Users \ Luana \ Documents \ Arduino \ libraries \ UTFT / UTFT.h : 199 : error : ‘ bitmapdatatype ‘ has not been declared
    C : \ Users \ Luana \ Documents \ Arduino \ libraries \ UTFT / UTFT.h : 219 : error : ISO C + + forbids declaration of ‘ regtype ‘ with no type
    C : \ Users \ Luana \ Documents \ Arduino \ libraries \ UTFT / UTFT.h : 219 : error : expected ‘ ; ‘ before ‘ * ‘ token
    C : \ Users \ Luana \ Documents \ Arduino \ libraries \ UTFT / UTFT.h : 220 : error : ‘ regsize ‘ does not name a type
    example50p3.ino : In function ‘ void loop ( ) ‘ :
    example50p3.ino : 23 : warning: deprecated conversion from string constant to ‘ char * ‘

    Can you help me plss ?

    • Wow, that’s odd. Are you using Arduino IDE v1.0.x? If not, please do so. If that fails, delete and reinstall the library files.

    • Hi Luana, the libraries are written for use on MAC (/). If you want to use then in Windows (\) you will need to change the directories. For example open UTFT.h and change “hardware/avr/HW_AVR_defines.h” to “C:\Program Files (x86)\Arduino\hardware\avr/HW_AVR_defines.h”, or where ever you saved them. You would need to do this with UTFT.cpp as well.
      Regards
      Ruart

  17. ————- SOLUTION FOR ARDUINO_MEGA ———————–
    The D0-D7 (Display) must be connected to (D)22-29 of the Arduino_Mega.

    I have used: UTFT myGLCD(ILI9325C,A5,A4,A3,A2);

    You will find this info in the document:
    http://henningkarlsen.com/electronics/files/UTFT_Requirements.pdf

    See this picture:
    https://www.dropbox.com/s/4urtxr68ey22dw3/IMG_20140214_115706.jpg

    My Display has a other (newer?) PCB, the datalines are marked D10-D17 (not D0-7 or D8-15).

    @John: Feel free to copy the picture to your side – it will be avalible on my side only for some days/weeks.

    Thx to John and Hennig for her work!
    Pit
    —————————————————————-

  18. Your work on these tfts is admirable, almost heroic! But for the more novices out there (myself), I would recommend using a tft that incorporates a controller that can be talked to by SPI. Then 4 pins suffice!

  19. Thanks for all usefull knowledges…
    I getting started with stm32 and lpc2102, this explanation was very usefull for me.

  20. This uses quite a few pins. Is it possible to use a shift register or something so I could use three at once? Or could I use an Arduino Mega? I assume I would have to alter the library to do either of these. Thanks!

    • Some people have found success with a Mega, some have not. If I/O is limited perhaps look for a screen with a serial or SPI interface.

  21. Hello! I bought a LCD similar to this one, but with 20-pin interface, and luckily I was able to make it work with the UTFT library. My question is: how long these LCDs can stand working in 24/7, showing the same image? It is needed some kind of screensaver?

  22. Thanks so much for your article.
    I’ve a little problem using the “HY-TFT240_262k HEYAODZ120820″.
    I followed the guide and get the results shown, but during the operation the display shows a clear halo annoying, such as flicker, which disappears with the refresh. Is it normal, or it could be a hardware problem? I’ve already checked connections and they seem ok.
    Thank you!

  23. you stated above in the tutorial that:
    “The subject of our tutorial is a 2.8″ 240 x 320 TFT module with the ILI9325 LCD ”
    but below the picture you said:
    “the line “HY-TFT240_262k HEYAODZ110510″ printed on the back of the module.”

    Does it mean I have to buy both of them, or one of them?
    I want 2.8″ LCD

    • It’s all the same thing. “HY-TFT240_262k HEYAODZ110510″ is what was printed on the back of the LCD module we used.

  24. well, I think it’ll work in whatever size that has the same specification. ^^
    There’s arduino sheild for the LCD instead of the “16 jumper wires”, would you recommend me to buy it? I think it’ll look pretty better.