2.4" Colour TFT Touch Screen and Adapter Board for Arduino (slipping away again)

What TFT are we talking about now?

I ordered the SPI/8 bit/16bit model yesterday, should keep me busy porting the libraries. Ill report when and if it arrives.

casemod: What TFT are we talking about now?

I ordered the SPI/8 bit/16bit model yesterday, should keep me busy porting the libraries. Ill report when and if it arrives.

This one http://www.ebay.co.uk/itm/141321869364?_trksid=p2059210.m2749.l2649&var=440442626135&ssPageName=STRK%3AMEBIDX%3AIT

I think this wouls suit your requisites quite nicelly.

SPI TFT, screen and SD interface. And there are libraries widelly available for the ILI9341

http://www.ebay.co.uk/itm/240x320-2-4-SPI-TFT-LCD-Touch-Panel-Serial-Port-Module-with-PBC-ILI9341-5V-3-3V-/121414443081?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item1c44dd6049

casemod: I think this would suit your requisites quite nicelly.

SPI TFT, screen and SD interface. And there are libraries widely available for the ILI9341

http://www.ebay.co.uk/itm/240x320-2-4-SPI-TFT-LCD-Touch-Panel-Serial-Port-Module-with-PBC-ILI9341-5V-3-3V-/121414443081?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item1c44dd6049

At that price including postage I'd be prepared to order directly from China. I'll have a look for Arduino type libraries when I get a bit more time but a quick look at the download files they supply has some C code along with comments in Chinese (my Chinese is only good enough to order at the take away... a number 34, 56 and 123 please). I don't fancy reverse engineering the code as this could be a project in its own right.

Doesn't look to be touch screen.

Possibly originally intended for mobile phones but technology and user demands moved on and left these on the shelf???

acboother: Doesn't look to be touch screen.

It is

I've ordered one. :astonished:

Wahey, it's arrived today.

Just in time... was knee deep in a variation of the project without a screen. Now I'll have to look up how to get this little baby running. It has a fraction the number of pins on the board and I'd say it was exactly the same LCD on board so feeling very hopeful.

Ouch! Libraries, libraries, libraries...

Can anyone jump start me please. I need the LCD and touch but not the SD card

Cheers Alan

acboother: Ouch! Libraries, libraries, libraries...

Can anyone jump start me please. I need the LCD and touch but not the SD card

Cheers Alan

Have you inquired the seller? I got one without the touch. Working good ;)

casemod:

acboother: Ouch! Libraries, libraries, libraries...

Can anyone jump start me please. I need the LCD and touch but not the SD card

Cheers Alan

Have you inquired the seller? I got one without the touch. Working good ;)

