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.

45 Responses to “Tutorial – Arduino and ILI9325 colour TFT LCD modules”

  1. John says:

    H John,
    that looks really good for ts prce, I am buldng a robot controller for outdoor use, and I had planned to use 2 lcd dsplays ( whte on blue backlt background ) but testng t outdoors yesterday you could hardly see the wrtng.
    Ths unt looks very brght, but of course ts pctured ndoors.
    Do you thnk ts brghter than a bog standard LCD?

    Well done wth the artcles, very nformatve !
    John

  2. gadjet0 says:

    Thanks for the tutoral, really nterestng. I’ve ordered one.
    I notced that t has an SD card slot and an SPI nterface, have you tred these at all?

  3. Salut,
    the UTFT lbrary s absolutely worth a donaton. Hennng has wrtten a superb peace of code. I use t wth several TFT wthout ssues and of course, I have done my donaton (I suggest 5 Euro/TFT you use ;^)
    Cao! Mathas

  4. jayfdee says:

    Many thanks for the tutoral,I have been meanng to try one of these for a whle,so you have prompted me to buy one. Ordered from ebay £7 from Hong Kong..

    John D

  5. gadjet0 says:

    Sorry, mssed that but no menton of SPI, I’m plannng on usng wth a chpkt board

  6. Geoff says:

    H John:
    Thanks so much for your artcle. Frst of all, a newbe, so please bear wth me.
    I am not usng Arduno – usng a PIC16F877 nstead, but the exact dsplay you are usng!
    I have not been able to fnd any documentaton re the pnouts for the dsplay except the ILI9325 Data Sheet. Unfortunately ths does not gve me a clue where the Backlght pn s on the dsplay. I can’t fgure 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 dsplay?
    A search for “HY-TFT240_262k HEYAODZ110510” only comes up wth your artcle!

  7. Gus Smith says:

    Thanks! Bought 2 of the exact same models and t s workng great on Uno.

    Cheers,
    Gus

  8. Col says:

    Do you know f ths works wth an arduno nano v3. I have connected as per nstructons above and downloaded the sketch wth utft pns set to 24,23,22,21 but I do not get any text dsplayed , just backlt.

  9. gadjet0 says:

    The LCD arrved ths mornng and works fne.

    I tred the Touch lbrary but the resultant code s more then 32K so they won’t work, :-(.

    • gadjet0 says:

      H, I fgured out how to make the code smaller by un-commentng the defnes for other chpsets , n the memorysaver.h fle, now the program to clabrate the touch screen loads but there s no touch workng. Does yours?

    • Gus Smith says:

      H, tred the UTouch lbrary and the examples n there but ths but does not work for me. Also tred on Mega 2560 and does not work on that one ether.

      Gus

      • gadjet0 says:

        @Gus,
        Dd you connect the 6 way connector to the Arduno before tryng the touch functon, I ddn’t DOH!, I thought t all worked through the data connectons, I just realsed my error.

        I’ll connect them up and try agan.

      • Gus Smith says:

        I ddn’t RTFM. Forgot to connect the pns for the Utouch functons. “myTouch(6,5,4,3,2);”
        But I’m havng mxed results. The calbraton example works and recognzes the stylus nput. Then I coped the CAL_X, CAL_Y and CAL_S value to UTouchCD.h
        After that the button example dd not recognze anythng. Also tred LANDSCAPE and PORTRAIT mode. When Seral.prnt X and Y values t does show values.

        I wll play agan later today.

  10. Mr. Sharkey says:

    John;

    Very tmely post, I was researchng new and better LCD dsplays for my project and just happened to stop by here to see what was new and found your tutoral on the color dsplays. Ordered two (both worked), and grabbed the UTFT lbrary. Hennng was most helpful when I had download dffcultes, but t all got sorted out.

    Everyone, f you use ths lbrary, please consder sendng Hennng a donaton, the UTFT lbrary s excellent, well wrtten, and well documented wth many example sketches. It really does some amazng thngs.

    Now awatng the delvery of my new Mega2560, as I got so nvolved n wrtng code that my Duemlanove ran out of flash memory. 32k seemed lke so much space such a short tme ago…

  11. EasyE says:

    Hey John,
    Thank you for the post! Do you have any advce on movng the data pns? I’m tryng to to grab a .bmp fle from the Uno Wreless/SD sheld but there s a conflct wth pn 4 (needed for the SDCS).

  12. Mr. Sharkey says:

    Dd anyone actually ever get the UTFT brary to work on a Mega2560? I have had absolutely no success attemptng to run ether the UTFT examples or the sketches presented here on a Mega. All I get s a whte screen, n spte of wrng and re-wrng the LCD to the proper pns on the board.

  13. gadjet0 says:

    I fnally got the screen and the touch workng wth my UNO, I got the calbraton data wrong at frst, typos!
    I’m thnkng of dong a pcb for the dsplay, whch would be better, a sheld for the UNO or a pcb contanng ts own smd 328p (extra IO)?

    • John Boxall says:

      Nce work. If you were gong to manufacture somethng, gve t the opton of beng 5V/3.3V compatble so the Due can use t and also people wth the lttle computer… I thnks t’s called a Raspberry P?

  14. sharon says:

    H John,
    on the manual of the l9325 they wrote to use pn DB10-DB17 for 8bt, you are usng DB0-DB7.
    s there any dfference?
    thanks,

  15. Zoszko says:

    Hello!
    I have tred ths wth the exact same TFT screen. All I have got s a whte screen(backlght). I have checked the wrngs, t looks ok for me. Do you have any dea what the problem s?

    Z

  16. rafael garcia says:

    hello, srry, am usng the same lcd from the pcture and also am usng an arduno mega, but all that get s a whte screen, the lbary only work wth arduno uno?

  17. Igor says:

    H, John!
    Two month ago I changed dsplay on my Samsung E1080 moble phone and I’ve bought 3 spare dsplays for the moble.
    Now I have two absolutely new dsplays and I want to use them wth Arduno.
    Dsplays are marked on the top sde as 4535A; on the back sde as FPC4535A-V3-F
    Dsplays dmenton – 128х128 px.
    Colors – 65535.
    I asked Samsung for help but I was refused. No datasheet was found over nternet. Can you gve me advse how to use the dsplays?
    Thank you!

  18. Oliver says:

    H!

    Are you sure the 3.3V s needed? Accordng to

    http://www.ebay.com.au/tm/2-4-nch-TFT-LCD-Module-Screen-240-x-320-Pxels-ILI9325-IC-for-51-MSP430-AVR-PIC-/281090547824?pt=AU_B_I_Electrcal_Test_Equpment&hash=tem41724d6070

    there s regulator IC on board that supples the 3.3V f 5V are connected to VIN.

  19. John Dowdell says:

    The onlne converter looks handy. I wrote a RB565 app for myself that maybe others mght also fnd handy. Does pretty much the same thng convertng to a 16 bt word array: http://www.fluxfocus.com/lcd/btmap-bmp-to-rgb565-ans-c-array-converter/

Trackbacks/Pingbacks


Leave a Reply

Subscribe via email

Receive notifications of new posts by email.

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

Buy and support Silicon Chip - Australia's only Electronics Magazine.

Use of our content…

%d bloggers like this: