How to Use 2.4 Inch TFT LCD SPFD5408 With Arduino Uno and Mega

249,037

134

182

Published

Introduction: How to Use 2.4 Inch TFT LCD SPFD5408 With Arduino Uno and Mega

This Instructable is to know how to work TFT 2.4 with the controller SPFD5408
with the libraries of Adafruit for TFT.

This library is the Adafruit TFT Libraries changed to works in TFT 2.4 shields with the SPFD5408 controller.

Now it is for Uno and Mega, Teensy is on the way...

It is based in the last version of Adafruit, inclusive with buttons features.

The TFT 2.4 is cheap TFT, that generally is from China, without documentation or libraries for it.

I tested some mcufriend shields.

When we try to use the TFT 2.4 with SPFD5408 controller in sketches with Adafruit TFT libraries, several things can happen :

  • White Screen
  • All screen with noise
  • Touch not works or is inverted (coordinate Y)
  • The colors are inverted
  • And other things

After trying for several days trying the solutions I found on the web, and none works 100%. So I decided to do an library specific to this controller.

I changed the Adafruit libraries for TFT: GFX , TFTLCD and TouchScreen. I join all in this one library, the library SPFD5408, to avoid problems with duplicate libraries and enables also have the original library Adafruit ready for use in other projects with another TFT hardware.

Step 1: Download the SPFD5408 Library

I made available it in my GitHub .

Please download it in: https://github.com/JoaoLopesF/SPFD5408

Attention: This library is ONLY for SPFD5408 TFT controller

If it not work, and you get a blank screen,

please access this site to help you identify the correct library:

http://misc.ws/2015/01/24/lcd-touch-screen-inform...

Step 2: Install

Please follow the details in README.

Step 3: First Test - Graphicstest

I modified the Adafruit graphicstest to work.

Please open the folder in spfd5408_graphicstest sketch example.

Upload this to Arduino Uno

Step 4: Test 2 - Tftpaint

TftPaint is a sketch from Adafruit_TFTLCD, is a one simple paint, but important for learning and test the TFT.

I modified this to work.

Please open the folder in spfd5408_tftpaint sketch example

Step 5: Utility - Calibrate

This TFT is with a resistive touch, and need calibration for accurate the touch

I made one sketch to help this process.

Please open the folder in spfd5408_calibration sketch example.
After the run of this program , you have the parameters of calibration to put in your sketch code.

10 People Made This Project!

Recommendations

  • Water Contest

    Water Contest
  • Creative Misuse Contest

    Creative Misuse Contest
  • Oil Contest

    Oil Contest

182 Discussions

My board arrived today and it looks like the one on your pic except for the silk screen print which simply says 2.4'' TFT LCD SHIELD.
And the ID with LCD_ID test returns 000.
I also found that the touch panel is connected to pins A2, A3, D8, D9.

With this adjustment touch gets recognized but the orientation is still a mess and I haven't found yet how to correct it.

How to adjust the backlight at this TFT? Thank you! I think it would be useful to know how to change font type in letters and numbers!

hey, can you help me with this tft display, i have an rotary encoder on pin 0 and pin a5, in serial monitor and tft display used the counter is error while imn't using tft display rotary encoder work fine, can u help me with that problem?

Thank you so much for the post. But I still can't fix the mirrored text and also it occupies only partial screen :/ Can someone help? The below comments din't help :/

1 reply

I have same problem with HX8347G driver (0x7575)
did have someone solution?

hello everyone

i am using this screen for my project and the problem i am having is that once i touch on the screen and display the next one and try to touch again the screen doesnt recognize what it is basically doing is in the background the initial screen is still present and the touch point is sensing from the 1st screen

i tried using the function "screen.background(0, 0, 0);" but i am getting an error:- 'class TFT' has no member named 'background'

any help would be appreciated ASAP

Everything works fine, thank u soo much ,except when i change the screen rotation (tft.setRotation(3);) touch is not aligned ,touch x and y coordinates are not with the display x,y coordinates ,

how ca i fix this.

1 reply

Thank you sir, finally i got a right library for it! while i run the "paint" example, i had noticed that the touch plate is not working properly, if i touch at the right corner it is selecting the left corner; how can i fix it?

2 replies

Thanks to slava_gll, I tried his tip for editing SPFD5408_TouchScreen.cpp, and for the first time after quite some nights of struggling the touchscreen is working in the correct x-y directions!

So, in SPFD5408_TouchScreen.cpp, change lines 157-164 to:

return TSPoint(y, x, z);

// *** SPFD5408 change -- Begin
// SPFD5408 change, because Y coordinate is inverted in this controller
//return TSPoint(x, 1023 - y, z);
// -- End

NOTE: y and x reversed!

Thanks a lot Broda

Now my screen work perfectly.

U r genius.

This instructable and your library have been extremely useful. Thanks so much. I've got it all working, but now when I write a new sketch I'm finding I'm having trouble with waitOneTouch(). It appears that several "touches" are being buffered. I notice in the Adafruit_STMPE610 there is a bufferEmpty() function that lets me check the buffer and keep reading until it's empty. But I can't find such a function in the SPFD5408 lib. Any tips would be greatly appreciated. Thanks!

1 reply

In case this might be helpful to others, I've got this worked out to my satisfaction. I don't quite understand why it works, but if you add a short delay between calls to waitOneTouch() it seems to work normally.

Your examples are excellent working!! Thank You very much.

HI, I have quite a few of these screens for the Arduino aleard. I like it. Now I have a Raspberry Pi, I do really want to buy yet another one just for Pi. Can I convert it to uae on Pi? I think it is a matter or usung the Pi GPIO, or configure Uthe GPIOs to mimic the Adruino, can this be done? Thanks,

Dear

My touch screen does not work at all. Do you know whats wrong here?

Thanks much, Joao! I was dreading getting started trying to make these little displays work, with no documentation and the word on the street being that even displays that looked alike might have different controllers. There were several Arduino libraries to pick from, but yours looked relatively straightforward and I liked your Instructables writeup. The libraries and the graphics test sketch worked, kind-of, with same problems as padouet reported, but it was fairly easy to find fixes for those, and now the graphics test sketch is working correctly. (Fixes noted below...)

Hello JoaoLopesF

Thank you for your work and librairies.
With my first tft 2.4 touch screen, it is very good, it is 0x9341 or ili9341..

Now, with my new 2.4 touch screen,I have a big problem., it is 0x9342 or ili9342 and your librairies give a bad result. All other librairies give nothing.

- colors are inverted ;black is 0xffff and white is 0x0000
- texte is mirored
- picture is troncated : landscape <=> paysage

On this no mine video, at 8'15" you can see what I have on screen
https://www.youtube.com/watch?v=5IcvKTeQPiY

The ILI9341 and ILI9342 are very
similar but the latter is configured for 320x240 (960 x 240 outputs)
instead of 240x320 (720 x 320 outputs).

Here data for ili9342

http://www.buydisplay.com/download/ic/ILI9342.pdf

Please, can you release your librairies ?
Thank you very much.

1 reply

Hello padouet,

I had EXACTLY the same problem this evening when I first started. I fixed each problem with some code changes:

First, the colors. I just swapped the color definitions in the test sketch. There may be a better way, but this works. Swap white and black; swap blue and yellow; swap red and cyan; swap green and magenta. (I need to dig into this a little further. The datasheet for the ILI9341 clearly shows 6 bits per color, but in the sketch, only 16 bits are used to define the colors... Also, it may be possible to send some bit(s) to the ILI9341/2 to invert the colors. I only started to look at the data sheet maybe two hours ago, so there is a lot in it I have not investigated.)

Second, for the reversed text: in SPFD5408_Adafruit_TFTLCD.cpp, look for lines with ILI9341_MADCTL_MX. You should find only two such lines, in case 1 and case 2 of the section that deals with rotation. Remove that part (and the following | ) from those two cases and add it to case 0 and case 3. This swaps the "X" direction for each rotation. (The definition of ILI9341_MADCTL_MX is in registers.h; it's just the bit position of MX in the ILI9341 memory address control register.)

Third, for the portrait <-> landscape problem, I just swapped the sizes in the #defines for TFTWIDTH and TFTHEIGHT. It occurs to me that I might have been able to do it differently; I suppose it could depend on what you want to think of as the width and the height of the display: are you using it in portrait or in landscape orientation. But anyway, that worked for me. It's late; I'll try playing with the other tests tomorrow!