I got a download link but the files are not Arduino orientated and would require decoding a bit... plus the comments all show in high order ASCII :(

Could you point me to the LCD only library you have please

Alan

I use the adafruit one. Same thing as another 2.2 I have

https://github.com/adafruit/TFTLCD-Library

You also need the adafruit_GFX if you dont have it installed already https://github.com/adafruit/Adafruit-GFX-Library

Cant test the touch to see if it works with that model I have been giving some tips on another thread, but the poster didn't bother trying, so let us know

casemod: I use the adafruit one. Same thing as another 2.2 I have

https://github.com/adafruit/TFTLCD-Library

You also need the adafruit_GFX if you dont have it installed already https://github.com/adafruit/Adafruit-GFX-Library

Cant test the touch to see if it works with that model I have been giving some tips on another thread, but the poster didn't bother trying, so let us know

Okay, some free time and trying to get this going. Have downloaded the libraries and did a test compile of a sample so everything set to rock and roll on my Nano... Did have some ADAfruit libs but these are more up to date.

Need to wire it up but having an issue with the voltage. I don't want to experiment too much as the time to wait for a second unit is soooo long if it goes horribly wrong.

The eBay advert says 5v compatible but the supporting documentation (ha ha ha) doesn't help. Lots of stuff on the internet about using 3.3v. I don't have a voltage convertor but would a voltage divider work for the data pins in (not for MOSI as its 3.3v data into the Arduino... or is it the MISO thats in???).

130 ohm and 330 ohm dividing the voltage from 5 v to 3.587 v ( a little high may be but I have 130 and 330 ohms kicking about)

460 ohm total resistance at 5 v = 54.348 milliwatts

54.348 millwatts at 5v is 10.87 millamps

Sounds okay? Anyone point out my mistake if any.

Hmm... the screen on my 2.4" LCD is the same physical size as the screen on my 2.2" LCD...

Can't wait to get the second one up and running to check.

Are the sellers over advertising or is one actually bigger than the other... we wait with baited breath

I have both the 2.2 and the 2.4 and they are different in size.

As to the wiring:

LED - 5V trought a 100Ohm resistor.
VCC - 3.3V on the arduino

Data:
10Kohm resistors in series with the arduino <-> display.
The display has internal zener’s on the inputs. The inputs are not 5V compatible, only the SD input is.

– or –

Some people have had success using a logic level buffer such as the CD4050. Others have only managed to get it working with bitbanged SPI.

Here they are…

Connected up and … failed :frowning: Screen lights up but that’s it. I am using voltage dividers but that give 3.5v… on the data pins

I am using this sample code directly from the Adafruit library see below.

My worries started because the pins referred to in the sketch don’t quite correspond with the names on the LCD board.

#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

I have the following pins on the LCD connected

LCD                      Arduino
-----                    --------
VCC                    3.3v directly
GND                    GND directly
CS                     A3 via voltage divider
RST                    A4 via voltage divider
D/C                    A2 via voltage divider
MOSI/SDI               A1 via voltage divider
SCK                    D13 via voltage divider
LED                    3.3v via 10ohm resistor
MOSI/SDO               A0 directly

I also am worried that I have used the D13 pin (SCK) but not the D11 (MOSI) and D12 (MISO)… There is no reference to the connection from the LCD SCK pin to the Arduino in the sample sketch so I guessed.

Here is the output from the serial monitor

TFT LCD test
Using Adafruit 2.8" TFT Breakout Board Pinout
TFT size is 240x320
Unknown LCD driver chip: 0
If using the Adafruit 2.8" TFT Arduino shield, the line:
  #define USE_ADAFRUIT_SHIELD_PINOUT
should appear in the library header (Adafruit_TFT.h).
If using the breakout board, it should NOT be #defined!
Also if using the breakout, double-check that all wiring
matches the tutorial.

and the actual sketch below:

// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.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

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;

void setup(void) {
  Serial.begin(9600);
  Serial.println(F("TFT LCD test"));

#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
  Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif

  Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());

  tft.reset();

  uint16_t identifier = tft.readID();

  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    return;
  }

  tft.begin(identifier);

  Serial.println(F("Benchmark                Time (microseconds)"));

  Serial.print(F("Screen fill              "));
  Serial.println(testFillScreen());
  delay(500);

  Serial.print(F("Text                     "));
  Serial.println(testText());
  delay(3000);

  Serial.print(F("Lines                    "));
  Serial.println(testLines(CYAN));
  delay(500);

  Serial.print(F("Horiz/Vert Lines         "));
  Serial.println(testFastLines(RED, BLUE));
  delay(500);

  Serial.print(F("Rectangles (outline)     "));
  Serial.println(testRects(GREEN));
  delay(500);

  Serial.print(F("Rectangles (filled)      "));
  Serial.println(testFilledRects(YELLOW, MAGENTA));
  delay(500);

  Serial.print(F("Circles (filled)         "));
  Serial.println(testFilledCircles(10, MAGENTA));

  Serial.print(F("Circles (outline)        "));
  Serial.println(testCircles(10, WHITE));
  delay(500);

  Serial.print(F("Triangles (outline)      "));
  Serial.println(testTriangles());
  delay(500);

  Serial.print(F("Triangles (filled)       "));
  Serial.println(testFilledTriangles());
  delay(500);

  Serial.print(F("Rounded rects (outline)  "));
  Serial.println(testRoundRects());
  delay(500);

  Serial.print(F("Rounded rects (filled)   "));
  Serial.println(testFilledRoundRects());
  delay(500);

  Serial.println(F("Done!"));
}

void loop(void) {
  for(uint8_t rotation=0; rotation<4; rotation++) {
    tft.setRotation(rotation);
    testText();
    delay(2000);
  }


 FUNCTIONS REMOVED TO REMAIN WITHIN MESSAGE POSTING LIMIT
}

I believe the example you used is for software SPI. Tomorrow I'll post some example code using HW SPI.

casemod: I believe the example you used is for software SPI. Tomorrow I'll post some example code using HW SPI.

Great. It's getting late here and time for bed.

Wire as per description and run the text_graphics example

–or–

/***************************************************
  This is our Bitmap drawing example for the Adafruit ILI9341 Breakout and Shield
  ----> http://www.adafruit.com/products/1651

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
  
  Aditions by Carlos Silva - May 2014
 ****************************************************/


#include <Adafruit_GFX.h>    // Core graphics library
#include "Adafruit_ILI9341.h" // Hardware-specific library
#include <SPI.h>
#include <SD.h>

