Problem with libraries for ST7796S using Uno/Mega sheild

Hi. I recently bought the following ST7796S based display for use with Uno or Mega. http://www.lcdwiki.com/3.95inch_Arduino_Display-UNO. Downloaded and installed the relevant LCDWIKI libraries and examples. I am using with a Mega2560.

Was able to successfully run the _ST7796S_Mega2560.ino example sketch which doesn't use the LCDWIKI libraries. When I tried running the other examples which make use of the libraries, all I achieved was a white screen. I have examined all the supplied library files and have a fairly good understanding of how they work.

I notice that in the file lcd_mode.h there is the following macro.

define USE_8BIT_SHIELD_ON_MEGA 0 which should be commented out according to the comments.

There is also a line in the file LCDWIKI_KBV.h //#define USE_ADAFRUIT_SHIELD_PIN 1 which I believe should be uncommented. If I change either of these lines from the default I get a massive amount of errors when compiling.

I feel I have spent more than enough hours trying to solve the problem and would rather work on the application that I bought the screen for. Would be grateful if someone could advise me of the modifications I need to the library files. Even better would be if someone who has had success with this display could upload a fully functional program that uses all of the displays features including touch & sd card functions, along with the modified library files.

thanks.

MCUFRIEND_kbv has supported ST7796 since v2.9.2 (Jan 2017)

I suggest that you install Adafruit_GFX and MCUFRIEND_kbv via the IDE Library Manager. Run all the examples. Report back with any problems.

I have never owned a ST7796 shield. I rely on feedback from User: safari1

I have recently bought a ST7796S SPI display. I have discovered "features". So I ordered a parallel Shield from AliExpress to test MCUFRIEND_kbv for myself. The Shield has not arrived yet.

If you provide feedback, I can probably get you going before I receive my hardware. graphictest_kbv.ino should show any glitches, bad colours, directions, scroll, ... readpixel_kbv.ino should show any readGRAM() problems.

David.

Hi David. I have followed your suggestions with partial success. GLUE_Demo_480x320, and graphictest_kbv both draw to screen but seem to be limited to a 320 x 240 window on the screen and all of the text is a mirror image of what it should be. The scroll_kbv sketch also works but none of your other examples work. I am assuming that the ST7796 command set and registers are different to other controllers but you have said your library supports it. Below is the output from the serial monitor when I upload LCD_ID_readreg.

Read Registers on MCUFRIEND UNO shield controllers either read as single 16-bit e.g. the ID is at readReg(0) or as a sequence of 8-bit values in special locations (first is dummy)

reg(0x0000) 00 00 ID: ILI9320, ILI9325, ILI9335, ... reg(0x0004) 00 6B FF FF Manufacturer ID reg(0x0009) 00 00 61 00 00 Status Register reg(0x000A) 08 08 Get Powsr Mode reg(0x000C) 66 66 Get Pixel Format reg(0x0061) 00 00 RDID1 HX8347-G reg(0x0062) 00 00 RDID2 HX8347-G reg(0x0063) 00 00 RDID3 HX8347-G reg(0x0064) 00 00 RDID1 HX8347-A reg(0x0065) 00 00 RDID2 HX8347-A reg(0x0066) 00 00 RDID3 HX8347-A reg(0x0067) 00 00 RDID Himax HX8347-A reg(0x0070) 00 00 Panel Himax HX8347-A reg(0x00A1) 00 00 00 00 00 RD_DDB SSD1963 reg(0x00B0) 00 00 RGB Interface Signal Control reg(0x00B4) 01 01 Inversion Control reg(0x00B6) 80 02 3B 00 00 Display Control reg(0x00B7) 06 06 Entry Mode Set reg(0x00BF) 00 00 00 00 00 00 ILI9481, HX8357-B reg(0x00C0) 80 25 00 00 00 00 00 00 80 Panel Control reg(0x00C8) 00 00 00 00 00 00 00 00 00 00 00 00 00 GAMMA reg(0x00CC) 00 00 Panel Control reg(0x00D0) 00 00 FF Power Control reg(0x00D2) 01 01 00 01 00 NVM Read reg(0x00D3) 00 00 77 96 ILI9341, ILI9488 reg(0x00DA) 6B 6B RDID1 reg(0x00DB) FF FF RDID2 reg(0x00DC) FF FF RDID3 reg(0x00E0) F0 03 05 09 0C 0F 3E 77 4F 0F 17 17 21 23 00 00 GAMMA-P reg(0x00E1) F0 03 05 09 0C 0F 3E 77 4F 0F 17 17 21 23 00 00 GAMMA-N reg(0x00EF) 00 00 00 00 00 00 ILI9327 reg(0x00F2) DD DD DD DD DD DD DD DD DD DD DD DD Adjust Control 2 reg(0x00F6) FF FF FF FF Interface Control

It seems the only available 4" screens on aliexpress all use the ST7796 controller. I guess if I bought a 3.5" model with a ILI9486 it would be more likely to work with existing libraries but id prefer to use the 4". Id also prefer to use the parallel interface rather than the SPI as I have already designed my pcb and had it manufactured and would have to make some slight modifications. Anway I see that you are awaiting delivery of the same shield so I guess you will have it functioning before long once you receive it. Will try any other suggestions you can give me, but am quite happy to wait until you have got yours running before you reply.

thanks, Craig.

Yes, you have an ST7796

reg(0x00D3) 00 00 77 96   ILI9341, ILI9488

What ID is reported to the Serial Terminal by MCUFRIEND_kbv examples ? e.g. graphictest_kbv

Please edit setup() in graphictest_kbv.ino e.g.

    uint16_t ID = tft.readID(); //
    Serial.print("ID = 0x");
    Serial.println(ID, HEX);
    if (ID == 0xD3D3) ID = 0x9481; // write-only shield
    ID = 0x7796;                             // force ID
    tft.begin(ID);

In the Adafruit Tests Report screen it shows the ID. You should be able to read it even if mirrored.

Copy-paste the Serial Terminal from the diagnose_TFT_controller sketch.

I suspect that the ID is being read as 0x0000. In which case you change code in all the examples e.g.

    uint16_t ID = tft.readID(); //
    if (ID == 0) ID = 0x7796; //
    tft.begin(ID);

The GLUE_Demo will only work if ID is read correctly. Edit UTFTGLUE.h

         uint16_t ID = MCUFRIEND_kbv::readID();
         if (ID == 0) ID = 0x7796;        //force the ID

David.

Hi, the id shown in serial terminal is 0x0 for all examples. I tried changing the identifier in the example sketches and UTFTGLUE.h to 0x7796 and I got the white screen so I tried other identifiers and found that 0x9488 worked correctly for all the graphics and text at the full 480x320 resolution. Now that the graphics are functioning correctly I tried the touchscreen examples. None of the three examples responded to touching anywhere on the screen. The output from Touch_shield_kbv is as follows.

Found ILI9488 LCD driver ID=0x9488 Screen is 320x480 Calibration is: LEFT = 904 RT = 170 TOP = 950 BOT = 158 Wiring is: PORTRAIT YP=55 XM=56 YM=7 XP=6

Also you mentioned the diagnose_TFT_controller sketch. I cannot find a sketch of this name in any of the downloaded folders. Thanks, Craig.

diagnose_TFT_controller should have been diagnose_TFT_support. First came with v2.9.7
Current Release is v2.9.8

My shield has cleared Customs. So it should arrive soon.

I will be able to see why readID() is not working.
And investigate the features that appear on my SPI ST7796

David.

My ST7796 Uno Shield arrived today.

MCUFRIEND_kbv identified 0x7796 correctly.

graphictest_kbv: Vertical Scroll was horrible in Portrait, Landscape, Portrait_Rev. Ok in Landscape_Rev

