www.allpcb.com

Author Topic: 2.4 TFT screen  (Read 1170 times)

0 Members and 1 Guest are viewing this topic.

Offline dan3460

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: us
2.4 TFT screen
« on: February 14, 2017, 06:57:04 AM »
I bought a 2.4 TFT screen to test, it comes with a shield that fist on a UNO. I have been working on Atmel studio for a while and I found a few articles and libraries but I have not been able to find information regarding how this thing work. On LCDs like the 1602 there is some information about he pins and  the codes that the screen uses. Where is the information that people used to make the libraries?
This is a no name screen from China, that only cost $4.

Thanks for the help
 

Offline madires

  • Super Contributor
  • ***
  • Posts: 3305
  • Country: de
  • A qualified hobbyist ;-)
Re: 2.4 TFT screen
« Reply #1 on: February 14, 2017, 07:10:52 AM »
Do you know which controller it got? Color? Dots?
 

Offline phlip00ws6

  • Newbie
  • Posts: 1
  • Country: us
Re: 2.4 TFT screen
« Reply #2 on: February 14, 2017, 07:11:18 AM »
All you need to know is which controller it uses, most of these seem to use SPFD5408. If it does, you should be able to use any of the libraries associated with that controller.

People make the libraries based off the controller's data sheet.
 

Offline Dielectric

  • Regular Contributor
  • *
  • Posts: 87
  • Country: us
Re: 2.4 TFT screen
« Reply #3 on: February 14, 2017, 07:21:58 AM »
Does it look like this from Adafruit:
https://www.adafruit.com/product/1651

Or maybe this although it's not in shield form:
http://www.elecfreaks.com/estore/2-4-tft-lcd-tft01-2-4sp.html

It's quite possible that the board you have is a copy of one of those, or maybe another type.  At that size SPI interface is common, and the drivers are pretty easy to find via Arduino.  I grabbed one of those 1.8" libs and ported it into a PSoC4 without too much difficulty, I don't imagine it's much different.
 

Offline dan3460

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: us
Re: 2.4 TFT screen
« Reply #4 on: February 14, 2017, 09:26:29 AM »
Thanks guys, the two chips on the back are DP74HC245 and here is a picture of the screen.

 

Online Avacee

  • Regular Contributor
  • *
  • Posts: 133
  • Country: gb
Re: 2.4 TFT screen
« Reply #5 on: February 14, 2017, 09:42:05 AM »
The Adafruit TFT library works with these shields:  https://github.com/adafruit/TFTLCD-Library
Another library:  https://github.com/yamsam/TFTLCD_ST7781
Checked working on a screen I have here with HC245 chips.

FWIW: I no longer use these TFTs for much beyond simple text output.
Have a look at the Nextion screens which can be picked up from £8 (about $11).
https://nextion.itead.cc/
« Last Edit: February 14, 2017, 10:19:14 AM by Avacee »
 

Offline RoGeorge

  • Frequent Contributor
  • **
  • Posts: 304
  • Country: ro
Re: 2.4 TFT screen
« Reply #6 on: February 14, 2017, 11:07:27 AM »
I have a 2.4 LCD marked as mcufriend, too. The pinout is the same, and the PCB is almost the same as yours, but not identical.

Mine have a S6D0154 controller. The library was from 'https://github.com/samuraijap/TFTLCD-Library'. For Arduino UNO, you need to install both libraries attached, then replace the file 'pin_magic.h' from the installation folder 'libraries\TFTLCD-Library-master', with the 'pin_magic.h' file attached here.

Now you can run this demo to pick colors and draw using the touch screen:
Code: [Select]
// Paint example specifically for the TFTLCD breakout board.
// If using the Arduino shield, use the tftpaint_shield.pde sketch instead!
// DOES NOT CURRENTLY WORK ON ARDUINO LEONARDO

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>

#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif

// 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).
//   D0 connects to digital pin 22
//   D1 connects to digital pin 23
//   D2 connects to digital pin 24
//   D3 connects to digital pin 25
//   D4 connects to digital pin 26
//   D5 connects to digital pin 27
//   D6 connects to digital pin 28
//   D7 connects to digital pin 29

// For the Arduino Due, use digital pins 33 through 40
// (on the 2-row header at the end of the board).
//   D0 connects to digital pin 33
//   D1 connects to digital pin 34
//   D2 connects to digital pin 35
//   D3 connects to digital pin 36
//   D4 connects to digital pin 37
//   D5 connects to digital pin 38
//   D6 connects to digital pin 39
//   D7 connects to digital pin 40