// TFT display and SD card will share the hardware SPI interface.
// Hardware SPI pins are specific to the Arduino board type and
// cannot be remapped to alternate pins.  For Arduino Uno,
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
// MEGA pin 51 = MOSI, pin 50 = MISO, pin 52 = SCK.

#define TFT_DC 9
#define TFT_CS 10

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

#define SD_CS 4

void setup(void) {
  Serial.begin(9600);

  tft.begin();
  tft.fillScreen(ILI9341_BLUE);
  
  Serial.print("Initializing SD card...");
  if (!SD.begin(SD_CS)) {
    Serial.println("failed!");
  }
  Serial.println("OK!");

  bmpDraw("flower.bmp", 0, 0);
}

void loop() {
}

// This function opens a Windows Bitmap (BMP) file and
// displays it at the given coordinates.  It's sped up
// by reading many pixels worth of data at a time
// (rather than pixel by pixel).  Increasing the buffer
// size takes more of the Arduino's precious RAM but
// makes loading a little faster.  20 pixels seems a
// good balance.

#define BUFFPIXEL 20

void bmpDraw(char *filename, uint8_t x, uint16_t y) {

  File     bmpFile;
  int      bmpWidth, bmpHeight;   // W+H in pixels
  uint8_t  bmpDepth;              // Bit depth (currently must be 24)
  uint32_t bmpImageoffset;        // Start of image data in file
  uint32_t rowSize;               // Not always = bmpWidth; may have padding
  uint8_t  sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
  uint8_t  buffidx = sizeof(sdbuffer); // Current position in sdbuffer
  boolean  goodBmp = false;       // Set to true on valid header parse
  boolean  flip    = true;        // BMP is stored bottom-to-top
  int      w, h, row, col;
  uint8_t  r, g, b;
  uint32_t pos = 0, startTime = millis();

  if((x >= tft.width()) || (y >= tft.height())) return;

  Serial.println();
  Serial.print(F("Loading image '"));
  Serial.print(filename);
  Serial.println('\'');

  // Open requested file on SD card
  if ((bmpFile = SD.open(filename)) == NULL) {
    Serial.print(F("File not found"));
    return;
  }

  // Parse BMP header
  if(read16(bmpFile) == 0x4D42) { // BMP signature
    Serial.print(F("File size: ")); Serial.println(read32(bmpFile));
    (void)read32(bmpFile); // Read & ignore creator bytes
    bmpImageoffset = read32(bmpFile); // Start of image data
    Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC);
    // Read DIB header
    Serial.print(F("Header size: ")); Serial.println(read32(bmpFile));
    bmpWidth  = read32(bmpFile);
    bmpHeight = read32(bmpFile);
    if(read16(bmpFile) == 1) { // # planes -- must be '1'
      bmpDepth = read16(bmpFile); // bits per pixel
      Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth);
      if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed

        goodBmp = true; // Supported BMP format -- proceed!
        Serial.print(F("Image size: "));
        Serial.print(bmpWidth);
        Serial.print('x');
        Serial.println(bmpHeight);

        // BMP rows are padded (if needed) to 4-byte boundary
        rowSize = (bmpWidth * 3 + 3) & ~3;

        // If bmpHeight is negative, image is in top-down order.
        // This is not canon but has been observed in the wild.
        if(bmpHeight < 0) {
          bmpHeight = -bmpHeight;
          flip      = false;
        }

        // Crop area to be loaded
        w = bmpWidth;
        h = bmpHeight;
        if((x+w-1) >= tft.width())  w = tft.width()  - x;
        if((y+h-1) >= tft.height()) h = tft.height() - y;

        // Set TFT address window to clipped image bounds
        tft.setAddrWindow(x, y, x+w-1, y+h-1);

        for (row=0; row<h; row++) { // For each scanline...

          // Seek to start of scan line.  It might seem labor-
          // intensive to be doing this on every line, but this
          // method covers a lot of gritty details like cropping
          // and scanline padding.  Also, the seek only takes
          // place if the file position actually needs to change
          // (avoids a lot of cluster math in SD library).
          if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
            pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
          else     // Bitmap is stored top-to-bottom
            pos = bmpImageoffset + row * rowSize;
          if(bmpFile.position() != pos) { // Need seek?
            bmpFile.seek(pos);
            buffidx = sizeof(sdbuffer); // Force buffer reload
          }

          for (col=0; col<w; col++) { // For each pixel...
            // Time to read more pixel data?
            if (buffidx >= sizeof(sdbuffer)) { // Indeed
              bmpFile.read(sdbuffer, sizeof(sdbuffer));
              buffidx = 0; // Set index to beginning
            }

            // Convert pixel from BMP to TFT format, push to display
            b = sdbuffer[buffidx++];
            g = sdbuffer[buffidx++];
            r = sdbuffer[buffidx++];
            tft.pushColor(tft.color565(r,g,b));
          } // end pixel
        } // end scanline
        Serial.print(F("Loaded in "));
        Serial.print(millis() - startTime);
        Serial.println(" ms");
      } // end goodBmp
    }
  }

  bmpFile.close();
  if(!goodBmp) Serial.println(F("BMP format not recognized."));
}

