MCUFRIEND_kbv Library for Uno 2.4, 2.8, 3.5, 3.6, 3.95 inch mcufriend Shields

david_prentice:
I have updated the sketch attached to #1607.
Please comment.

David.

Here are my experiments:

Touchscreen ID: reg(0x0000) 93 25 ID: ILI9320, ILI9325, ILI9335, ... (TS that i used in post #1606)

1st Try:

TouchScreen.h Calibration
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction

Testing : (A1, D7) = 52
Testing : (A2, D6) = 32
Diagnosing as:-
YP,YM:  (A1, D7) = 52
XM,XP:  (A2, D6) = 32

cx=911 cy=974
cx=606 cy=977
cx=229 cy=982
cx=909 cy=832
cx=238 cy=904
cx=915 cy=628
cx=574 cy=814
cx=238 cy=844
Sketch is PORTRAIT      240 x 320
PORTRAIT CALIBRATION     240 x 320
x = map(p.x, LEFT=986, RT=752, 0, 240)
y = map(p.y, TOP=933, BOT=212, 0, 320)
Touch Pin Wiring XP=6 XM=A2 YP=A1 YM=7
LANDSCAPE CALIBRATION     320 x 240
x = map(p.y, LEFT=933, RT=212, 0, 320)
y = map(p.x, TOP=752, BOT=986, 0, 240)

2nd Try:

TouchScreen.h Calibration
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction

Testing : (A1, D7) = 53
Testing : (A2, D6) = 29
Diagnosing as:-
YP,YM:  (A1, D7) = 53
XM,XP:  (A2, D6) = 29

cx=911 cy=969
cx=586 cy=978
cx=235 cy=977
cx=902 cy=829
cx=231 cy=898
cx=909 cy=656
cx=563 cy=817
cx=274 cy=835
Sketch is PORTRAIT      240 x 320
PORTRAIT CALIBRATION     240 x 320
x = map(p.x, LEFT=983, RT=759, 0, 240)
y = map(p.y, TOP=929, BOT=223, 0, 320)
Touch Pin Wiring XP=6 XM=A2 YP=A1 YM=7
LANDSCAPE CALIBRATION     320 x 240
x = map(p.y, LEFT=929, RT=223, 0, 320)
y = map(p.x, TOP=759, BOT=983, 0, 240)

Touchscreen ID: reg(0x0000) 93 25 ID: ILI9320, ILI9325, ILI9335, ... (my Old TS)

1st Try:

TouchScreen.h Calibration
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction

Testing : (A1, D7) = 30
Testing : (A2, D6) = 26
Diagnosing as:-
YP,YM:  (A1, D7) = 30
XM,XP:  (A2, D6) = 26

cx=808 cy=909
cx=804 cy=552
cx=842 cy=153
cx=475 cy=895
cx=464 cy=182
cx=229 cy=873
cx=170 cy=540
cx=157 cy=163
Sketch is PORTRAIT      240 x 320
PORTRAIT CALIBRATION     240 x 320
x = map(p.x, LEFT=846, RT=156, 0, 240)
y = map(p.y, TOP=916, BOT=141, 0, 320)
Touch Pin Wiring XP=6 XM=A2 YP=A1 YM=7
LANDSCAPE CALIBRATION     320 x 240
x = map(p.y, LEFT=916, RT=141, 0, 320)
y = map(p.x, TOP=156, BOT=846, 0, 240)

2nd Try:

TouchScreen.h Calibration
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction

Testing : (A1, D7) = 29
Testing : (A2, D6) = 26
Diagnosing as:-
YP,YM:  (A1, D7) = 29
XM,XP:  (A2, D6) = 26

cx=828 cy=902
cx=807 cy=529
cx=849 cy=140
cx=456 cy=885
cx=474 cy=161
cx=175 cy=899
cx=162 cy=539
cx=167 cy=190
Sketch is PORTRAIT      240 x 320
PORTRAIT CALIBRATION     240 x 320
x = map(p.x, LEFT=858, RT=138, 0, 240)
y = map(p.y, TOP=919, BOT=138, 0, 320)
Touch Pin Wiring XP=6 XM=A2 YP=A1 YM=7
LANDSCAPE CALIBRATION     320 x 240
x = map(p.y, LEFT=919, RT=138, 0, 320)
y = map(p.x, TOP=138, BOT=858, 0, 240)

Your sketch is great! Many thanks!
nug.

Please try the new sketch on GitHub. I does the same Calibration but you get the information on Serial too.

So you can copy-paste your results for future reference. Or post it here if you have a problem.

You might find the new showBMP examples useful.

I would appreciate feedback from non-English speakers.

GFX programs work on an Arduino with almost any controller,
Touch programs require configuration of TouchScreen.h library e.g. NUMSAMPLES, finding YP, XM pins.
SD programs only work on a Uno. (it is a Uno Shield)
SD programs on Mega, Due require configuration of SdFat.h library i.e. ENABLE_SOFTWARE_SPI_CLASS 1

David.

Thanks for all.

Everything works perfectly

I am pleased that you have it working now.

I would appreciate some feedback. This could help other users that have experienced your difficulties.

I have always been reluctant to assist non-Uno users. After all, you have bought Uno Shields. Owners never know where they obtained "third party libraries"

Now that SdFat library is available from the Library Manager, life should be much easier.

David.

david_prentice:
I would appreciate feedback from non-English speakers.

GFX programs work on an Arduino with almost any controller,
Touch programs require configuration of TouchScreen.h library e.g. NUMSAMPLES, finding YP, XM pins.
SD programs only work on a Uno. (it is a Uno Shield)
SD programs on Mega, Due require configuration of SdFat.h library i.e. ENABLE_SOFTWARE_SPI_CLASS 1

David.

Hi David !

What tests would you need to do for you?
Tell me and I will.

François.

Just

david_prentice:
I have put a new TouchScreen_Calibration and two new showBMP sketches on GitHub. And several BMPs of different size and format.

I hope that the "not_Uno" sketch explains how to install and configure "SdFat.h" to work on your Mega2560.
The good news is that "SdFat.h" is now in the Library Manager. So at least we know where it comes from.

Please give some feedback. I know that people have difficulties.

David.

It is just a question of copy-pasting the new example sketches from GitHub (or downloading the whole Master Branch as a ZIP)

Run the sketches.
Do you understand the "instructions"?
Do the sketches work for you?

Can you suggest "better" instructions?
Can you suggest "better" display images / text on the TFT?

English speakers find things difficult. Non-English speakers will find it harder.

David.

Huge thanks for david_prentice. My weird 9488 555 works almost perfectly. I just want to report very strange behavior. I have uploaded my sketch to DUE and it's doing it's own bussines. When I upload sketch it takes like 2 minutes and it jumps to next line of code without touching it. Strange. When I upload same sketch to UNO it didn't do anything for half an hour. It seems like "it randomly "touch"" display. I know that it just "should" work for due but other than that it's absolutely ok.

void loop() {
start:  
  stuff();
while(1){
    tp = ts.getPoint();
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
    pinMode(XP, OUTPUT);
    pinMode(YM, OUTPUT);
    if (tp.z < MINPRESSURE || tp.z > MAXPRESSURE  ) {
    if (tp.x > 110 && tp.x < 300  && tp.y > 525 && tp.y < 910) {
      
while(1){
    something(); 
    
    if (break == true){ break = false; goto start;}
    
    somethin1(stuff1);
      }
    }
    if (tp.x > 667 && tp.x < 930  && tp.y > 125 && tp.y < 515) {
     otherstuff
    break;
    }
    
  }

}
}

I possess one Due clone and one Mega2560 clone. I don't use either very often.

If you tell me what sketch takes 2 minutes to upload to a Due, I will try it with the 9488_555 shield.

Likewise, if you post a buildable sketch of your own, I can debug it.
It is not much good posting a snippet that says stuff() and something() or uses keyword break as a variable.

Yes, the 9488_555 works reasonably well. The Red is a bit weak and the Blue is too strong. Photos will never look very lifelike.

David.

Dragonsired1:
Huge thanks for david_prentice. My weird 9488 555 works almost perfectly. I just want to report very strange behavior. I have uploaded my sketch to DUE and it's doing it's own bussines. When I upload sketch it takes like 2 minutes and it jumps to next line of code without touching it. Strange. When I upload same sketch to UNO it didn't do anything for half an hour. It seems like "it randomly "touch"" display. I know that it just "should" work for due but other than that it's absolutely ok.

I tried your sketch on a Due with the weird 9488_555 display.

  1. I did not get a reliable readID() with the Due.

So I put the shield onto the mega2560.

  1. your #define SUPPORT_9488_555 should be in MCUFRIEND_kbv.cpp. It does nothing for the INO file.
  2. your calibration seems wrong. I always name the Touch pins in Portrait mode. i.e. Y is the long dimension.
  3. the Touch seems to work ok with the Mega2560.
  4. I always map the Touch values to the pixel coordinates. It is easier to refer to screen x,y
  5. Your numbers are written in transparent mode. use tft.setTextColor(GREEN, BLACK) for rubout mode.
  6. The Adafruit_GFX_Button class is a lot easier to use than hand-drawing individual buttons.

Quite honestly, I do not think the Due is built for reading a Resistive screen. 300R means 10mA is being drawn from the GPIO pins. This is more than the spec sheet.

Your sketch will build on a Uno. Why do you need a Due?

David.

david_prentice:
Just
It is just a question of copy-pasting the new example sketches from GitHub (or downloading the whole Master Branch as a ZIP)

Run the sketches.
Do the sketches work for you ?

For the sketch showBMP_kbv_Uno : (With a Arduino UNO).

The bitmaps: betty_1 -- betty_4 -- marilyn_240x240x8 -- tiger_178x160x4 -- tiger_240x317x4 .
Do not appear on screen, the serial monitor returns:"unsupported palette".
For the other pictures that's ok.

If #define PALETTEDEPTH 8, the serial monitor returns:"bad ID" and nothing appears on the screen.
The screen remains blue.

For the sketch showBMP_not_Uno : (With a Arduino UNO and a Arduino MEGA 2560).
Everything works perfectly.

david_prentice:
Do you understand the "instructions"?
Can you suggest "better" instructions?

I understand the instructions very well, for me I do not see what should be added.
I think that's pretty clear in the code comments.

david_prentice:
Can you suggest "better" display images / text on the TFT?

As for images and text, it is not very complicated.
I did a test with the sketch showBMP_kbv_as7 sometime ago, it is just necessary use the normal procedures of the MCUFRIEND_kbv library.

david_prentice:
English speakers find things difficult. Non-English speakers will find it harder.
David.

Personally I do not speak or understand English except a few words.
(The "technical" words used in electronics and programming).

I speak and understand only French and Spanish.
Just need is a little determination, and Google translate do the rest it is not so difficult.

Hoping that these tests and my comments will be able to advance this magnificent work that you do.

If you still need further testing, please do not hesitate to let me know.
I would do them with great pleasure, because I do not forget that if all my screens work it is entirely thanks to you and your library.

Thank you very much David.
François.

The Uno has not got enough SRAM to display big Palettes. You should be able to view the 16-colour bitmaps if you define PALETTEDEPTH 4

If you have a Mega or Due, you must install SdFat library and configure it for Software SPI.
It will display most bitmap formats.

In practice, you would use 65k colour bitmaps on a Uno. Storage size does not matter on several GigaBytes of microSD.

David.

Hi,
I'm sorry, I want help! I have a 1284p Arduino compatible card, I want to connect a 2.8 Mcufriends display.
I tried UTFT libraries but I only have a white display. A board with the link below:
http://www.egyediprogramok.hu/1284p%20Arduino%20pinout-1.jpg

I can upload the UTFT sample program without error.

I made the connections as follows:

2.8 TFT LCD ---------------------------------------- 1284p Arduino pin

Digital Pin 0 = PD0 (Port D - bit 0) = Atmega 1284p D8
Digital Pin 1 = PD1 (Port D - bit 1) = Atmega 1284p D9
Digital Pin 2 = PD2 (Port D - bit 2) = Atmega 1284p D10
Digital Pin 3 = PD3 (Port D - bit 3) = Atmega 1284p D11
Digital Pin 4 = PB0 (Port B - bit 0) = Atmega 1284p D12
Digital Pin 5 = PB1 (Port B - bit 1) = Atmega 1284p D13
Digital Pin 6 = PB2 (Port B - bit 2) = Atmega 1284p D14
Digital Pin 7 = PB3 (Port B - bit 3) = Atmega 1284p D15

// #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// #define LCD_CS A3 // Chip Select goes to Analog 3
// #define LCD_CD(RS) A2 // Command/Data goes to Analog 2
// #define LCD_WR A1 // LCD Write goes to Analog 1
// #define LCD_RD A0 // LCD Read goes to Analog 0

my sample code:

// main code from Rinky-Dink Electronics, Henning Karlsen.
// web: http://www.RinkyDinkElectronics.com/
// edited by : Motaz bany amer
//
// This program requires the UTFT library.
//

#include <UTFT.h>

// Declare which fonts we will be using
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];