#define YP A1  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 7   // can be a digital pin
#define XP 6   // can be a digital pin

#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4

// 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);

#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;

void setup(void) {
  Serial.begin(9600);
  Serial.println(F("Paint!"));
 
  tft.reset();
 
  uint16_t identifier = tft.readID();

    if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9327) {
    Serial.println(F("Found ILI9327 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 if(identifier == 0x0154) {
    Serial.println(F("Found S6D0154 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);

  tft.fillScreen(BLACK);

  tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED);
  tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW);
  tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN);
  tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN);
  tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE);
  tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA);
  // tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, WHITE);
 
  tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
  currentcolor = RED;
 
  pinMode(13, OUTPUT);
}

#define MINPRESSURE 10
#define MAXPRESSURE 1000

void loop()
{
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);

  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    /*
    Serial.print("X = "); Serial.print(p.x);
    Serial.print("\tY = "); Serial.print(p.y);
    Serial.print("\tPressure = "); Serial.println(p.z);
    */
   
    if (p.y < (TS_MINY-5)) {
      Serial.println("erase");
      // press the bottom of the screen to erase
      tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK);
    }
    // scale from 0->1023 to tft.width
    p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
    p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
    /*
    Serial.print("("); Serial.print(p.x);
    Serial.print(", "); Serial.print(p.y);
    Serial.println(")");
    */
    if (p.y < BOXSIZE) {
       oldcolor = currentcolor;

       if (p.x < BOXSIZE) {
         currentcolor = RED;
         tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*2) {
         currentcolor = YELLOW;
         tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*3) {
         currentcolor = GREEN;
         tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*4) {
         currentcolor = CYAN;
         tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*5) {
         currentcolor = BLUE;
         tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE);
       } else if (p.x < BOXSIZE*6) {
         currentcolor = MAGENTA;
         tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE);
       }

       if (oldcolor != currentcolor) {
          if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED);
          if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW);
          if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN);
          if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN);
          if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE);
          if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA);
       }
    }
    if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
      tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
    }
  }
}

For me, the starting point for doing all these was this page: http://forum.arduino.cc/index.php?topic=286790.15
« Last Edit: February 14, 2017, 11:09:16 AM by RoGeorge »
 

Offline madires

  • Super Contributor
  • ***
  • Posts: 3305
  • Country: de
  • A qualified hobbyist ;-)
Re: 2.4 TFT screen
« Reply #7 on: February 14, 2017, 09:29:18 PM »
I've seen that one also with ILI9325D and SPFD5408 (240x320, 262k colors). Another typical controller for that resolution is an  ILI9341/ILI9342. Possibly all work fine with the same driver since the command sets are quite similar.
 

Offline dan3460

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: us
Re: 2.4 TFT screen
« Reply #8 on: February 14, 2017, 11:48:35 PM »
Thanks for the answers, I did see most of those libraries but there are for Arduino. I'm not programing in arduino. I have not gotten into the details of those libraries, but porting them to plain C seems like a daunting task, that is the reason why I was looking for documentation to write my own library.
Seems to me that there is no library written for regular C.
 

Online Avacee

  • Regular Contributor
  • *
  • Posts: 133
  • Country: gb
Re: 2.4 TFT screen
« Reply #9 on: February 15, 2017, 12:02:49 AM »
Apologies - based on the limited information provided, namely usage of the Atmel Studio) the natural assumption was that you were using an Arduino.

To avoid an XY Problem (http://xyproblem.info/) what exactly are you trying to achieve? - you still haven't said what platform merely that you aren't using arduino and that you are using C.
 

Offline RoGeorge

  • Frequent Contributor
  • **
  • Posts: 304
  • Country: ro
Re: 2.4 TFT screen
« Reply #10 on: February 15, 2017, 12:25:27 AM »
There is no such thing like "The Arduino Language".

Arduino is C/C++, and it is using the GNU GCC compiler to compile what Arduino likes to call "sketches", or .ino file. Those "sketches" are just plain .c/.cpp files renamed as .ino. Don't ask me why they did that. So, you can take whatever "Arduino" library matches with your LCD controller, and use it in your own C project.

Writing an LCD driver without knowing what LCD controller is on that LCD board could become a daunting task. Better take an Arduino board, plug in your LCD, then find what library is working for your LCD model. That way you identify the LCD controller. After you identify the controller, and also test that you don't have a defective LCD board, then you can look in the "Arduino" library, to see haw it's made. Again, the Arduino libraries are usually plain text C/C++ source code. So far, I didn't saw any binary "Arduino" library. You can copy/past the library into your C project, or write your own LCD driver if that is what you want. That is how I would do it.

Offline madires

  • Super Contributor
  • ***
  • Posts: 3305
  • Country: de
  • A qualified hobbyist ;-)