// These read 16- and 32-bit types from the SD card file.
// BMP data is stored little-endian, Arduino is little-endian too.
// May need to reverse subscript order if porting elsewhere.

uint16_t read16(File &f) {
  uint16_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read(); // MSB
  return result;
}

uint32_t read32(File &f) {
  uint32_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read();
  ((uint8_t *)&result)[2] = f.read();
  ((uint8_t *)&result)[3] = f.read(); // MSB
  return result;
}

Libraries below. Clear any previous libraries before attempting to install.

ADAFRUIT_GFX.rar (7.83 KB)

Adafruit_ILI9341.rar (129 KB)

That’s more sensible pin connections - something much more logical. Loaded the new libraries (they were different plus I didn’t have the ILI9341 specific ones).

Ran the graphics test sample supplied in the new library as I didn’t want to get confused about reading the SD card.

Still no joy. Wired in Nano and UNO.

The readcommand8 function returns in the startup are as follows

ILI9341 Test!
Display Power Mode: 0x0
MADCTL Mode: 0x0
Pixel Format: 0x0
Image Format: 0x0
Self Diagnostic: 0x0

But then I get 0x0 returns when running the tests with the LCD unpowered. Had a run where the self diagnostic code was 0xFF but that’s gone now.

It runs through the tests in the sketch and the output to serial monitor works but the screen only displays a slightly grey background (same as when powering up) with not even a flicker .

If the Reset is connected to the Arduino reset then it doesn’t run at all. If its connected during a run it pauses the Arduino and when disconnected causes it to restart the sketch.

I have put my oscilloscope on the pins and see stuff happening except the MISO which I guess is expected(?). The input voltages on the scope indicate 3.2v (approx) at the LCD

Checked the wiring and waggled everything… :frowning:

/***************************************************
  This is our GFX example for the Adafruit ILI9341 Breakout and Shield
  ----> http://www.adafruit.com/products/1651

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/


#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10

// Hardware SPI
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// Uno, Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.
// MEGA pin 51 = MOSI, pin 50 = MISO, pin 52 = SCK.

void setup() {
  Serial.begin(9600);
  Serial.println("ILI9341 Test!"); 
 
  tft.begin();

  // read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDMADCTL);
  Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDPIXFMT);
  Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDIMGFMT);
  Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDSELFDIAG);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 
  
  Serial.println(F("Benchmark                Time (microseconds)"));

  Serial.print(F("Screen fill              "));
  Serial.println(testFillScreen());
  delay(500);

  Serial.print(F("Text                     "));
  Serial.println(testText());
  delay(3000);

  Serial.print(F("Lines                    "));
  Serial.println(testLines(ILI9341_CYAN));
  delay(500);

  Serial.print(F("Horiz/Vert Lines         "));
  Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
  delay(500);

  Serial.print(F("Rectangles (outline)     "));
  Serial.println(testRects(ILI9341_GREEN));
  delay(500);

  Serial.print(F("Rectangles (filled)      "));
  Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
  delay(500);

  Serial.print(F("Circles (filled)         "));
  Serial.println(testFilledCircles(10, ILI9341_MAGENTA));

  Serial.print(F("Circles (outline)        "));
  Serial.println(testCircles(10, ILI9341_WHITE));
  delay(500);

  Serial.print(F("Triangles (outline)      "));
  Serial.println(testTriangles());
  delay(500);

  Serial.print(F("Triangles (filled)       "));
  Serial.println(testFilledTriangles());
  delay(500);

  Serial.print(F("Rounded rects (outline)  "));
  Serial.println(testRoundRects());
  delay(500);

  Serial.print(F("Rounded rects (filled)   "));
  Serial.println(testFilledRoundRects());
  delay(500);

  Serial.println(F("Done!"));

}


void loop(void) {
  for(uint8_t rotation=0; rotation<4; rotation++) {
    tft.setRotation(rotation);
    testText();
    delay(10);
  }
}


FUNCTIONS REMOVED TO ALLOW FIT MESSAGE POSTING LIMIT
}