// Remember to change the model parameter to suit your display module!
UTFT myGLCD(CTE28, A2, A1, A3, A4);

void setup()
{
myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(BigFont);
}
void loop()
{
myGLCD.setColor(0, 255, 0); //green
myGLCD.print("HELLO WORLD", 45, 100);
while (true) {};
}

Thanks
Norbert

Your photo does not have any "Arduino headers". So the Shield will not be able to mate as Nature intended.
Your photo shows a pcb that does not have a 3.3V pin. Mcufriend Uno shields must have a 3.3V supply pin.

Why not buy a proper Uno or clone? Plug the shield in and go.
I do not support the mega1284 chip. If someone manufactured an "m1284 Arduino" with proper headers and power pins, I would add support.

This thread is about MCUFRIEND_kbv library. Why are you asking about UTFT?
UTFT will have exactly the same "electrical" problems since you have no 3.3V pin.

David.

Thanks for the quick response.
Unfortunately, UNO, MEGA and DUE boards do not have enough memory.
Norbert

A Uno has 32kB Flash / 2kB SRAM.
Mega2560 has 256kB Flash / 8kB SRAM.
A Due has 512kB Flash / 96kB SRAM.
A Zero has 256kB Flash / 32kB SRAM.

They all have a 3.3V pin.

Your mega1284 has 128kB Flash / 8kB SRAM but no 3.3V pin.

