mcufriend 2.8 tft lcd shield library quotation

I have bought "MCUFRIEND" 2.8 tft touch lcd and controller printed on it shows "ILI9338". Example given in this library are not working except for the basic one and it don"t even work with touch examples. After searching on google found out that "MCUFRIEND_kbv" library for debug. When i run "diagnose_tft_support" it shows following output. Also added "Read reg" after first output. Please Help !!!

mcufriend 2.8 tft lcd shield library quotation

Displaying a custom image or graphic on a LCD display is a very useful task as displays are now a premium way of providing feedback to users on any project. With this functionality, we can build projects that display our own logo, or display images that help users better understand a particular task the project is performing, providing an all-round improved User Experience (UX) for your Arduino or ESP8266 based project. Today’s tutorial will focus on how you can display graphics on most Arduino compatible displays.

The procedure described in this tutorial works with all color displays supported by Adafruit’s GFX library and also works for displays supported by the TFTLCD library from Adafruit with little modification. Some of the displays on which this procedure works include:

For this tutorial, we will use the 2.8″ ILI9325 TFT Display which offers a resolution of 320 x 340 pixels and we will display a bitmap image of a car.

To demonstrate how things work, we will use the 2.8″ TFT Display. The 2.8″ TFT display comes as a shield which plugs directly into the Arduino UNO as shown in the image below.

Not all Arduino displays are available as shields, so when working with any of them, connect the display as you would when displaying text (we recommend following the detailed tutorial for the display type you use of the above list). This means no special connection is required to display graphics.

Image2Code is an easy-to-use, small Java utility to convert images into a byte array that can be used as a bitmap on displays that are compatible with the Adafruit-GFX or Adafruit TFTLCD (with little modification) library.

To reduce the amount of code, and stress involved in displaying the graphics, we will use two wonderful libraries; The GFX library and the TFTLCD library from Adafruit.

The GFX library, among several other useful functions, has a function called drawBitmap(), which enables the display of a monochrome bitmap image on the display. This function allows the upload of monochrome only (single color) graphics, but this can be overcome by changing the color of the bitmap using some code.

The Adafruit libraries do not support all of the displays but there are several modifications of the libraries on the internet for more displays. If you are unable to find a modified version of the library suitable for your the display, all you need do is copy the code of the drawBitmap() function from the GFX library and paste it in the Arduino sketch for your project such that it becomes a user-defined function.

As usual, we start writing the sketch by including the libraries required. For this procedure, we will use the TFTLCD library alone, since we are assuming you are using a display that is not supported by the GFX library.

The last section of the code is the drawBitmap function itself, as earlier mentioned, to use the drawbitmap() function with the Adafruit TFTLCD library, we need to copy the function’s code and paste into the Arduino sketch.

mcufriend 2.8 tft lcd shield library quotation

Features: 2.4 diagonal LCD TFT display Bright, 4 white-LED backlight, on by default but you can connect the transistor to a digital pin for backlight control Colorful, 18-bit 262,000 dierent shades 4-wire resistive touchscreen 240320 resolution spfd5408 controller with built in video RAM buer 8 bit digital interface, plus 4 control lines Uses digital pins 5-13 and analog 0-3. That means you can use digital pins 2, 3 and analog 4 and 5. Pin 12 is available if not using the micro SD 5V compatible, use with 3.3V or 5V logic Onboard 3.3V @ 300mA LDO regulator Speci cations: Size: 71*52*7mm Weight: about 31gLibraries Included (Kind of)

The shield came packed with one of those tiny CD ROM discs with a few dierent RAR les on it. The one with arduino-UNO in the name seemed like the most likelycandidate, so I opened it up and started poking around.

After some trial and error, including nding the correct library, changing library names, altering include le references, etc., I managed to get something on the screen. I made many small tweaks to the LCD library to make my life a little easier (see below), but the many references to Adafruit in the code led me to give their web site a look. There I found a library for a 2.8 touch screen that looks very similar to this one. Im not sure the code in their libraries will work without modication, but they may be worth taking a look at.

Compare the original image below to the 16-bit screen representation to its right. While the picture of the LCD screen doesnt really do it justice, it should give you anidea of what youll see. The rst thing that will likely draw your attention about the screen image is the very noticeable banding. This becomes less apparent with linedrawings using a simpler color palette, but it is very visible when viewing bitmaps or lling the screen with a solid color.

SD Card SlotThe shield comes equipped with a micro SD card slot, which I really had no real intention of using when I bought it. My curiosity quickly took over, however, and I triedto run some of the sample code. Unfortunately, I didnt meet with any success during my initial attempts to get it working and threw in the towel completely afterpushing a bit too hard on the card as I inserted it, breaking the connector o the board.

Im still not sure exactly what driver chip my LCD is using. The libraries included with the unit expand into a directory called arduino-9320. I originally took this tomean that it used the ILI9320 chip and started working from the data sheet I found here to expand functionality as needed. However, some of the sample code does adriver check before proceeding, as follows:

1 // find the TFT display ? 2 uint16_t identifier = tft.readRegister(0x0); 3 if (identifier == 0x9325) { 4 Serial.println("Found ILI9325"); 5 } else if (identifier == 0x9328) { 6 Serial.println("Found ILI9328"); 7 } else { 8 Serial.print("Unknown driver chip "); 9 Serial.println(identifier, HEX); 10 while (1); 11 }

I have made some modications to the library included with the board, and Ill include my les below. It wasnt until after Id started monkeying with things andnoticing references to Adafruit in the code, that I realized there may be better options already out there. Whether or not they work with this screen is something I haveyet to determine.

The TFT library includes functions for drawing lines, rectangles, rounded rectangles, circles and triangles, all of which can be lled or outlined. There is example codethat cycles through various screen patterns using each.

After I got the SD card reader working, I spent some time concentrating on loading bitmaps. The sample code that comes with the library has a few examples that load24-bit bitmap les from the SD card and display them on the screen in various rotations. These samples didnt work correctly until I modied the code to use thesetPixel method, which resulted in a very slow display time but worked in all screen rotations.

The writeData method that was originally being invoked simply writes to the displays graphics memory, which is a good thing for speed. However, this method was nottaking screen rotation into account. Studying the data sheet, I found that GRAM Access Direction can be altered such that after a writeData call, the next writeaddress will be properly calculated based on the current rotation. With that information, I modied the setRotation method to also change the GRAM access direction.This new setRotation method xed the bitmap sample code to some extent and sped things up considerably. Unfortunately, it was still taking 2.8 seconds to load anddisplay a 320200 24-bit bitmap. It was time to get serious.

The rs thing I did was switch away from the 24-bit bitmap format. The display uses a 16-bit RGB format (R5G6B5), so it makes more sense to do that transformationsomewhere other than the Arduino if youre just worried about getting it onto the screen as quickly as possible. Furthermore, the standard Windows bitmap le isstored in a bottom-up format, which adds a little complexity to the direct write method. So, I wrote a little utility to convert my bitmap les to a 16-bit, top-downformat that could be directly loaded into the LCDs GRAM. You can nd that utility here.

Moving to the 16-bit format had a huge impact on performance, though I didnt think to take any timings in this state, as I wasnt quite done. My next step was tosimplify loading by getting rid of the position calculations required for bitmaps that didnt extend the entire width of the screen. The data sheet provides details aboutcreating a window within the screen, which you can specify the dimensions of. Combining this window setting with the GRAM access direction settings mentionedabove, it is possible to just send the pixel information in bulk and allow the LCD driver chip handle the wrapping.

The end result is fast, loading and displaying a 320240 scooter image in 1.3 seconds and the smaller picture over the top in 129 milliseconds. Ive since beenexperimenting with the sdfatlib library for SD card access, and the results have improved even further, bringing load/display time to 1.048 seconds. I was looking morefor a smaller footprint, but Ill take the the speed as well.Arduino Code

