How to Use 2.4inch TFT LCD SPFD5408 With Arduino MEGA 2560




This instructable will show you how to interface the SPFD5408 2.4 Inch lcd to the arduino MEGA

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1:

Step 2: Libraries

Some of you may have purchased this LCD Screen or thinking of getting
one. Its a great screen for displaying images and graphics. I purchased mine for displaying sensor data from my 10 sensors on my robot via xbee (telemetry). I bought it not only out of impulse as it was very cheap but also that it was the biggest screen i could find cheaply in Australia. ($15).

Enough of me rambling...

Unfortunately this LCD Screen has not much support and i have seen people unable to find libraries for it especially for the MEGA.


1.I used the SWIFT Library and the Adafruit GFX Library

SWIFT Library by smoke and wires:

Smoke and wires lcd tutorial

2. Adafruit GFX Library

AdaFruit GFX Library

Step 3: Modify the Libraries to Interface With MEGA

2.After copying the libraries over to your libraries folder, open the SWIFT folder, locate SWIFT.cpp and change this line from:

// Use the include which corresponds to your arduino
//#include "mega_24_shield.h" #include "uno_24_shield.h"

to this (just un-comment the mega part and comment the uno part.

// Use the include which corresponds to your arduino
#include "mega_24_shield.h" //#include "uno_24_shield.h"

This will allow you to use the screen on the arduino MEGA. In terms of
the connections from the screen to the mega, just plug it in like a shield the same way as you do when connecting it to the UNO.

Step 4: Display Text on the Lcd

// Code provided by Smoke And Wires
// // This code has been taken from the Adafruit TFT Library and modified // by us for use with our TFT Shields / Modules // For original code / licensing please refer to //

#include // Core graphics library #include "SWTFT.h" // Hardware-specific library

// The control pins for the LCD can be assigned to any digital or // analog pins...but we'll use the analog pins as this allows us to // double up the pins with the touch screen (see the TFT paint example). // #define LCD_CS A3 // Chip Select goes to Analog 3 // #define LCD_CD A2 // Command/Data goes to Analog 2 // #define LCD_WR A1 // LCD Write goes to Analog 1 // #define LCD_RD A0 // LCD Read goes to Analog 0

// #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: // For the Arduino Uno, Duemilanove, Diecimila, etc.: // D0 connects to digital pin 8 (Notice these are // D1 connects to digital pin 9 NOT in order!) // D2 connects to digital pin 2 // D3 connects to digital pin 3 // D4 connects to digital pin 4 // D5 connects to digital pin 5 // D6 connects to digital pin 6 // D7 connects to digital pin 7 // For the Arduino Mega, use digital pins 22 through 29 // (on the 2-row header at the end of the board).

// Assign human-readable names to some common 16-bit color values: #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF

SWTFT tft; // If using the shield, all control and data lines are fixed, and // a simpler declaration can optionally be used: // SWTFT tft;

void setup(void) { tft.reset();

uint16_t identifier = tft.readID(); tft.begin(identifier); }

void loop(void) { for(uint8_t rotation=0; rotation=1; rotation++) { tft.setRotation(rotation); testText(); delay(20000); } }

unsigned long testFillScreen() { unsigned long start = micros(); tft.fillScreen(BLACK); tft.fillScreen(RED); tft.fillScreen(GREEN); tft.fillScreen(BLUE); tft.fillScreen(BLACK); return micros() - start; }

unsigned long testText() { tft.fillScreen(BLACK); unsigned long start = micros(); tft.setCursor(0, 0); tft.setTextColor(WHITE); tft.setTextSize(1); tft.println("Zhungu Robotics!");

tft.setTextColor(GREEN); tft.setTextSize(2); tft.println("Motor temp ~56 degrees C"); tft.setTextColor(WHITE);

tft.println("ESC Temp ~50 degrees C"); tft.setTextColor(MAGENTA);

tft.println("Methane Sensor ~20ppm"); tft.setTextColor(CYAN);

tft.println("Hydrogen sensor~0.2ppm"); tft.setTextColor(RED);

tft.println("Co2 Sensor ~70ppm"); tft.setTextColor(MAGENTA);

tft.println("Air pressure ~100011Pa"); tft.setTextColor(GREEN);

tft.println("Current temp ~30 degrees C"); tft.setTextColor(YELLOW);

tft.println("Current Humidity is 50%"); tft.setTextColor(CYAN);

tft.println("Altutude ~45m"); tft.setTextColor(WHITE);

tft.println("Voltage remaining ~ 7.6V"); tft.setTextColor(BLUE);

tft.println("Current draw ~12A"); tft.setTextColor(GREEN); tft.println("UV Index is 12mW/cm^2"); tft.setTextColor(RED); tft.println("light intensity is 930Lux");

return micros() - start; }

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    12 Discussions


    1 year ago

    It seems that the author did not test this code at all, or he left something out of the Instructable. The error with the incomplete #Include statement is solved by commenting out that line and adding the lines for the Adafruit GFX library. But then the compile fails in several ways.

    1. The constants for the colors (RED, BLUE, etc) are not defined and in the statement "SWTFT tft;" (about line 20), SWIFT is missing a type declaration.

    I haven't solved the last error and I may just move on using what limited knowledge I picked up from this Instructable.

    1 reply

    Reply 5 months ago

    Moving on would be best. There are better supported screens available at an attractive price point...regards


    Reply 5 months ago

    This instructable worked well for me, i am not sure what you are doing wrong. As mentioned before in the instructable, this is not a well supported screen. At the time i purchased it ~5years ago it was the only one that size i could find, now there are more screens available that are better supported. I suggest using those. I also suggest reading up on whether a product is well supported or not before purchasing too avoid issues in implementation. I see no reason to buy this screen now, when there are many and better supported ones available to use?


    2 years ago

    Assistance please, all I get when trying to compile this is the following error:
    Arduino: 1.8.2 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

    sketch_may06a:4: error: #include expects "FILENAME" or <FILENAME>

    #include // Core graphics library #include "SWTFT.h" // Hardware-specific library


    exit status 1

    #include expects "FILENAME" or <FILENAME>

    This report would have more information with

    "Show verbose output during compilation"

    option enabled in File -> Preferences.

    1 reply
    Akshay KG

    2 years ago

    I have only a white screen at here, what am i do now? i had tried it with another pair of Mega and tft display, same result obtained

    Fadhela Khalaf

    2 years ago

    hi thanks for sharing code
    i do it > but with inverted cordinates (mirror display )

    can you help please ??

    1 reply
    AbiramSFadhela Khalaf

    Reply 2 years ago

    find this "void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,uint16_t color, uint16_t bg, uint8_t size)" in Adafruit_GFX.cpp

    edit the for loop from this "for (int8_t j = 0; j<8; j++)"
    to "for (int8_t j = 8; j>0; j--)"


    Reply 2 years ago

    I am afraid it may not work on Uno because of lower specs. but google up, with time people find out new ways


    Reply 2 years ago

    I hope you got the answer in time. This tutorial is meant for MEGA because it is quite difficult (more steps) to get it working. For UNO, there are generic codes and yes, it works beautifully