David.

david_prentice:
You should be able to view the 16-colour bitmaps if you define PALETTEDEPTH 4

Yes with #define PALETTEDEPTH 4 pictures are visible except "marilyn_240x240x8" what normal with #define PALETTEDEPTH 4.

david_prentice:
The Uno has not got enough SRAM to display big Palettes.

David.

So can you explain to me why with the sketch showBMP_kbv_as7, #define PALETTEDEPTH is set to 8; and everything works well with an UNO.

While with the sketch showBMP_kbv_Uno if we set PALETTEDEPTH to 8, it does not work and returns "BAD ID" ??

Thank you in advance for your explanations.

François

The showBMP_kbv_as7 example from v2.9.6 Release uses SdFat.h library.
Yes, it copes with 256-colour palettes (PALETTEDEPTH=8) because it probably uses less Stack than the SD.h library.

You will probably get some bad colours in the Palette with some BMPs.

The intention of the two new showBMP examples is to be as reliable as possible.

  1. showBMP_kbv_Uno uses the regular SD.h library that comes with every Arduino installation.
  2. showBMP_not_Uno requires installing SdFat.h with the Library Manager and configuring for Software SPI.

Yes, you can use SdFat.h on the Uno. And it will cope with 256-colour palette.
I am impressed by how good Marilyn looks in just 256 colours. And how a 16-colour BMP can look on a small TFT e.g. my attachment

