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

Hi!

Link to LCD from Ebay:
http://www.ebay.com/itm/3-5-inch-TFT-LCD-Module-for-arduino-2560-R3-with-sd-card-slot/122399888078?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2060353.m2749.l2649

I tried sketch graphictest_kbv.h

If I left 0X9481 I can see something in a small rectangle screen size 50 X 100
If I forced it to 0x9327 then I reall can read letters GREEN, HelloWorl, 123.
DEA but correct colors, but only in screen size app 50 (width) X 100 (height)

Your link shows a pcb with RP1-RP7. So it is likely to be USE_MEGA_16BIT_SHIELD
The shape looks like 320x480 and not 240x400

I suggest that you try 320x480 IDs like 0x9486, 0x9488, 0x9090, ... 0x1581, 0x9481.
The how_to file lists all the 320x480 controller IDs.

Since Mega Shields are write-only you can only use guesswork.
I can't always recognise read-write Uno Shields, the Mega shields are even more of a lottery.

David.

Hi David!

I tried a lot of combinations regarding to your instructions, but unfortunately LCD shiled for Mega2560 not works properly.
The best result I got if I forced to 0x9327 (see picture - front).
I am sending another picture - back . Maybe you can recognise the type of controller...
At the cip I can read: XPT12046 1624.
Thank you and best regards.

Your photos show a 320x480 display. ILI9327 is 240x400 i.e. different shape

I can only suggest that you try forcing th ID from each 320x480 in the how_to file.
Report back with the results.

David.

Hi , David!

Ok, it works much better if I pluged OUT the LCD and pluged IN every time after loading new sketch with changed ID number...