I have added a specific initialisation sequence for ST7796. Edit MCUFRIEND_kbv.cpp in current Release v2.9.8

Change

    case 0x7796:
        _lcd_capable = AUTO_READINC | MIPI_DCS_REV1 | MV_AXIS;   //thanks to safari1
        goto common_9488;

to this:

    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 updated the Beta on GitHub. But it is simple to edit the regular Library Manager installed Release v2.9.8

Please let me know how you get on.

David.

Hi David. Maybe I had an older version of MCUFRIEND. After Deleting and redownloading the library, the graphics examples are all working fine and the id is now detected correctly. I don’t have a spare SD card for testing the sd reader but uploaded the example showBMP_kbv_Uno. The result was a blue screen. The showBMP_not_Uno example would not compile even after downloading the SdFat library I got the following error

showBMP_not_Uno:18:1: error: ‘SdFatSoftSpi’ does not name a type; did you mean ‘SdFatConfig_h’?

SdFatSoftSpi<12, 11, 13> SD; //Bit-Bang on the Shield pins

^~~~~~~~~~~~

SdFatConfig_h

Plus some other errors saying ‘SD’ was not declared in this scope.

TouchScreen_Calibr_native example worked and gave me the following output

TouchScreen.h GFX 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 : (A2, D8) = 21
Testing : (A3, D9) = 31
Diagnosing as:-
XM,XP: (A2, D8) = 21
YP,YM: (A3, D9) = 31
ID = 0x7796

cx=894 cy=77 cz=696 LEFT, TOP, Pressure
cx=906 cy=500 cz=547 LEFT, MIDH, Pressure
cx=902 cy=924 cz=419 LEFT, BOT, Pressure
cx=506 cy=80 cz=631 MIDW, TOP, Pressure
cx=523 cy=922 cz=282 MIDW, BOT, Pressure
cx=146 cy=79 cz=633 RT, TOP, Pressure
cx=141 cy=504 cz=428 RT, MIDH, Pressure
cx=170 cy=894 cz=217 RT, BOT, Pressure
MCUFRIEND_kbv ID=0x7796 320 x 480

const int XP=8,XM=A2,YP=A3,YM=9; //320x480 ID=0x7796
const int TS_LEFT=924,TS_RT=127,TS_TOP=59,TS_BOT=931;
PORTRAIT CALIBRATION 320 x 480
x = map(p.x, LEFT=924, RT=127, 0, 320)
y = map(p.y, TOP=59, BOT=931, 0, 480)
Touch Pin Wiring XP=8 XM=A2 YP=A3 YM=9
LANDSCAPE CALIBRATION 480 x 320
x = map(p.y, LEFT=59, RT=931, 0, 480)
y = map(p.x, TOP=127, BOT=924, 0, 320)

Touch_shield_new doesn’t work. It Says Please Calibrate near top of screen. How must I do this and must this be done for it to work?
Thanks,
Craig.

I had an older version of MCUFRIEND.

Where did it come from?

uploaded the example showBMP_kbv_Uno. The result was a blue screen

You had no SD card !! It probably reports on Serial.

after downloading the SdFat library

God gave you the IDE Library Manager. Never "download" from random places on the Internet.

showBMP_not_Uno:18:1: error: 'SdFatSoftSpi' does not name a type; did you mean 'SdFatConfig_h'?

Not only should you install via the Library Manager, you have to edit the SdFatConfig.h file

TouchScreen_Calibr_native example worked and gave me the following output

const int XP=8,XM=A2,YP=A3,YM=9; //320x480 ID=0x7796
const int TS_LEFT=924,TS_RT=127,TS_TOP=59,TS_BOT=931;

Touch_shield_new doesn't work. It Says Please Calibrate near top of screen. How must I do this and must this be done for it to work?

Touch_shield_new.ino expects you to copy-paste the two Calibration lines that you got from the Calibration sketch.

Thanks for the feedback.

I will make SD sketch show a RED screen for errors. I will try to make the Calibration sketch instructions clearer.

David.