A 2.4″ TFT Touchscreen Shield For Arduino

Introduction

2.4" TFT Touch Screen Shield With Micro SD Socket
2.4″ TFT Touch Screen Shield With Micro SD Socket

If you are looking for an inexpensive graphical interface for your Arduino, this could be it. Our 2.4″ Colour TFT display, has a four wire resistive touch screen, a micro SD card socket, and a convenient arduino shield footprint. To help you get going we have provided some example code, which can be downloaded here.

Specifications

  • Screen Size  :  2.4 inch
  • Resolution  :  240 x 320
  • LCD Color   :  65k
  • LCD Driver  : ST7781
  • Interface      : 8080 8 data bit with 4 control bits
  • Touchscreen  : 4 Wire Resistive Touchscreen

Arduino Pin Connections

Arduino Pin LCD Shield Pin Use
3.3V 3.3V Power
5V 5V Power
GND GND Power
A0 LCD_RD LCD Control
A1 LCD_WR   TOUCH_YP LCD Control / Touch Data
A2 LCD_RS     TOUCH_XM LCD Control / Touch Data
A3 LCD_CS LCD Control
A4 LCD_RST LCD Reset
D2 LCD_D2 LCD Data
D3 LCD_D3 LCD Data
D4 LCD_D4 LCD Data
D5 LCD_D5 LCD Data
D6 LCD_D6 / TOUCH XP LCD Data/ Touch Data
D7 LCD_D7 / TOUCH YM LCD Data / Touch Data
D8 LCD_D0 LCD Data
D9 LCD_D1 LCD Data
D10 SD_CS SD Select
D11 SD_DI SD Data
D12 SD_DO SD Data
D13 SD_SCK SD Clock

 How To Use.

WARNING.  The USB B-type port on the Arduino Uno R3 is taller then the headers on the board.  As a result, many shields, including this one can contact the metal shielding of the USB port, causing damage. The simplest way to avoid this is to place a piece of electrical tape, or Kapton tape, on top of the USB port to insulate it.

As with all Arduino Shields, connecting to the arduino is simply a matter of plugging the shield in. Take care to align the pins correctly, and ensure the bottom of the shield does not make contact with the Arduino USB port.

Software

We have modified the open source  Adafruit-TFTLCD library to work with the pin arrangement, and ST7781 Controller used bu this shield. Examining the examples should give a fair idea of how use these, however we are always happy to answer relevant questions. The original library was written to work with a range of different controllers and shields. While this is convenient for using boards interchangeably, we decided to strip it back to just what was needed for this shield and the ST7781 controller, rather than extend it to include one more shield. This should make the memory footprint smaller, and the code a little faster. We will continue to improve this as time permits. To use the demonstration code, download  the library from here, and extract. Copy the folder “SWTFT-Shield” from the extracted archive to your arduino Libraries folder. You will also need to install the :

 