Re: 2.4 TFT screen
« Reply #11 on: February 15, 2017, 12:37:57 AM »
The typical workflow is:
- identify the controller
- download the datasheet
- check for available drivers/libs (could be used as sample code and to understand how the controller works in case of a poor datasheet)
- use available driver/lib or write your own driver/lib
 

Offline picandmix

  • Frequent Contributor
  • **
  • Posts: 299
  • Country: gb
Re: 2.4 TFT screen
« Reply #12 on: February 15, 2017, 02:20:47 AM »
Perhaps why it only costs $4 .

With such screens knowing the chipset and that libraries are readily available for it is the key factor.

What  chips are you trying to program as only now have you told us you are coding in C, against the original impression it was Arduino.
 

Offline dan3460

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: us
Re: 2.4 TFT screen
« Reply #13 on: February 15, 2017, 03:07:12 AM »
Apologies - based on the limited information provided, namely usage of the Atmel Studio) the natural assumption was that you were using an Arduino.

To avoid an XY Problem (http://xyproblem.info/) what exactly are you trying to achieve? - you still haven't said what platform merely that you aren't using arduino and that you are using C.

My apologies, right now i'm just exploring and experimenting. I'm using AVR chips and writing on Atmel Studio C. What i'm trying to achieve is to be able to write something to the screen.

There is no such thing like "The Arduino Language".

Arduino is C/C++, and it is using the GNU GCC compiler to compile what Arduino likes to call "sketches", or .ino file. Those "sketches" are just plain .c/.cpp files renamed as .ino. Don't ask me why they did that. So, you can take whatever "Arduino" library matches with your LCD controller, and use it in your own C project.


I do understand that, I move away form the arduino eviroment a couple of years ago. I used Eclipse with the Arduino EDI for a while, but I moved to Atmel Studio. It is possible to port Arudino libraries to Atmel but I think you still have to ticker with it and not knowing if it will work you never know if there is a problem with the code or actually the library doesn't work with this particular screen.

The typical workflow is:
- identify the controller
- download the datasheet
- check for available drivers/libs (could be used as sample code and to understand how the controller works in case of a poor datasheet)
- use available driver/lib or write your own driver/lib

I understand the process, but in this case I could not find any documentation on the chipset used. Therefore to test, I wanted to use a library to see if works, if it doesn't pick another library and see if works, etc.

To summarize:
- Writing C Using Atmel Studio
- Looking for either the documentation of this chip or libraries written in plain C but not for the arduino environment.
- Thanks to everyone for the input.


 

Offline dan3460

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: us
Re: 2.4 TFT screen
« Reply #14 on: February 18, 2017, 12:49:46 AM »
I have not been able to find a library that has been written for 8 bit bus, so I'm working on retooling a SPI library to work with 8 bit bus.
I got most of the library rewritten but I have not bee successful in making anything happen on the screen. Right now i'm using ILI9341 datasheet and tonight i'm setting up the screen on a breadboard so I can poke the connectors with my logic analyzer to see what is happening on the pins.
My main confusion is with the naming of the pins, the data pins are fine they are labeled LCD_D0 to LCD_D7. What i'm trying to sort out are the control pins:
LCD_RST I'm guessing that is a hardware reset but bringing that pin down or high does nothing to the screen.
LCD_RD and LCD_WR, I think there are the only ones that i'm certain are RDX and WRX.
My problem is with LCD_RS and LCD_CS, on the datasheet there are CSX (chip select) and C/DX (Command/Data). I'm assuming that LCD_RS is C/DX. Is that correct?
 

Offline madires

  • Super Contributor
  • ***
  • Posts: 3305
  • Country: de
  • A qualified hobbyist ;-)
Re: 2.4 TFT screen
« Reply #15 on: February 18, 2017, 01:04:39 AM »
Most of the graphic LCD controllers support parallel and serial interfaces which are selected by a few mode pins. On some boards the interface selection is hardwired, some require you to select it. I'd guess your board also supports SPI. If you're new to LCD modules this might be confusing, but after a few LCDs you'll become familar with this. And learning Chinglish helps too :)