Correct colors I get with ID numbers:(
0x6814 and ID=0x1511

Problems:
ID: 6814 I get correct text positions and text reading only in "green and grey color grades - horizontal)
At blue and red, positions are OK, but all text is mirrored.

ID: 1511: wrong text positions and text reading (mirrored) for all color grades. Do not rotate the screen...
except RED text is OK.

You have a 100% shield to compare with. So you know the correct directions and colours.

Don't worry about the exact colours or even the correct directions just make notes.
0x1511 is clearly wrong if there is no rotation.

See which is best. I would start with 0x9090. Is it red-blue swap? Or black-white swap i.e. inversion?

David.

ID=0x9090:
blue grade cloors=yellow
green grade colors=pink
red grade colors=light blue
grey grade colors=grey

Text and orientation=OK

Colour inversion. Just call tft.invertDisplay(true)

Or add/remove the REV_SCREEN attribute in the .cpp file

Yes, now it is much better, thank you!

I will build this new knowledge in my final application.
Maybe one question in advance: my application use touch screen .
Regarding this, should I change something in libraries?

Thank you

The Mega shield uses a XPT2046 or similar.
Since this is wired to GPIO pins on a Mega, you have to bit-bash the SPI. e.g. with <URTouch.h>

David.

Thank you David. I am trying now to insert all changes in my final application to work with 3.5" mcufrined Mega2560 shield.

Best regards!

Edit:
Right out I find out that this shield maybe use HX 8357 driver. Accidentally I insert this shield into Atmega which was prevously programmed for HX 8357 and works.... Unfortunately the original HX8357 3.2" do not have touch shield. So I still continue to find pinout for touch shield on those 3.5" mcufriend LCD. And in your library there is written : HX8357 -D ID=09090 :slight_smile:

I suggest that you use your Uno shield on a Uno
And use your Mega shield on a Mega

If you use a Uno shield on a Mega when the Mega expects a special USE_MEGA_16BIT_SHIELD, you must disable the USE_SPECIAL

Regarding the controller on your Mega shield. You can try all the 320x480 controllers.

If and when you find the correct one, it will have a clear display with consistent directions, colours etc.
I can fix any colour inversion, mirroring etc.

I thought that you had concluded that 0x9090 with REV_SCREEN was 100% correct.

If you are unsure. TAKE NOTES ON PAPER.

Then you can post the problem results for each controller. e.g.
0x1581: BLUE band screen vertical mirror
0x1234: BLUE band is RED
0x2345: BLUE band is YELLOW
...

David.

David, thank you!

At beginning , when we discouss about icon, I use UNO shield at MEGA, becouse I wrote application for this combination.
But now, I am trying to finalise my main application on TFT LCD MEGA shield on MEGA board, becouse this shield have nice holes for mounting.
ID=0x9090 works 100% OK in this combination.
Everything I done at first combination: UNO shield - MEGA board works perfectly now, except touch screen...
The only thing I am trying now is to figure out touch screen for MEGA shield - MEGA board.
Best regards.

Attach your program that is fully working with Uno shield on the Mega.

I will show you how to adapt it for XPT2046 Mega shield on the Mega.

Please make sure that your example is buildable (by me). i.e. it does not use unusual Sensors or hardware.

David.

I took your JPEG and used the online converter at the UTFT website

This produced a C file like this:

// Generated by   : ImageConverter 565 Online
// Generated from : bigicon100 x100.jpg
// Time generated : Mon, 02 Oct 17 20:06:07 +0200  (Server timezone: CET)
// Image Size     : 100x100 pixels
// Memory usage   : 20000 bytes


#if defined(__AVR__)
#include <avr/pgmspace.h>
#elif defined(__PIC32MX__)
#define PROGMEM
#elif defined(__arm__)
#define PROGMEM
#endif

const unsigned short bigicon100_x100[10000] PROGMEM = {
    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,   // 0x0010 (16) pixels
    0xFFFF, 0xFFFE, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFE, 0xFFFE, 0xFFFF, 0xFFFF, 0xF7FF, 0xF7FF, 0xF7FF,   // 0x0020 (32) pixels
...

and had to declare and use it like this:

extern const unsigned short bigicon100_x100[];
...
    x = logox, y = logoy, w = 100, h = 100;
    tft.setAddrWindow(x, y, x - 1 + w, y - 1 + h);
    // 4th argument MUST be used for little-endian
    // the UTFT utility rearranges the hi, lo to the default
    tft.pushColors((uint8_t*)bigicon100_x100, w * h, 1, 0);
...

i.e. absolutely no problem with a 20000 byte array.
Note that I cast it to (uint8_t*) even though it is actually uint16_t[]

I initially thought that your 4-part icon would have been 4 horizontal rectangles. One below the previous layer. I could have just concatenated your arrays into one big array.

Since you use 4 square tiles, it was not possible to use your data. Hence going to the online converter.

Looking at your Touch code:

  1. you call ts.getPoint() in a single place. that is GOOD
  2. you use the ADC values throughout the rest of your logic. that is BAD

I strongly suggest that you convert p.x, p.y to the pixel coordinates with the map() function.
Please change ALL of your code to use logical pixel_x and pixel_y

This will make your button position and detection far easier to maintain.

When you have done that, I will show you how to use your Uno and Mega shield in a convenient way. i.e. about 5 lines of code.

David.

Hi, David!

Big iconw now works perfectly, thank you :slight_smile:

Regarding your proposal:

"I strongly suggest that you convert p.x, p.y to the pixel coordinates with the map() function.
Please change ALL of your code to use logical pixel_x and pixel_y "

I am afraid that I do not what/how to do that. Maybe becouse of my bad Arduino programming skill..

I looked here:
https://www.arduino.cc/en/Reference/Map

but still do not know what do you mean to do.

Best regards.

EDIT1:
In mean time i studied the mamp() function.
So analogue readings give values from 0 to 1023 and my display is 480 pixels width.
The map function will then create values (if I correctly write the map()= function) between 0 and 480 (for width).
The problem I see is that for touch screen analogue readings start app at 115 and finish app 950.
And are not the same every time I make this test to find the left minimum and right value.
And then next, what to do with next screen who will have different top left and top right values?
Did I catch the point?

The Calibration values should be reasonably consistent. e.g. if TS_LEFT is 115 then it would be normal to find 110 or 120.

If you get wildly different values it implies something is seriously wrong with your hardware.

In practice, you should be able to distinguish between about 60 separate "buttons" on a screen.
Think about the Touch keypad on a Tablet. It works pretty well but sometimes adjacent keys get returned.

With say 12 buttons on a screen, you should never get any false keys.

My point was: read getPoint() and map it to the screen coordinates immediately.

Then your program logic has just got to compare the x,y with the button geography.
Look at the GFX_Button class that comes with Adafruit_GFX library. It has methods for drawing and detecting buttons.

David.

Hi!

I want to adjust touch screen library for Arduino Uno to work with touch screen for Mega2560 shield to work on Arduino Mega2560.

The idea is, for the start, to set old library on new pinout for Mega2560 shield.
Unfortunately I can not find pinout for this model. I tried to reach www.mcufriend.com page but I looks that this page have a virus becouse I can not reach it for more than three days.

Does anybody have pinout for touch screen for mcufriend 3.5" Mega2560 shield?

Thank you.

Thanks for editing your project. I have not forgotten you. I will post a solution for you. Probably this evening.

David.

Thank you.

:slight_smile: