Hello ,
I by this 3.95/4" TFT LCD Mega Shield 320x480 , 8-bit and with ST7796 driver.
https://www.aliexpress.com/item/4000275142406.html?spm=a2g0s.9042311.0.0.103c4c4daTteWd
I have already experience with 3.5" TFT ILI9486 driver and use Bodmers HX8357 drivers , but with this LCD I am confused.
Firs I am confused because it is with ST7796S driver but I never find library with him .
I try WIKIS Driver 4.0inch Arduino Display-Mega2560 - LCD wiki and I have white screen .
Where I make mistake ?
Thanks

Your link shows a write-only shield with 8080-8 parallel interface.
This is supported by MCUFRIEND_kbv as USE_MEGA_8BIT_SHIELD "special"
Since it is write-only, you will have to experiment with ID. e.g. 0x9486, 0x9488, 0x7796, ..., 0x6814, ...
Your photo shows a write-only shield with 8080-8 parallel interface (and optional 8080-16 interface)
This is supported by MCUFRIEND_kbv as USE_MEGA_16BIT_SHIELD "special"
Note that the Touch and SD chip-selects are on unusual pins.
I have the shield in your link. The LCD_RD pin is useless. The pcb design is flawed. I would be 99.5% confident that your 8080-8/16 pcb design is equally flawed.
David.
Hi david
You have the same shield ?

I try with Yours instructions : #1663 ( May 31, 2017, 11:57 pm ) but no success .
Thanks
What instructions #1663 ?
Please post a link. I have 7742 Posts.
Your pcb is different to the photo in your Aliexpress link.
My pcb does not have U2, R5, R4
My pcb uses DB8-DB15 i.e. U3 buffer.
What values are R2, R3, R1, R5, R4 ?
What is printed on the pcb ? I can't see from your photo
David.
This is Post #1633
From utility/mcufiend_shield.h:
#define USE_SPECIAL //check for custom drivers
#if defined(USE_SPECIAL)
#include "mcufriend_special.h"
...
From utility/mcufiend_special.h:
...
//#define USE_MEGA_8BIT_PROTOSHIELD
#define USE_MEGA_8BIT_SHIELD
//#define USE_MEGA_16BIT_SHIELD //RD on PL6 (D43)
...
I don't know how much easier an "editing" process can be. Remove the two slashes as marked in red //
In graphictest_kbv.ino setup() function:
...
uint16_t ID = tft.readID(); //
Serial.print("ID = 0x");
Serial.println(ID, HEX);
if (ID == 0xD3D3) ID = 0x9090; // write-only shield
Anyway is the same " white screen" .My Pcb is newer as Yours because I have U2 and R1-R5.
R4 and R5 are 0 Ohm Jumpers for selecting 8bit/16bit interface.Now is R4 in and R5 out and it is for 8bir setup.I will try to setup 16bit.
What is printed next to the R4 and R5 footprints?
Are both R4 and R5 mounted?
What values are R2, R3, R1 ?
Can you solder SMD resistors?
If you answer my questions, I can offer solutions that do not involve soldering.
God invented printed messages on pcbs. You only have to type what messages you see for R4, R5. Easier than attempting a focussed photo.
David.
Ok
R1 is 2 ohm writed 2R0
R2 is 10K " 103
R3 is 10K " 103
R4 is 0Ohm jumper for 8 bit mode and out for 16 bit mode
R5 is 0Ohm jumper for 16bit mode and out for 8 bit mode
R4 and R5 are never both mounted .
Originaly was R4 mounted and R5 out
I can solder SMD , specially I will setup for 16 bit mode.
I try with 16 bit and it works with 9481 driver.But the picture on the screen is inverted.
Last update , everything works fine with 9488 .
David thanks for support
What is printed next to the R4 and R5 footprints?
I would really like an answer to this question.
Other readers might buy the same Shield as you. But not know how to solder SMD.
Please add this block to your mcufriend_special.h
#elif defined(__AVR_ATmega2560__) && defined(USE_MEGA_8BIT_PORTC_SHIELD)
#warning USE_MEGA_8BIT_PORTC_SHIELD for Mihael54
#define RD_PORT PORTL
#define RD_PIN 6 //PL6 (D43). Graham has PA15 (D24) on Due Shield
#define WR_PORT PORTG
#define WR_PIN 2 //D39 CTE
#define CD_PORT PORTD
#define CD_PIN 7 //D38 CTE
#define CS_PORT PORTG
#define CS_PIN 1 //D40 CTE
#define RESET_PORT PORTG
#define RESET_PIN 0 //D41 CTE
#define write_8(x) { PORTC = x;}
#define read_8() ( PINC )
#define setWriteDir() { DDRC = 0xFF; }
#define setReadDir() { DDRC = 0x00; }
#define write8(x) { write_8(x); WR_ACTIVE; WR_STROBE; } // HX8357-D is slower
#define write16(x) { uint8_t h = (x)>>8, l = x; write8(h); write8(l); }
#define READ_8(dst) { RD_STROBE; dst = read_8(); RD_IDLE; }
#define READ_16(dst) { RD_STROBE; dst = read_8(); RD_IDLE; RD_STROBE; dst = (dst<<8) | read_8(); RD_IDLE; }
#define PIN_LOW(p, b) (p) &= ~(1<<(b))
#define PIN_HIGH(p, b) (p) |= (1<<(b))
#define PIN_OUTPUT(p, b) *(&p-1) |= (1<<(b))
Follow the procedure in #4
For shields without U2 chip:
#define USE_MEGA_8BIT_SHIELD
For shields with U2 chip and configured for 8-bit:
#define USE_MEGA_8BIT_PORTC_SHIELD
For shields with U2 chip and configured for 16-bit:
#define USE_MEGA_16BIT_SHIELD
In your sketch, you will have to force the ID e.g.
uint16_t ID = tft.readID(); //
if (ID == 0xD3D3) ID = 0x7796; // write-only shield
tft.begin(ID); //use correct ID for your controller
I would be very grateful if you could configure for 16-bit and 0x7796. Report the result.
And then configure for 8-bit PORTC and 0x7796. i.e. as it came out of the box.
If 0x7796 does not give 100% directions, try other 320x480 ID values from the how_to file.
David.
Picture with R4 and R5 is atach .
For shields with U2 chip and configured for 16-bit:
Please add this block to your mcufriend_special.h
#define USE_MEGA_16BIT_SHIELD
in graphictest_kbv.ino
uint16_t ID = tft.readID(); //
Serial.print("ID = 0x");
Serial.println(ID, HEX);
if (ID == 0xD3D3) ID = 0x7796; // write-only shield
// ID = 0x9329; // force ID
tft.begin(ID);
It runs fine wih ID = 0x7796 and with 0x9488 .With 0x9486 did not work .
I try also Bodmers librarys and when in User_Setup.h is defined ILI9481 , it runs well.
So , now I will change setup to 8 bit and give the result later.
Thanks for the clear photo of the pcb. The text says:
R5 16Bit (DB0~DB15)
R4 8Bit (DB0~DB7)
MCUFRIEND_kbv was written for the read-write Uno shields. You can read the controller ID.
It is possible to use MCUFRIEND_kbv with write-only shields (as a SPECIAL)
But you have to guess the controller type.
Likewise, Bodmer lets you configure the controller type in User_Setup.h
Or Henning Karlsen lets you configure the controller model in the UTFT constructor
Different controllers have different Manufacturer registers but most modern controllers have the same User registers.
That is why ST7796 might display a User sketch on a library configured for ILI9481. However you risk serious damage when the wrong Manufacturer Power registers are set to the wrong values.
I support more controllers than most other libraries. Since I would never trust your Aliexpress Shop, I would experiment with different IDs. Obviously starting with controller "claimed" by the Shop.
David.
David ,this is with 8bit setup and with block to mcufriend_special.h
But did not work .
Arduino: 1.8.10 (Windows 8.1), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
In file included from C:\Users\Milenko\Documents\Arduino\libraries\MCUFRIEND_kbv-master\utility/mcufriend_shield.h:16:0,
from C:\Users\Milenko\Documents\Arduino\libraries\MCUFRIEND_kbv-master\MCUFRIEND_kbv.cpp:35:
C:\Users\Milenko\Documents\Arduino\libraries\MCUFRIEND_kbv-master\utility/mcufriend_special.h:22:2: error: #elif without #if
I will setup now for 16 bit.
You can see how to add the USE_MEGA_8BIT_PORTC_SHIELD block to the special.h by looking at your existing USE_MEGA_8BIT_SHIELD and USE_MEGA_16BIT_SHIELD blocks
This is the important lines from my build report:
#warning USE_MEGA_8BIT_PORTC_SHIELD for Mihael54
^
In file included from C:\Users\David Prentice\Documents\Arduino\libraries\Mcufriend_kbv\MCUFRIEND_kbv.cpp:35:0:
C:\Users\David Prentice\Documents\Arduino\libraries\Mcufriend_kbv\utility/mcufriend_shield.h:18:2: warning: #warning WE ARE USING A SPECIAL CUSTOM DRIVER [-Wcpp]
#warning WE ARE USING A SPECIAL CUSTOM DRIVER
^
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino-1.8.9\hardware\arduino\avr\libraries\SPI
Using library Adafruit_GFX_Library at version 1.7.3 in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Adafruit_GFX_Library
Using library Mcufriend_kbv at version 2.9.9-Beta in folder: C:\Users\David Prentice\Documents\Arduino\libraries\Mcufriend_kbv
"C:\\Program Files (x86)\\Arduino-1.8.9\\hardware\\tools\\avr/bin/avr-size" -A "C:\\Users\\DAVIDP~1\\AppData\\Local\\Temp\\arduino_build_425669/graphictest_kbv.ino.elf"
Sketch uses 30538 bytes (12%) of program storage space. Maximum is 253952 bytes.
Global variables use 1600 bytes (19%) of dynamic memory, leaving 6592 bytes for local variables. Maximum is 8192 bytes.
Obviously this is untested. I don't have your hardware.
The #warning USE_MEGA_8BIT_PORTC_SHIELD for Mihael54 line is printed in Orange
You only get the warning when you build for the first time. Subsequent builds just say:
Using previously compiled file:
David.
Hi David ,
I cant change the pcb to 8 bit , I'm scared to damage by soldering always .
So I stay with 16 bit setup , it runs good .
Thans for your help .
Regards Mihael
No problem. The next purchaser can try it.
I have updated the Beta on GitHub. So it will be easier for her.
Since you have a Mega shield with 16-bit buffers there is no point in using 8-bit mode.
You will get a better performance with 8080-16 interface anyway. ( 8x faster than a Uno shield on a Mega)
David.
Hello,
I allow myself to unearth this topic because I also encounter a compatibility problem between the ST7796S and the mega 2560
I buy this model on Aliexpress
https://fr.aliexpress.com/item/33057452144.html?spm=a2g0s.9042311.0.0.27426c37FblNPT
All the examples of this lib work on Uno but only the first example works on mega:
http://www.lcdwiki.com/index.php?title=3.95inch_Arduino_Display-UNO&oldid=3318
Do you have any idea why? the mega Pinout are identical to the uno. only the SPI port changes. lib seems to be designed in this sense. Can you help me understand why it doesn't work on mega?
I have this Uno read-write shield. i.e. from your link in #14.
It "almost works" out of the box with MCUFRIEND_kbv v2.9.8 Release (i.e. as installed by the Library Manager)
However it works 100% in the Beta on GitHub.
Either install the Beta.
Or edit your v2.9.8 file MCUFRIEND_kbv.cpp e.g. in the begin() method:
case 0x7796:
_lcd_capable = AUTO_READINC | MIPI_DCS_REV1 | MV_AXIS; //thanks to safari1
static const uint8_t PROGMEM ST7796_regValues[] = {
0xB7, 1, 0xC6, //Entry Mode [06]
0xE8, 8, 0x40, 0x8A, 0x00, 0x00, 0x29, 0x19, 0xA5, 0x33, //Adj3 [40 8A 00 00 25 0A 38 33]
};
table8_ads = ST7796_regValues, table_size = sizeof(ST7796_regValues);
p16 = (int16_t *) & HEIGHT;
*p16 = 480;
p16 = (int16_t *) & WIDTH;
*p16 = 320;
break;
//goto common_9488;
I have no connection with LCDWIKI.
David.
Thank you so much! I will use it. I can't find a beta version of MCUFRIEND_kbv on github MCUFRIEND_kdv
I advise you to just install the regular v2.9.8 Release via the IDE Library Manager.
It should "work 90%".
Then edit your v2.9.8 file MCUFRIEND_kbv.cpp begin() method as I showed in #15.
It should work 100%.
David.
p.s. The "master" branch in a GitHub repository is generally referred to as the "current Beta"
A Beta should always "work" but might not be perfect. It is always better to install an official Release unless you have been advised to use another Branch. "test_xxx" branches should only be used when the author directs you.
Awesome! It works, even the emulation of SPI. Thank you very much for your library.
The only thing that doesn't work is the button_simple example because the touch doesn't respond. It responds very well in the calibration example
The Calibration sketch will work.
Copy-paste the two "const int" statements from the Serial Terminal to the "button_simple" sketch.
You will notice that your shield uses 8, 9, A2, A3 pins whereas most 2.4 inch shields use 6. 7, A1, A2 pins.
David.