Your assumptions about the pins for the parallel interface seem to be correct.
« Last Edit: February 18, 2017, 01:06:39 AM by madires »
 

Offline dan3460

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: us
Re: 2.4 TFT screen
« Reply #16 on: February 18, 2017, 02:43:27 AM »
The main problem is that I have not been able to find anything on the chips that this screen uses. So far I have been using the regular 1x16, 2x16 or 4x16 LCDs, and normally using a I2C backpack, but in a few more weeks I'm starting a project that I want to have a TFT main screen.
I probably end up using a ISP or I2C screen at the end, but is a nice challenge to make this thing work.
 

Offline madires

  • Super Contributor
  • ***
  • Posts: 3305
  • Country: de
  • A qualified hobbyist ;-)
Re: 2.4 TFT screen
« Reply #17 on: February 18, 2017, 03:41:22 AM »
The graphic LCD modules got a similar command interface but don't include a font set like the HD44780. You have to set each dot yourself, i.e. you need to add a font to your code.
 

Offline dan3460

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: us
Re: 2.4 TFT screen
« Reply #18 on: February 18, 2017, 04:36:30 AM »
Yes, I was aware of that. My main concern right now is to just get this thing working, i'll figure out the writing later.
 

Offline donotdespisethesnake

  • Frequent Contributor
  • **
  • Posts: 402
  • Country: gb
  • Embedded stuff
Re: 2.4 TFT screen
« Reply #19 on: February 18, 2017, 06:23:17 AM »
The main problem is that I have not been able to find anything on the chips that this screen uses.

Do you mean sample code or data sheets? Both are fairly easy to find with google once you know the controller number. "Arduino code" is easily converted to "regular" C++ or even C.

The LCD controller is usually part of the display itself (COG) and so is not readily readable. Google image search is useful to match up controller with boards, the form factor is often a better template than whatever is on the silkscreen. The chances are that someone somewhere has bought the same board and has the same questions.

Note that manufacturers often switch controllers depending on availability, so I would strongly recommend writing the controller number on the board when you identify it, and don't assume if you buy the board or a similar one 6 months later it will have the same controller!
Bob
 

Offline MickM

  • Regular Contributor
  • *
  • Posts: 98
Re: 2.4 TFT screen
« Reply #20 on: February 18, 2017, 10:18:05 AM »
Hi;
 http://mcufriend.com/shop/html/?12.html
Shows ILI9341 / ILI9325.

 

Offline dan3460

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: us
Re: 2.4 TFT screen
« Reply #21 on: February 19, 2017, 12:01:13 AM »
I have been working on this thing, first a couple of answers.
- I know that Arduino code can be "easily" converted to regular C, but not knowing exactly what chip is on this thing and some of the libraries have extensive use of the "Arduino.h" header I see my self with hours of translating something that will not work.
- The link posted shows and ILI9341, my board has a DP74HC245, also the number of chips do not match the picture that I posted earlier.

Now this is where am i: I have been sending commands to the pins but I don't have life on the screen yet. One of my questions is the LCD_RST line, I'm not clear of the line should be high or low for operation. I was expecting some flickering of the screen when you tickle this line but don't see any thing. I'm new working with kind of screens, should I see flickering when doing a hardware reset?

Attached are a couple of screen shoots for the reset command and  the software reset command (0x01).
 

Offline madires

  • Super Contributor
  • ***
  • Posts: 3305
  • Country: de
  • A qualified hobbyist ;-)
Re: 2.4 TFT screen
« Reply #22 on: February 19, 2017, 12:35:56 AM »
/RES is low active.
 

Online Avacee

  • Regular Contributor
  • *
  • Posts: 133
  • Country: gb
Re: 2.4 TFT screen
« Reply #23 on: February 19, 2017, 12:42:24 AM »
My board has HC245 chips - see photo below.
As posted in reply #5 it works with the Adafruit and UTFT libraries.
I appreciate this is "arduino code" but the constructor and init() routines show what lines should be set low/high.

If you think our boards match and it would help I can hook up the LA and record the activity the arduino sends to my screen.




 

Offline dan3460

  • Frequent Contributor
  • **
  • Posts: 324
  • Country: us
Re: 2.4 TFT screen
« Reply #24 on: February 19, 2017, 01:09:24 AM »
Life... :)

I was looking at the initialization code and a few of the commands did not match with the datasheet. Now that I know that is working I have to reformat my library so it can be used with other screens. Will post the library at the end if anyone is interested.

Thanks everyone for your help.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf