Go Down

Topic: MCUFRIEND_kbv Library for Uno 2.4, 2.8, 3.5, 3.6, 3.95 inch mcufriend Shields (Read 457120 times) previous topic - next topic


Oops.   It looks as if I put the wrong "graphictest_kbv.ino" sketch into the ZIP.   
I have replaced the ZIP with a corrected version.   And put the "corrected" sketch as a separate attachment.   

I am a little worried by your JPEG.   It is displaying in PORTRAIT_REV mode but the directions are completely wrong.   Arduino v1.6.6 reports for a UNO:
Code: [Select]

Sketch uses 31,508 bytes (97%) of program storage space. Maximum is 32,256 bytes.
Global variables use 1,904 bytes (92%) of dynamic memory, leaving 144 bytes for local variables. Maximum is 2,048 bytes.
Low memory available, stability problems may occur.

Yes,  I have tried to squeeze as much as I can into the test sketch.   99.99% Flash is perfectly safe.  92% SRAM should be safe.   You definitely do not want to risk more.

That is the reason for the "graphictest_slim.ino" sketch.
The standard sketch will not fit in a Leonardo or even a Duemilanove.

You can remove Serial, Floating Point,  ... to reduce the Flash memory.
You can reduce the size of the software scroll buffer to reduce the SRAM memory.

Note that the ST7781 is the least powerful controller.    It has a bug in its "vertical scroll" hardware.
That is why the Scroll tests do not operate on your board.



David, thanks for fast answer and sorry for my bad english. :)

Most current goes to the backlight.     There is no way to turn this off without hacking the shield.
I thought exactly the same, but I'm not versed in microelectronics.

You would need to switch the 5V pin.

Most of these shields use the 5V pin from the Arduino to supply the backlight.
They use the 3.3V pin from the Arduino for the controller logic.

Cut the trace between 5V pin and the shield LDO regulator.
Place a 500mA PNP transistor between 5V and LDO.   
Control the transistor with the (unused) A5 pin via a resistor to the base.
You can look at the attached photo, and tell how and what to do in my case?

I connect this shield to mega2560 with the wires, so I can insert an additional circuit with a transistor before 5V connection.

Which of the inexpensive transistor can you advise?

UNTESTED.   Do any mods at your own risk.   The backlights take 100mA - 200mA.
I completely understand. Thank you very much for your help!


Any PNP transistor with a max collector current of 500mA or so will be fine.

I looked at what transistors I have.    I seem to have several BC212L that are probably 30 yrs old.

Looking up the data.   It is 300mA max.   With a min hFE of 50.   i.e. 4mA base current for 200mA.
So a 1k0 base resistor would switch it on.

If you are buying a new transistor,   look for a 500mA PNP with hFE > 100.    Look for a plastic case like TO92.

You can see the pcb trace that goes from 5V pin to U1.  It looks easy to cut.
You can get at A5 pin by soldering on to the top of the header pin.
Glue the transistor and base resistor to the pcb with some epoxy.

Connect up by soldering some fine wire from A5 to the base resistor.

If you do not understand this,   you should not attempt the mod.
I have not tried it.



Yes, of course I downloaded the new sketch, it works very beautiful.

Now, I want to start learning C++ :)



Any PNP transistor .....

If you do not understand this...
I'm understand and try to mod shield next week! Thanks very much for your advise!

And I think, this instruction may be helpful for others... Thanks!


What is the basic structures of programming a TFT display?

Such a big program, like this one which exceeds 30kb of flash memory.


The example sketch is at the limit of a UNO's memory.   read message #45.

Regarding program structure,   the other examples are a lot smaller.
There are hundreds of "Adafruit-style" examples.   They should all work with this library.   The only important lines are:

Code: [Select]

#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

uint16_t ID;

void setup(void)
    ID = tft.readID();  // you must detect the correct controller
    tft.begin(ID);      // everything will start working
    tft.fillScreen(0x001F);    //BLUE
    tft.print("Hello World");

void loop(void)

This was 10744 bytes (on my current un-released version).   It may be different for you.

The purpose of "example" programs is to show you what you can do.   

You write your own applications.   When you are unsure how to draw a circle or print a message,  you look at the example to see what was done.

It should be possible to fit most regular apps into a UNO.
However you need to be aware that loading big Fonts or bitmaps will use lots of Flash memory.



Hi everyone

I'm trying to make the resistive touchscreen work with the arduino due, but I'm new to this arduino stuff so I'm having a hard time understanding what I need to do or even if its possible...

I have the 3.95'' TFT LCD ili9488 from mcufriend like this one:

I don't have any shield, just the lcd directly plugged into the due...

Anyone knows how to make the touchscreen work with the due?


Your display is a shield.    You plug it directly into your UNO (or DUE).

The regular <TouchScreen.h> or <TouchScreen_due> library do not work with the shared pins.

One day I will write / publish a version that does work with the shield.

Meanwhile,   I suggest that you plug it into a UNO.



I thought you called the "shield" those intermediate boards you plug between the display and the arduino... my bad...

Ok thanks, I only have the DUE so I'm gonna have to keep researching... hopefully you'll not keep waiting for too long hehe.

Will you publish the solution here?


The board that "plugs into" the Arduino is called a Shield.
The intermediate board is called an "Adapter Shield".   e.g. the ColdTears adapter shield for regular 40-pin TFT displays.

The Mcufriend MEGA2560 display shields have a separate Touch Controller chip and should work fine with UTFT and UTouch libraries.    Unfortunately,  the microSD does not work reliably.

No,  I have no plans for writing a Touch library for the Due.
Meanwhile,  you could buy a Uno clone.



Hello, David,
Thanks for your great job!
Only owing to your topic i have started my LCD shield with chip ST7789V.
Finally i got a correct displaying in scketchs:

But i still can not use touchscreen:
are not working.
I suspect, that these sketchs are not optimized for ST7789V.

Could you give me information, where i can get correct library for touchscreen?

Thanks in advance!


I presume that you have a regular 2.4" Red shield or a 2.8" Blue shield.

The Touch is nothing to do with the TFT controller.
It is just a resistive screen that shares some pins with the controller.

Most of these shields use A1, 7 and A2, 6.
Unplug your shield and test the resistance between A1 and 7.  It should be about 300 ohms.

If there is no resistance,   try A1 with other digital pins.  e.g. 6, 7, 8, 9.

When you have identified the actual pins used by the Resistive screen,   you edit the TouchScreen_Calibr_kbv.ino sketch.

Please report back with your results.



... try A1 with other digital pins.  e.g. 6, 7, 8, 9.
When you have identified the actual pins used by the Resistive screen,   you edit the TouchScreen_Calibr_kbv.ino sketch...
Ok. understood.

Do you mean this records:
#define YP A1   
#define YM 7
#define XM A2
#define XP 6


Do you have a Red or Blue shield?

Yes,   you should read 300 ohms between YP and YM pins.    It may be 1000 ohms.

If your screen is cracked,   the resistance is broken too !


Go Up