2.4 TFT screen - Page 1
Forum section: electronics / general

author: dan3460
author_rank: Frequent Contributor
timestamp: February 13, 2017, 07:57:04 pm
content: 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

author: madires
author_rank: Super Contributor
timestamp: February 13, 2017, 08:10:52 pm
content: Do you know which controller it got? Color? Dots?

author: phlip00ws6
author_rank: Newbie
timestamp: February 13, 2017, 08:11:18 pm
content: 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.

author: Dielectric
author_rank: Regular Contributor
timestamp: February 13, 2017, 08:21:58 pm
content: Does it look like this from Adafruit:https://www.adafruit.com/product/1651Or maybe this although it's not in shield form:http://www.elecfreaks.com/estore/2-4-tft-lcd-tft01-2-4sp.htmlIt'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.

author: dan3460
author_rank: Frequent Contributor
timestamp: February 13, 2017, 10:26:29 pm
content: Thanks guys, the two chips on the back are DP74HC245 and here is a picture of the screen.

author: Avacee
author_rank: Unknown
timestamp: February 13, 2017, 10:42:05 pm
content: The Adafruit TFT library works with these shields:https://github.com/adafruit/TFTLCD-LibraryAnother library:https://github.com/yamsam/TFTLCD_ST7781Checked 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/

author: RoGeorge
author_rank: Super Contributor
timestamp: February 14, 2017, 12:07:27 am
content: 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:// 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 plateTouchScreen 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:#defineBLACK 0x0000#defineBLUE 0x001F#defineRED 0xF800#defineGREEN 0x07E0#define CYAN 0x07FF#define MAGENTA 0xF81F#define YELLOW 0xFFE0#define WHITE 0xFFFFAdafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);#define BOXSIZE 40#define PENRADIUS 3int 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 1000void 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 erasetft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK);}// scale from 0->1023 to tft.widthp.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

author: madires
author_rank: Super Contributor
timestamp: February 14, 2017, 10:29:18 am
content: 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.

author: dan3460
author_rank: Frequent Contributor
timestamp: February 14, 2017, 12:48:35 pm
content: 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.

author: Avacee
author_rank: Unknown
timestamp: February 14, 2017, 01:02:49 pm
content: 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.

author: RoGeorge
author_rank: Super Contributor
timestamp: February 14, 2017, 01:25:27 pm
content: 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.

author: madires
author_rank: Super Contributor
timestamp: February 14, 2017, 01:37:57 pm
content: 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

author: picandmix
author_rank: Frequent Contributor
timestamp: February 14, 2017, 03:20:47 pm
content: 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.

author: dan3460
author_rank: Frequent Contributor
timestamp: February 14, 2017, 04:07:12 pm
content: Quote from: Avacee on February 14, 2017, 01:02:49 pmMy 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.Quote from: RoGeorge on February 14, 2017, 01:25:27 pmI 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.Quote from: madires on February 14, 2017, 01:37:57 pmI 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.

author: dan3460
author_rank: Frequent Contributor
timestamp: February 17, 2017, 01:49:46 pm
content: 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?

author: madires
author_rank: Super Contributor
timestamp: February 17, 2017, 02:04:39 pm
content: 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 tooYour assumptions about the pins for the parallel interface seem to be correct.

author: dan3460
author_rank: Frequent Contributor
timestamp: February 17, 2017, 03:43:27 pm
content: 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.

author: madires
author_rank: Super Contributor
timestamp: February 17, 2017, 04:41:22 pm
content: 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.

author: dan3460
author_rank: Frequent Contributor
timestamp: February 17, 2017, 05:36:30 pm
content: 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.

author: donotdespisethesnake
author_rank: Super Contributor
timestamp: February 17, 2017, 07:23:17 pm
content: Quote from: dan3460 on February 17, 2017, 03:43:27 pmDo 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!

author: MickM
author_rank: Regular Contributor
timestamp: February 17, 2017, 11:18:05 pm
content: Hi;http://mcufriend.com/shop/html/?12.htmlShows ILI9341 / ILI9325.

author: dan3460
author_rank: Frequent Contributor
timestamp: February 18, 2017, 01:01:13 pm
content: 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).

author: madires
author_rank: Super Contributor
timestamp: February 18, 2017, 01:35:56 pm
content: /RES is low active.

author: Avacee
author_rank: Unknown
timestamp: February 18, 2017, 01:42:24 pm
content: 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.

author: dan3460
author_rank: Frequent Contributor
timestamp: February 18, 2017, 02:09:24 pm
content: 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.