1 void displayBitmap(int x, int y) ? 2 { 3 uint16_t bx, ex, by, ey; 4 uint32_t time = millis(); 5 6 // Raw pixel data starts at position 8 7 bmpFile.seek(8); 8 9 // Save the current viewport settings and set 10 tft.getViewport(&bx, &ex, &by, &ey); 11 tft.setViewport(x, y, x + bmpWidth - 1, y + bmpHeight - 1); 12 tft.goTo(x, y); 13 14 // Bulk write data to LCD, loadBitmapData is a callback to refill buffer 15 int bytesRead = loadBitmapData(NULL); 16 tft.bulkWrite( (uint16_t *) picBuffer, bytesRead, loadBitmapData, NULL); 17 18 // Leave the viewport like we found it 19 tft.setViewport(bx, ex, by, ey); 20 21 Serial.print("Total time: "); 22 Serial.println(millis() - time, DEC); 23 24 }

1 // Writes 16-bit data in bulk, using callback to get more ? 2 void TFTLCD::bulkWrite(uint16_t *data, uint16_t bufferSize, uint16_t (*getNextValues)(void *), void *userData) 3 { 4 *portOutputRegister(csport) &= ~cspin; 5 *portOutputRegister(cdport) |= cdpin; 6 *portOutputRegister(rdport) |= rdpin; 7 *portOutputRegister(wrport) |= wrpin; 8 9 setWriteDir(); 10 while( bufferSize ) 11 { 12 for(uint16_t i=0; i < bufferSize; i++) 13 { 14 writeData_unsafe(data[i]); 15 } 16 bufferSize = getNextValues(userData); 17 } 18 *portOutputRegister(csport) |= cspin; 19 }

The display and touch screen features were what I was really looking for from this LCD, though I became somewhat sidetracked by the bitmap examples. The touchscreen example software ran pretty much without a hitch from the beginning using the pin settings for the shield. Essentially, you get two coordinates (X and Y) backfrom the screen, plus a Z, which indicates the pressure being applied. Those coordinates coincide with the LCDs default rotation, which is with the Arduinos USB plugon top in this case, so youll have to adjust those for yourself.

1 #include "TouchScreen.h" ? 2 3 // These are the pins for the shield! 4 #define YP A1 // must be an analog pin, use "An" notation! 5 #define XM A2 // must be an analog pin, use "An" notation! 6 #define YM 7 // can be a digital pin 7 #define XP 6 // can be a digital pin 8 9 #define MINPRESSURE 10 10 #define MAXPRESSURE 1000 11 12 // For better pressure precision, we need to know the resistance 13 // between X+ and X- Use any multimeter to read it 14 // For the one we"re using, its 300 ohms across the X plate 15 TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

The one potential area for trouble is the fact that the touch screen shares pins with the LCD. So, if you invoke methods from the touch screen library, then make calls tothe LCD library, you may get unexpected results, as the touch screen library doesnt always leave things in the right state, and the LCD library doesnt put them in theright state before it does its work. The newer Adafruit libraries may account for this better than the ones Im using, but Ive worked around it for now.

1 Point getPressPosition() ? 2 { 3 4 Point p, q; 5 int upCount = 0; 6 7 // Wait for screen press 8 do 9 { 10 q = ts.getPoint(); 11 delay(10); 12 } while( q.z < MINPRESSURE || q.z > MAXPRESSURE ); 13 14 // Save initial touch point 15 p.x = q.x; p.y = q.y; p.z = q.z; 16 17 // Wait for finger to come up 18 do 19 { 20 q = ts.getPoint(); 21 if ( q.z < MINPRESSURE || q.z > MAXPRESSURE ) 22 { 23 upCount++; 24 } 25 else 26 { 27 upCount = 0; 28 p.x = q.x; p.y = q.y; p.z = q.z; 28 p.x = q.x; p.y = q.y; p.z = q.z; 29 } 30 31 delay(10); // Try varying this delay 32 33 } while( upCount < 10 ); // and this count for different results. 34 35 p.x = map(p.x, tsMinX, tsMaxX, 0, 239); 36 p.y = map(p.y, tsMinY, tsMaxY, 0, 319); 37 38 // I"ve been focused on rotation 3, with the USB connector on the right-hand side 39 // so, you"ll have to add your own code here. 40 switch( ROTATION ) 41 { 42 case 3: 43 swap(p.x, p.y); 44 p.x = (320 - p.x); 45 break; 46 } 47 48 // Clean up pin modes for LCD 49 pinMode(XM, OUTPUT); 50 digitalWrite(XM, LOW); 51 pinMode(YP, OUTPUT); 52 digitalWrite(YP, HIGH); 53 pinMode(YM, OUTPUT); 54 digitalWrite(YM, LOW); 55 pinMode(XP, OUTPUT); 56 digitalWrite(XP, HIGH); 57 58 return p; 59 }SD Card

As I mentioned, the SD card wasnt something I was necessarily looking for from this shield, but it has proven to be a blessing. It works with the standard Arduino SDlibrary, and Ive also tried the sdfatlib with great results. The cable select should be set to pin 10, and after that, youre ready to go. There is an example calledlistles that spits out a directory listing, which is great for both testing that the card works, and as a reminder that youre limited abbreviated le names that turn aname like BURG_BLUE.BMP into BURG_B~1.BMP.

I have attached the TFTLCD libraries with the modications Ive made for rotation and positioning reliability as well as the bulk data load function Im using fordisplaying bitmaps. Sample sketches are also included and should work with this LCD without modication.

There seem to be variants of this shield that look the same or similar but function dierently. Many users have had issues with reversed text and coordinate ippingusing the same library I originally provided. In the comments, Mike McCauley added a link to a patched version of the library that may x reverse coordinate issues. Ihave now added his patch into my library to avoid further confusion.

I was able to get this screen working as a shield with an Arduino Mega 2650 as well. I posted an article with an updated source le. Until I get some feedback, Illconsider it experimental. The article is here.

You may also like:Adding Mass Actions to Magento Bitmap Converter for Arduino LCD Touch Screen Shield for ArduinoOrders UNO

How did you go with the touchscreen code? I have the same shield but only get double characters when I press a number (doing the touch numeric keyboard thing aswell).Cheers,Darren.

Hey Justin Great post.I got the same lcd and my lcd co-ordinates appear reversed.I uncommented either and both of//#dene INVERT_X//#dene INVERT_Y these lines but it didnt work.It seems changing anything in TFTLCD.cpp le doesnt aect the code. Please help me . I am stuck at the same point from two weeks.

What do I need to compile the bmp2lcd utility in Windows? Can I use Atmel Studio or do I need another compiler? I want to try your 16 bit bmp method but dont knowexactly what to compile the source with.

Wow. Theres part of me that wonders if its even reading the register correctly. Im playing with the Adafruit library, and thats returning 0x0 for the ID, though Ivegotten it to produce graphics on the screen by forcing it to initialize properly. Sebastian December 28, 2013

Hi! Your work here helped me a lot! Right now Im modifying the Adafruit library to work with this shield, I replaced part of the code on the Adafruits with the_regValues[] and the initScreen from the CDs library and it worked! But I have the problem that X axis is mirrored, so the characters look backwards. If you havemade something to solve this orientation problem, it would help me a lot!

First, your English is great. I ran into the same problem with the Adafruit library when I tried it, but I havent had a chance to get back in and see what can be done to xthe backwards problem. Once the holiday season has passed and I get back to normal life, Ill take another look and update you.

I just picked up this same lcd. I also noticed that text is upside down and backwards. I discovered this blog (which is much appreciated, btw) because I was googlingspfd5408 arduino backwards. However, Im not certain that our displays are identical. Mine has some printed icons on the bottom and is intended to be used in aphone, in a portrait orientation. Im sure you would have mentioned if the text in the example program didnt appear correct.Any hooI started thinking about how the text in the graphic demo is displaying on MY screen. X=0 and Y=0 is actually the bottom left (when viewed in portrait). But I wouldprefer that the origin be at the top left and the display be viewed in a landscape orientation. So I looked at the code in TFTLCD.cpp for drawing characters and stringsand swapped X and Y by adding this line (as the rst line) to drawString() and drawChar():uint16_t t = x;x=y;y=t;

That works, but the fonts are sideways. So I then looked at the hex in glcdfont.cpp. For a moment, but only a moment, I considered that I really needed completelydierent font codes. The I looked more closely at drawChar() and just swapped the counters used to walk through the bits of each hex codevoid TFTLCD::drawChar(uint16_t x, uint16_t y, char c,uint16_t color, uint8_t size) {uint16_t t = x;x=y;y=t;//xy

Unfortunately, my coding skills are still in their infancy and I am unclear on implementing the changes you suggest I know how to edit the les, just not the preciselocation of any changes and /or additions to the code. I took a few stabs at it, but just get compiling errors. Any chance on further clarication of the exact changesrequired in the TFTLCD.ccp, and/or updated libraries?

I have been downloaded your library in rar format. It compiles satisfactorily problem is that SD Card is not working properly. The message shown by Arduino serial portmonitor is SD Card initilization failed. Although I selected proper chip select of SD Card. Kindly, tell me how can I achieve this goal. Your prompt reply is highlyappreciated.

Hi,I have the very same display (2 of them), Ive tried to download your library but my display stay stubbornly blank Ive tried on arduino uno, a clone of uno Butnothingh !

Thanks for your help, Ive tried your library and adafruit but I was not lucky. Perhaps I should start from scratch, or perhaps I was plainly cheated !

I really thank you for your really great work, im quite new at the Arduino world, so its impossible for me to make this type of things . I have the same shield/screen,and your library works really well, but there are stil 2 problems: I read in some comments above that some persons have the text upside down, and i have the same problem. As im new, i couldnt understand whats the solution, socould you please explain a bit how to solve it? I didnt understand how to use the touchscreen. Im using the Arduino Mega2560, so im using the pins a)-A4 and 22-29. which pins are used by the touchscreen, andhow do I use it? i saw that it shares pins with the LCD, but even if you explained somehow how to use it, im not an expert and cant use it

1. Go at the library folder, named TFTLCD;2. Open the le named TFTLCD.cpp with any text editor;3. Search for the function void TFTLCD::drawChar(uint16_t x, uint16_t y, char c, uint16_t color, uint8_t size) { [];4. Delete these lines:

void TFTLCD::drawChar(uint16_t x, uint16_t y, char c,uint16_t color, uint8_t size) {for (uint8_t i =0; i<5; i++ ) {uint8_t line = pgm_read_byte(font+(c*5)+i);for (uint8_t j = 0; j>= 1;}}}

void TFTLCD::drawChar(uint16_t x, uint16_t y, char c,uint16_t color, uint8_t size) {uint16_t t = x;x=y;y=t;for (uint8_t i =0; i<5; i++ ) {uint8_t line = pgm_read_byte(font+(c*5)+i);for (uint8_t j = 0; j>= 1;}}}

void TFTLCD::drawChar(uint16_t x, uint16_t y, char c,uint16_t color, uint8_t size) {uint16_t t = x;x=y;y=t;for (uint8_t i =0; i<5; i++ ) {uint8_t line = pgm_read_byte(font+(c*5)+i);for (uint8_t j = 0; j>= 1;}}}

I hope it is clear, and hope itll be useful for some of you. Now it works ne for me, this library is really perfect!For the touchscreen library, i still dont get itThanks in advance for your future reply, Justin! (and maybe another person?)

// draw a charactervoid TFTLCD::drawChar(uint16_t x, uint16_t y, char c,uint16_t color, uint8_t size) {for (uint8_t i =0; i<5; i++ ) {uint8_t line = pgm_read_byte(font+(c*5)+i);for (uint8_t j = 0; j>= 1;}}}

// draw a charactervoid TFTLCD::drawChar(uint16_t x, uint16_t y, char c,uint16_t color, uint8_t size) {for (uint8_t i =0; i<5; i++ ) {uint8_t line = pgm_read_byte(font+(c*5)+i);for (uint8_t j = 0; j>= 1;}}}

Thanks for this library.I too got some of the cheap LCD screens marked with http://www.mcufriend.com, and I too get reversed text.But further tests, such as the included tftpaint show that the Y coordinates are reversed.Further investigation shows that on my devices the direction of the Y coordinates is reversed to that expected by the library.So, its not sucient to just alter drawText as described above, but to make some similar changes to the low-level drawing routines.I have made appropriate changes to the library to suit my device, in a modular way so it will now support devices with and without X and/or Y coordinate ipping. Note:this is not the same issue as the orientation feature added by Pierre. I have also included the TouchScreen code used by the examples.All the included examples now compile and run correctly out of the box.http://www.airspayce.com/mikem/TFTLCD-mikem.zip Steven February 13, 2014

Thanks man, I just got this lcd yesterday and tried to make this work for few hours :D, but unfortunately when it started to work the image was mirrored. But theTouchScreen les are corrupted, the program wont compile when they are in the library folder, theres no problem after removing them so maaaaany thanks :).

hey! i have downloaded justins as well as mikes code. in justins code there is a pin LCD_CD dened on the pin A2, but theres no such pin on the LCD, where does it goexactly? can someone please help me ASAP? i am using the exact shield that justin has put up on the blog.

Hi, I have got this screens today 2 of them, but after loading test sketch, screen just blink and does not do anything else. Im running it on Arduino Mega with modiedTFTLCD.cpp from this topic: http://misc.ws/2014/06/26/touch-screen-on-the-arduino-mega-2560/, what could be wrong? Ken Wagnitz February 27, 2014

Thanks to Justin and Mike.I got here from the APC article, after buying a few of the screens to try.Mine look like the one in Justins photo, but exhibited the mirror-imaged text in the graphics test sketch.Mikes library xed that. Now to try touchscreen and SD slot

No luck getting touch input to work. Your sketch comments say to use a multimeter to read the X+ to X- resistance. But you dont say where to measure. The exiblestrip going away from the screen has its insulated side on the outside. I presume the pins going to the Arduino arent analog voltages in? Anyway, I guess poorcalibration would only mean wrong screen position reported, I dont see any response, either on the screen or on the serial monitor. Incidentally I had to set font[] to aconst in glcdfont.c to compile. (Using Mikes library.)Should the screen drop in brightness when running your KeypadTest sketch? Resetting briey brings it up to full brightness. -Or is that an indication I have a pinmismatch with your code?Could be that I have brummy screens. (I have 3.)

The notes in the other sketch about measuring with the multimeter are not mine, Im afraid. Those were in the sketch originally, and I didnt remove them. It looks likeyou should measure between the pins mentioned in the touch screen set-up denes. So, in the example below, I would measure between the A2 pin (X-, LCD_RS) anddigital pin 6 (X+, LCD_D6). I just did so on my board, and it read 326 ohms.

I just updated my download to include the patched version of the library that provides for coordinate ipping. Please update your library and change the denes asneeded to see if it helps. I updated the post with instructions as well.

I have a new arduino mega. I try to make the LCD to work but with no luck. The LCD remaining white. I test it on an arduino uno and work like a charm. Could anyonehelp me??

//codeuint16_t identier = tft.readRegister(0x0);if (identier == 0x9325) {Serial.println(Found ILI9325);} else if (identier == 0x9328) {Serial.println(Found ILI9328);} else {Serial.print(Unknown driver chip );Serial.println(identier, HEX);while (1);}

Hi Guys.Ive searched for the entire web, and found this site. Unfortunaly My board didnt work with any of your tips. In my last hope, I post my problem in the Arduino google+page and, in minutes, I received a tip about this site:http://www.smokeandwires.co.nz/blog/a-2-4-tft-touchscreen-shield-for-arduino/A voil, the board worked like a charm.I hope this tip help more people like me.

Thanks Julio Ferreira for the Smoke and Wires link, this is the only implementation that gave me any results. It worked awlessly whereas all others failed miserably. Myquest for a cheap LCD (from ebay and was the blue mcufriend.com 2.8 inch touchscreen) has nally come to a close.

Hi, First of all let me tell you that I nd your website very informative.I purchased some of these screens a while ago, and I just nally realized I couldnt use the library from Adafruit and started trying to nd the info like crazy.I found your block and while I got it working, using everyones corrections I still do get the screen Y axis inverted.I have corrected the .cpp le that supposedly alters the ipping, with no success. My question is, once I modify the .cpp le, do I save, close and re-upload theprogram to the arduino? or is there something else involved? since its a .cpp le on its own I couldnt re-compile it

maybe you can help me? i have the same display. and i dont get it work correctly. have you ever got it working on a mega2560? thats what i tried to do. my results sofar:1. the touchscreendemo from adafruit fold the following message on the serial monitor :unknown driver chip: 7783. you said you have got C0505 is that correct?that would be 50437 in decimal?2. i got the paint-example working, but without any touch-functionality, so there is just the static picture of the color-elds and the black drawing area.3. in the touchscreendemo i am able to see some x- and y-coordinates, when i press the shield. i am not sure about these coordinates: the x-coordinate shows alwaysthe same value, regardless of the place where i press. she y- and z- values are changing.

thanks to the Clean up pin modes for LCD part*pinMode(XM, OUTPUT);digitalWrite(XM, LOW);pinMode(YP, OUTPUT);digitalWrite(YP, HIGH);pinMode(YM, OUTPUT);digitalWrite(YM, LOW);pinMode(XP, OUTPUT);digitalWrite(XP, HIGH);*

himy display from mcufriend shows color banding as shown in https://mbed.org/questions/3270/Banding-on-24-display/ what should i do to correct the mistake

i tried your library in your source code but still i donot see any thing on the screen display only the white backlight . i tried a lot ,plz i really need this working .i solved the errors i got while compililing but it doesnt work .if u can help me in just getting any stu over this screen .plz tell me what i am doing wrong . i am usingmega board

Hi Justin.Excellent article . With all that I found on the net, there was work to do this display.I have only one doubt the tftpaint.ino sketch gives me this error.

tftpaint.ino: In function void loop ():tftpaint: 95: error: Point was not Declared In this scopetftpaint: 95: error: expected `; before ptftpaint: 106: error: p was not Declared In this scope

I am an Engineering student.I want to do project using arduino board.my questions are1)Can an arduino tft touch screen allows to save or store the images.?2)if yes then in which formate it saves.can it be in .jpg or . gif.?3)what is maximum size of arduino tft touch screen.4)is it stores images from sd card.can we send the images from sd card to other devices using bluetooth.

C:\Program Files\Arduino\libraries\TFTLCD\TFTLCD.cpp:761:4: error: #error No pins dened!C:\Program Files\Arduino\libraries\TFTLCD\TFTLCD.cpp:799:4: error: #error No pins dened!C:\Program Files\Arduino\libraries\TFTLCD\TFTLCD.cpp:832:4: error: #error No pins dened!

C:\Program Files\Arduino\libraries\TFTLCD\TFTLCD.cpp:743:4: error: #error No pins dened!C:\Program Files\Arduino\libraries\TFTLCD\TFTLCD.cpp:761:4: error: #error No pins dened!C:\Program Files\Arduino\libraries\TFTLCD\TFTLCD.cpp:799:4: error: #error No pins dened!C:\Program Files\Arduino\libraries\TFTLCD\TFTLCD.cpp:832:4: error: #error No pins dened!

Albert September 4, 2014For the people who do not get it done, download: https://github.com/Smoke-And-Wires/TFT-Shield-Example-Code https://github.com/adafruit/Touch-Screen-Library https://github.com/adafruit/Adafruit-GFX-Library

For the people who do have an arduino Mega 2560 DONT forget to modify the SWTFT.cpp.Change// Use the include which corresponde to your arduino//#include mega_24_shield.h//#include uno_24_shield.h

1) SD card wont work as Uno does SPI via the Digital pins whereas Leonardo has separate pins specically for SPI.2) I need to change the references that map the various pins of the shield to things like PORTB, PORTD etc as the Leonardo port mappings dier from the UNO.

I picked up the mcufriend 2.8inch touchscreen+SD reader for 6 and would love to get it working with my Leonardo but its just (well hoping its *just*) beyond mycapabilities at the moment any tips much appreciated.

I got a 2.8In one of these from Amazon, all it says in it is www.mcuriend.com and 2.8 TFT LCD ShieldIt came with a mini cd.So far i think i have tried everyones code in the world and all it will do is light up all white????I see in the serial out the line LCD driver Chip: 0 which makes me somewhat suspicious, im pretty sure that should not have a value of zero!Ive checked the pin assignments in the swift code & all looks okay. still it just lights up blank white.Am i missing a massive elephant here or are both of the tft#s i bought du???Any and all help appreciated, im not trying to be lasy here & use someone elses code, I just want to verify i havent been shipped two du screens!

Hi,I bought 2.4 TFT. Plugged it into Arduino MEGA, included mega_24_shield.h and after uploading code what I can see its just full screen of color dots. Chip id is 0. Is itfaulty TFT board or something else? Thanks.

Richard December 7, 2014I also bought this lcd on ebay like Ramis and have the same problem with white screen. The ebay reseller has linked his item to this page for usage instructions butdoesnt provide support because of the low price.

I downolad code, i had an arduino YUN but when i build sample graphicstest i recive error:Arduino\libraries\TFTLCD\TFTLCD.cpp:743:4: error: #error No pins dened!Arduino\libraries\TFTLCD\TFTLCD.cpp:761:4: error: #error No pins dened!Arduino\libraries\TFTLCD\TFTLCD.cpp:799:4: error: #error No pins dened!Arduino\libraries\TFTLCD\TFTLCD.cpp:832:4: error: #error No pins dened!

The Leonardo and Yun have dierent SPI pinouts to the UNO, so youll not be able to connect the shield directly to your arduino and youll need to use jumpers orsomething else to connect the display to your arduinos. I know the Leonardo does NOT duplicate the SPI pins like the UNO, Nano, others, on the Leonardo they are onlyconnected to the 6 pin ISCP (on Uno the 4 of these pins are that make up SPI are also routed through pins 10-13). So these would need to be re-routed with jumpers.(The Mega has dierent pinouts to the Uno of course too, but obviously these are being accounted for the in the code and examples.)Good Luck

could you PLEASE post the exact sketch you used to do ANYTHING with this sceen, nding the UTFT library to operate it took about 3 hours and Im getting corruptresults, NOBODY who has these screens working has posted the initialization line they are using.mine is myGLCD(UNO_24,A2,A1,A3,A4);what are you using!?

Just posting to say that I am also having issues with this screen. The shield looks very similar but it has the phone type icons as someone else has described. It hasmcufriend on the screen though that is not useful. The button is in a slightly dierent place to yours (where the bare solder pads are on yours).

I am able to compile the graphictest ne but when running, the screen just ickers, nothing is displayed. I am worried I damaged something as the bottom of the boardis not protected and the contact there touched the USB shield (something people need to be aware and careful of). Note that it does not icker when the program isnot running so that at least something appears to be happening.

I guess I will grab the adafruit library and see if that does anything. Just getting some kind of output would be good.Thanks for the good work you have done.

Have the same excaty problem. This is the only version of any library that does anything on the screen and its not much, just some ickering. I also tried to play withseveral dierent touchscreen libraries but cant get anything sensible out of them. Even the pressure value is jumping between -297 and 0.My TFT has http://www.mcufriend.com label on the bottom.

if(identier == 0x9325) {Serial.println(F(Found ILI9325 LCD driver));} else if(identier == 0x9328) {Serial.println(F(Found ILI9328 LCD driver));} else if(identier == 0x7575) {Serial.println(F(Found HX8347G LCD driver));} else if(identier == 0x9341) {Serial.println(F(Found ILI9341 LCD driver));} else {Serial.print(F(Unknown LCD driver chip: ));Serial.println(identier, HEX);return;}

It turns out that the device seems to require some time between tft.reset() and tft.readID(). when I put a delay(500) between these calls everything started to work.

Can i interface both Ethernet W5100 R3 and above LCD TFT touch display shields simultaneously with UNO R3. I also need 2 or 3 analog and 2 digital IOs for interfacingthermocouples and sounders .Please advise whether UNO R3 can be used for same or not.

I cannot get my LCD to work! At rst it would always be white, but now I found this and it seemed reliable. I tried it but the one I tried (tftpaint) had an error:tftpaint.ino: In function void loop():tftpaint:94: error: Point was not declared in this scopetftpaint:94: error: expected `; before ptftpaint:105: error: p was not declared in this scope

I did managed to get mine 2.8 tft LCD working with adafruit library, just forcing it to recognize my chipset 8357, despite Im using Arduino MEGA (connecting digitalpins to 22-29) and more its mirrored, but at least working. Now question is : how to make it to work with original pins (2-9) is it possible? What needs to be changed inadafruit library les to remap digital pins?

Thank you all! Very helpful in getting my TFT to work. Now I am facing problem with variables. How can I display variables in tft.print(). I am digging in the library lebut unable to gure out yet. Quick response is highly appreciated!. Aamer January 18, 2015

I am using the same tft, have used dierent libraries of utft and adafruit. For me each of the library compiles and uploads just right. Even in serial monitor everythingjust works ne. The chip in serial monitor that i get is 154 in HEX. But the screen just lights up and stays blank. None of the example like paint and graphics test are notworking. I am using UNO board with this tft. Also i have replaced the tft and UNO boards,but the problem stays as same. I really need to get this working. Help plzz

// This header le serves two purposes://// 1) Isolate non-portable MCU port- and pin-specic identiers and// operations so the library code itself remains somewhat agnostic// (PORTs and pin numbers are always referenced through macros).//// 2) GCC doesnt always respect the inline keyword, so this is a// ham-sted manner of forcing the issue to minimize function calls.// This sometimes makes the library a bit bigger than before, but fast++.// However, because theyre macros, we need to be SUPER CAREFUL about// parameters for example, write8(x) may expand to multiple PORT

// When using the TFT shield, control and data pins exist in set physical// locations, but the ports and bitmasks corresponding to each vary among// boards. A separate set of pin denitions is given for each supported// board type.// When using the TFT breakout board, control pins are congurable but// the data pins are still xed making every data pin congurable// would be much too slow. The data pin layouts are not the same between// the shield and breakout congurations for the latter, pins were// chosen to keep the tutorial wiring manageable more than making optimal// use of ports and bitmasks. So theres a second set of pin denitions// given for each supported board.

// Shield pin usage:// LCD Data Bit : 7 6 5 4 3 2 1 0// Digital pin #: 7 6 13 4 11 10 9 8// Uno port/pin : PD7 PD6 PB5 PD4 PB3 PB2 PB1 PB0// Mega port/pin: PH4 PH3 PB7 PG5 PB5 PB4 PH6 PH5// Leo port/pin : PE6 PD7 PC7 PD4 PB7 PB6 PB5 PB4// Due port/pin : PC23 PC24 PB27 PC26 PD7 PC29 PC21 PC22// Breakout pin usage:// LCD Data Bit : 7 6 5 4 3 2 1 0// Uno dig. pin : 7 6 5 4 3 2 9 8// Uno port/pin : PD7 PD6 PD5 PD4 PD3 PD2 PB1 PB0// Mega dig. pin: 29 28 27 26 25 24 23 22// Mega port/pin: PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0 (one contiguous PORT)// Leo dig. pin : 7 6 5 4 3 2 9 8// Leo port/pin : PE6 PD7 PC6 PD4 PD0 PD1 PB5 PB4// Due dig. pin : 40 39 38 37 36 35 34 33// Due port/pin : PC8 PC7 PC6 PC5 PC4 PC3 PC2 PC1 (one contiguous PORT. -ish)

// LCD control lines:// RD (read), WR (write), CD (command/data), CS (chip select)#dene RD_PORT PORTC/*pin A0 */#dene WR_PORT PORTC/*pin A1 */#dene CD_PORT PORTC/*pin A2 */#dene CS_PORT PORTC/*pin A3 */#dene RD_MASK B00000001#dene WR_MASK B00000010#dene CD_MASK B00000100#dene CS_MASK B00001000

// Write 8-bit value to LCD data lines#dene write8inline(d) { \PORTD = (PORTD & B00101111) | ((d) & B11010000); \PORTB = (PORTB & B11010000) | ((d) & B00101111); \WR_STROBE; } // STROBEs are dened later

// Read 8-bit value from LCD data lines. The signle argument// is a destination variable; this isnt a function and doesnt// return a value in the conventional sense.#dene read8inline(result) { \RD_ACTIVE; \DELAY7; \result = (PIND & B11010000) | (PINB & B00101111); \RD_IDLE; }

// These set the PORT directions as required before the write and read// operations. Because write operations are much more common than reads,// the data-reading functions in the library code set the PORT(s) to// input before a read, and restore them back to the write state before// returning. This avoids having to set it for output inside every// drawing method. The default state has them initialized for writes.#dene setWriteDirInline() { DDRD |= B11010000; DDRB |= B00101111; }#dene setReadDirInline() { DDRD &= ~B11010000; DDRB &= ~B00101111; }

// All of the functions are inlined on the Arduino Mega. When using the// breakout board, the macro versions arent appreciably larger than the// function equivalents, and theyre super simple and fast. When using// the shield, the macros become pretty complicatedbut this board has// so much code space, the macros are used anyway. If you need to free// up program space, some macros can be removed, at a minor cost in speed.#dene write8 write8inline#dene read8 read8inline#dene setWriteDir setWriteDirInline#dene setReadDir setReadDirInline#dene writeRegister8 writeRegister8inline#dene writeRegister16 writeRegister16inline#dene writeRegisterPair writeRegisterPairInline

#dene setReadDirInline() { \pmc_enable_periph_clk( ID_PIOC ) ; \PIOC->PIO_PUDR |= 0x000001FE; PIOC->PIO_IFDR |= 0x000001FE; PIOC->PIO_ODR |= 0x000001FE; PIOC->PIO_PER |= 0x000001FE; }// When using the TFT breakout board, control pins are congurable.#dene RD_ACTIVErdPort->PIO_CODR |= rdPinSet//PIO_Clear(rdPort, rdPinSet)#dene RD_IDLErdPort->PIO_SODR |= rdPinSet//PIO_Set(rdPort, rdPinSet)#dene WR_ACTIVEwrPort->PIO_CODR |= wrPinSet//PIO_Clear(wrPort, wrPinSet)#dene WR_IDLEwrPort->PIO_SODR |= wrPinSet//PIO_Set(wrPort, wrPinSet)#dene CD_COMMANDcdPort->PIO_CODR |= cdPinSet//PIO_Clear(cdPort, cdPinSet)#dene CD_DATAcdPort->PIO_SODR |= cdPinSet//PIO_Set(cdPort, cdPinSet)#dene CS_ACTIVEcsPort->PIO_CODR |= csPinSet//PIO_Clear(csPort, csPinSet)#dene CS_IDLEcsPort->PIO_SODR |= csPinSet//PIO_Set(csPort, csPinSet)

// When using the TFT breakout board, control pins are congurable.#dene RD_ACTIVE *rdPort &= rdPinUnset#dene RD_IDLE *rdPort |= rdPinSet#dene WR_ACTIVE *wrPort &= wrPinUnset#dene WR_IDLE *wrPort |= wrPinSet#dene CD_COMMAND *cdPort &= cdPinUnset#dene CD_DATA *cdPort |= cdPinSet#dene CS_ACTIVE *csPort &= csPinUnset#dene CS_IDLE *csPort |= csPinSet

// Set value of TFT register: 16-bit address, 16-bit value// See notes at top about macro expansion, hence hi & lo temp vars#dene writeRegister16inline(a, d) { \uint8_t hi, lo; \hi = (a) >> 8; lo = (a); CD_COMMAND; write8(hi); write8(lo); \hi = (d) >> 8; lo = (d); CD_DATA ; write8(hi); write8(lo); }

// Set value of 2 TFT registers: Two 8-bit addresses (hi & lo), 16-bit value#dene writeRegisterPairInline(aH, aL, d) { \uint8_t hi = (d) >> 8, lo = (d); \CD_COMMAND; write8(aH); CD_DATA; write8(hi); \CD_COMMAND; write8(aL); CD_DATA; write8(lo); }

Thanxs alott dear for giving us the library for 154 the lcd is now working perfectly accept the touchscreen,the example tft paint is still not working as the there is noresponse from the touchscreen..

@Farrukh, you probably need to take the tftpaint (without shield), and change the pins for the touchscreen to the shield pinout.Because while this looks like a shield to me, for the screen I had to leave the USE_ADAFRUIT_SHIELD_PINOUT commented out, but apparently the touchscreen doeshave the shield pinning.So in the tftpaint sketch, change:#dene YP A3 // must be an analog pin, use An notation!#dene XM A2 // must be an analog pin, use An notation!#dene YM 9 // can be a digital pin#dene XP 8 // can be a digital pin

to:// These are the pins for the shield!#dene YP A1 // must be an analog pin, use An notation!#dene XM A2 // must be an analog pin, use An notation!#dene YM 7 // can be a digital pin#dene XP 6 // can be a digital pinThat worked for me.Also I had to change the display height in Adafruit_TFTLCD.cppfrom:#dene TFTHEIGHT 400to:#dene TFTHEIGHT 320

Just saw on github that the rst = false; line in tftbmp should not be removed, but that the bracketing in the pushColors function in Adafruit_TFTLCD.cpp was wrong.The bracket on line 899 (after CS_IDLE) should in fact be placed on line 889 (before CD_DATA).

Hii use this shield to display numbes the came from sensori try to make the touch screen button in order to turn on and o ledwhen i insert the touch screen command TSPoint p = ts.getPoint(); ,the numbers stop to update on the screen,how can i keep the numbers update and still make button from the screen? Sru February 19, 2015

Hi,I too used this LCD tft to display the data from the sensor..used the library fromhttps://github.com/Smoke-And-Wires/TFT-Shield-Example-Code/tree/master/SWTFT-ShieldI am getting the right values displayed but in mirrored form.Used the same library to display a string and its displayed properly. Is it nythng to do with thetft.setRotation function? without using this function i m not getting the sensor values displayed but if used its giving mirrored values. someone lease help meregarding this.

I am Nagesh and newbie in Arduino. I found this post useful to show info on TFT display. The library is working with UNO where as the same is failing with Arduno Yun.Program complies but there is blank display. I couldnt gure out cause and solution for the same.

I found Andrea, Leonardo Kusch and Manoj Vora faced the same problem above and L Mitchell recommended to use SPI. To be honest I am not able to understand onHOW TO part. I request you to share the connection diagram and sample program (if any). Unfortunately there is very less documentation on this TFT display (bymcufriend.com), so your comments would be helpful.

I think valid share, I had the same problem with mirror image, through brute strength and patience, I was changing dword and succeeded, UTFT \ tft_drivers \spfd5408a \ initlcd.h change in the Control Panel value LCD_Write_COM_DATA (0x90, 0x0010); to the value LCD_Write_COM_DATA (0x90, 0x0033); and be happy varun April 6, 2015

C:\Users\vermillionr\Documents\Arduino\libraries\TFTLCD\glcdfont.c:9:23: error: variable font must be const in order to be put into read-only section by means of__attribute__((progmem))static unsigned char font[] PROGMEM = {^Error compiling.Does anyone know why this error is occurring?

Hi, Could you elaborate where you popped the constant at? in glcdfont.c or in the examples them self?Much thanks Gunner May 22, 2015

After much trial and error, I opened glcdfont.c (in the TFTLCD library) with NOTEPAD (or use any text editor) and popped the word const in front of the only existingword char that I could nd In the rst line of code the rest looked like hex.

I really appreciate this article.As you know most OEM resellers and eBay sellers supply shields generally and including these LCD shields with absolutely no documentation, so the info youveprovided is invaluable. Thank you.

I have adapted the LCD_ID_Reader code to work on an STM32L152RE. I am using Atollic trueSTUDIO. The lcd has MCU Friend printed on it and the controller isST7781 according to the Ebay seller. The ID seems to be C505.

I tried your graphicstest example where I replaced the #include TFTLCD.h by #include and changed the type of font[] to const to be able to compile (Arduino IDE). Istill have a simple white screen.

what a wonderfull website!I had a problem with a e-bay 2.4 inch display, which is equipted with a ili9335 contorller.At rst it will not run on your TFTLCD driver downloaded at your website.It appears only full-white-screen.With x times trial I had found that errors happen to, when the registers are inintialized.Datatransfort may be need more time, so I insert a delay time.

mcufriend 2.8 tft lcd shield library quotation

Spice up your Arduino project with a beautiful large touchscreen display shield with built in microSD card connection. This TFT display is big (2.3" diagonal) bright (4 white-LED backlight) and colorful (18-bit 262,000 different shades)! 320x240 pixels with individual pixel control.

The shield is fully assembled, tested and ready to go. No wiring, no soldering! Simply plug it in and load up our library - you"ll have it running in under 10 minutes! Works best with any classic Arduino (Due/Mega 2560).

This display shield has a controller built into it with RAM buffering, so that almost no work is done by the microcontroller. You can connect more sensors, buttons and LEDs.

Of course, we wouldn"t just leave you with a datasheet and a "good luck!" - we"ve written a full open source graphics library at the bottom of this page that can draw pixels, lines, rectangles, circles and text. We also have a touch screen library that detects x,y and z (pressure) and example code to demonstrate all of it. The code is written for Arduino but can be easily ported to your favorite microcontroller!

mcufriend 2.8 tft lcd shield library quotation

TFT LCDs are the most popular color displays – the displays in smartphones, tablets, and laptops are actually the TFT LCDs only. There are TFT LCD shields available for Arduino in a variety of sizes like 1.44″, 1.8″, 2.0″, 2.4″, and 2.8″. Arduino is quite a humble machine whenever it comes to process or control graphics. After all, it is a microcontroller platform, and graphical applications usually require much greater processing resources. Still, Arduino is capable enough to control small display units. TFT LCDs are colorful display screens that can host beautiful user interfaces.

Most of the smaller TFT LCD shields can be controlled using the Adafruit TFT LCD library. There is also a larger TFT LCD shield of 3.5 inches, with an ILI9486 8-bit driver.

The Adafruit library does not support the ILI9486 driver. Actually, the Adafruit library is written to control only TFT displays smaller than 3.5 inches. To control the 3.5 inch TFT LCD touch screen, we need another library. This is MCUFRIEND_kbv. The MCUFRIEND_kbv library is, in fact, even easier to use in comparison to the Adafruit TFT LCD library. This library only requires instantiating a TFT object and even does not require specifying pin connections.

TFT LCDs for ArduinoUser interfaces are an essential part of any embedded application. The user interface enables any interaction with the end-user and makes possible the ultimate use of the device. The user interfaces are hosted using a number of devices like seven-segments, character LCDs, graphical LCDs, and full-color TFT LCDs. Out of all these devices, only full-color TFT displays are capable of hosting sophisticated interfaces. A sophisticated user interface may have many data fields to display or may need to host menus and sub-menus or host interactive graphics. A TFT LCD is an active matrix LCD capable of hosting high-quality images.

Arduino operates at low frequency. That is why it is not possible to render high-definition images or videos with Arduino. However, Arduino can control a small TFT display screen rendering graphically enriched data and commands. By interfacing a TFT LCD touch screen with Arduino, it is possible to render interactive graphics, menus, charts, graphs, and user panels.

Some of the popular full-color TFT LCDs available for Arduino include 3.5″ 480×320 display, 2.8″ 400×200 display, 2.4″ 320×240 display and 1.8″ 220×176 display. A TFT screen of appropriate size and resolution can be selected as per a given application.

If the user interface has only graphical data and commands, Atmega328 Arduino boards can control the display. If the user interface is a large program hosting several menus and/or submenus, Arduino Mega2560 should be preferred to control the TFT display. If the user interface needs to host high-resolution images and motions, ARM core Arduino boards like the DUE should be used to control the TFT display.

MCUFRIEND_kbv libraryAdafruit TFT LCD library supports only small TFT displays. For large TFT display shields like 3.5-inch, 3.6-inch, 3.95-inch, including 2.4-inch and 2.8-inch TFT LCDs, MCUFRIEND_kbv library is useful. This library has been designed to control 28-pin TFT LCD shields for Arduino UNO. It also works with Arduino Mega2560. Apart from UNO and Mega2560, the library also supports LEONARDO, DUE, ZERO, and M0-PRO. It also runs on NUCLEO-F103 and TEENSY3.2 with Sparkfun Adapter. The Mcufriend-style shields tend to have a resistive TouchScreen on A1, 7, A2, 6 but are not always in the same direction rotation. The MCUFRIEND_kbv library can be included in an Arduino sketch from the library manager.

The 3.5-inch TFT LCD shield needs to be plugged atop the Arduino board. The Mcufriend-style shields are designed to fit into all the above-mentioned Arduino boards. The shields have a TFT touch screen that can display colorful images and interfaces and a micro SD card reader to save images and other data. A 3.5-inch TFT LCD touch screen has the following pin diagram.