12 thoughts on “A 2.4″ TFT Touchscreen Shield For Arduino”

  1. Hi,
    thanks a lot for your great work adapting your shield with the ST7781 controller. It works great on my UNO, but i don’t know how to get it working on a Mega2560. In the original Adafruit_TFTLCD.h there is the possibility to put this line into the code ://#define USE_ADAFRUIT_SHIELD_PINOUT 1

    I also tried to somehow merge the original version and your adapted one, but i got too many errors (its too hard programming stuff for me;-). so could you be so kind and give mi a hint what i have to change to use it with the Mega (either the shield- pinout or the “typical” 22-29 – pinout – for me both is possible…)

    thank you so much!

    paul

    1. Hi Paul,
      You will need to look at the port mapping of the Uno vs Mega.
      In the file uno_24_shield.h is the macro
      #define write8inline(d) { \
      PORTD = (PORTD & B00000011) | ((d) & B11111100); \
      PORTB = (PORTB & B11111100) | ((d) & B00000011); \
      WR_STROBE; }

      This will need to be altered to reflect the ports that map to the digital pins of the mega.

      Let me know how you get on.

      If I have some time this weekend I will try to get one working on a Mega. It shouldn’t be too difficult, but the code will be a bit slower as the port to pin assignments are a little messier.

      Nick

    2. OK, I have finally had a couple of hours spare and have this working with an Arduino Mega. There is a new file “mega_24_shield.h” which addresses the pins the Mega uses. Just uncomment the correct include inside “SWTFT.cpp”

      #include “mega_24_shield.h” if you are using a mega
      or
      #include “uno_24_shield.h”

      Everything else should work the same, although the Mega will be a little slower due to the overhead of shifting the data bits around.

      I haven’t tested this with the SD card yet.

  2. Hi Nick,

    I don’t know if you are aware but setRotation does not work correctly. It only works correctly for 0 degrees. 90, 180 and 270 does not work correctly.

    1. Hi, The setRotation works with regards to the graphics library, so I assume you are referring to uploading bitmaps from a SD card. According to the datasheet, that should be accomplished by setting the MADCTL registers to define the ram update direction, and window, but I haven’t managed to get that working correctly for this controller. I’m kinda hoping someone else will figure that out first.

  3. Hi,

    when i was testing tftpaint it gives me

    tftpaint.ino: In function ‘void loop()’:
    tftpaint:80: error: ‘Point’ was not declared in this scope
    tftpaint:80: error: expected `;’ before ‘p’
    tftpaint:92: error: ‘p’ was not declared in this scope

    1. OK, I see in the latest version of the TouchScreen library, class “Point” has been renamed “TSPoint” I have updated the code on Github to reflect this.
      If change the line
      Point p = ts.getPoint();
      to
      TSPoint p = ts.getPoint();
      in your sketch, everything should work as expected.

  4. Hi,
    I have a motherboard compatible with Arduino Uno Rev3 , and when I run the program, “rotationtest” appear the following errors:

    rotationtest:18: error: ‘SWTFT’ does not name a type
    rotationtest.pde: In function ‘void setup()’:
    rotationtest:27: error: ‘tft’ was not declared in this scope
    rotationtest.pde: In function ‘void rotateText()’:
    rotationtest:53: error: ‘tft’ was not declared in this scope
    rotationtest.pde: In function ‘void rotateFillcircle()’:
    rotationtest:79: error: ‘tft’ was not declared in this scope
    rotationtest.pde: In function ‘void rotateDrawcircle()’:
    rotationtest:93: error: ‘tft’ was not declared in this scope
    rotationtest.pde: In function ‘void rotateFillrect()’:
    rotationtest:107: error: ‘tft’ was not declared in this scope
    rotationtest.pde: In function ‘void rotateDrawrect()’:
    rotationtest:121: error: ‘tft’ was not declared in this scope
    rotationtest.pde: In function ‘void rotateFastline()’:
    rotationtest:135: error: ‘tft’ was not declared in this scope
    rotationtest.pde: In function ‘void rotateLine()’:
    rotationtest:150: error: ‘tft’ was not declared in this scope
    rotationtest.pde: In function ‘void rotatePixel()’:
    rotationtest:163: error: ‘tft’ was not declared in this scope

    What am I doing wrong?

    1. Hi,
      This is an error from the compiler. The first error “SWTFT does not name a type” is the main error. The rest stem from this. It is saying that the name “SWTFT” is not recognized as a class. This is caused by the library SWTFT not being available to the compiler.
      Have you copied the directory to your arduino libraries folder, and named it “SWTFT”
      This folder should contain the files SWTFT.cpp and SWTFT.h amongst others.
      In your arduino IDE, under File–>Examples, Is SWTFT showing at the bottom of the list?

  5. Hi
    It was a problem because I had several folders in the same libraries. But I still have problems with my tft …
    When you run for example “paint” the screen stays lit, but it shows nothing, however, in the terminal, displays the coordinates according click on the screen program.
    I tested with libraries and so does ST7783. Have you got your idea of ​​the TFT is faulty?
    Thank you.

Leave a Reply