Regular 24-bit colour BMP are most common. No, I doubt if many Uno users want to render many formats.

Even a monochrome BMP still uses quite a lot of data. It is not practical to embed a BMP in Uno Flash memory.
However, full colour JPEGs compress quite well. You can embed JPEG images in a Mega2560, Zero, Due, STM32, ... Flash memory. A Uno does not have sufficient SRAM to decode and render JPEGs.

David.

lady_128x127x4.zip (10.2 KB)

hi david i find i was getting unusual id from my lcd as you said the problem was from lcd it self
now i got 2.4inch lcd and i ran touchscreen calibration and i got four number for left rt top bot but i don't know where in my touchscreen.cpp should i apply the changes ???

First off. Do you get an ID = 0x1602 now?
Do my examples work?
I seem to remember that Software Scroll did not work on the 0x1602 controller.

What did you get for your Calibration? e.g. this is the result for my 9488_555 shield:

TouchScreen.h Calibration
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction

Testing : (A1, D7) = 22
Testing : (A2, D6) = 29
Diagnosing as:-
XM,XP:  (A1, D7) = 22
YP,YM:  (A2, D6) = 29

cx=895 cy=936
cx=904 cy=561
cx=897 cy=189
cx=543 cy=932
cx=540 cy=188
cx=190 cy=936
cx=191 cy=555
cx=189 cy=186
Sketch is PORTRAIT      320 x 480
PORTRAIT CALIBRATION     320 x 480
x = map(p.x, LEFT=921, RT=166, 0, 320)
y = map(p.y, TOP=950, BOT=170, 0, 480)
Touch Pin Wiring XP=7 XM=A1 YP=A2 YM=6
LANDSCAPE CALIBRATION     480 x 320
x = map(p.y, LEFT=950, RT=170, 0, 480)
y = map(p.x, TOP=166, BOT=921, 0, 320)

David.

Good afternoon!
I'm new to the forum, I'm trying to make the TFT LCD Display 3.95 "Shield Arduino Mega Touch Screen with SD Slot (MCUFRIEND) work,
On ARDUINO MEGA 2560 and I can not, the display remains white. I have tested several libraries without success.
Can someone help me?

Here are some links that I downloaded the libraries:

http://www.rinkydinkelectronics.com/library.php?id=51
http://osoyoo.com/2016/06/16/use-mega2560-to-drive-ili-9481-3-5-inch-lcd-screen/

Display photos and arduino:

I'm sorry for bad english, I'm using google tradudor.

Thank you!