lvgl / lv_binding_micropython

LVGL binding for MicroPython
MIT License
250 stars 161 forks source link

Support for ili9486 display (3.5inch RPi Display) #191

Closed GianK128 closed 2 years ago

GianK128 commented 2 years ago

Hello, like a month or so ago, I've created this thread on the forum. And I've been trying to get the driver to work with no results.

I've been able to make the display work with Bodmer's TFT_eSPI library. When trying that configuration, as well as other people's and even my own, the screen does not even change a little when initializing the driver. My thoughts are that it is not a matter of the initialization commands, but maybe a difference in how Bodmer handles writing to the memory of the display, and also that my current skill does not allow me to distinguish if there is an actual difference or not, or if it actually is a problem of my initialization code.

So I figured I'd post what I have here, please excuse me for the (probably) bad issue formatting.

This is the display I have: http://www.lcdwiki.com/3.5inch_RPi_Display. And these are the pin connections, which is missing one 5V right below the other one (what I mean is pin 2 and 4 are connected to 5V).

This is the initialization class I am trying with:

class ili9486(ili9XXX):

    def __init__(self,
        miso=5, mosi=18, clk=19, cs=13, dc=12, rst=4, power=14, backlight=15, backlight_on=0, power_on=0,
        spihost=esp.HSPI_HOST, mhz=40, factor=8, hybrid=True, width=320, height=480,
        colormode=COLOR_MODE_BGR, rot=PORTRAIT, invert=False, double_buffer=True, half_duplex=True,
        asynchronous=False, initialize=True
    ):

        if lv.color_t.__SIZE__ != 2:
            raise RuntimeError('ili9486 micropython driver requires defining LV_COLOR_DEPTH=16')
        if colormode == COLOR_MODE_BGR and not hasattr(lv.color_t().ch, 'green_l'):
            raise RuntimeError('ili9486 BGR color mode requires defining LV_COLOR_16_SWAP=1')

        self.display_name = 'ILI9486'
        self.display_type = DISPLAY_TYPE_ILI9486

        self.init_cmds = [
            # ustropo's & gfxlcd config (not working)
            #{'cmd': 0xB0, 'data': bytes([0x00])},                       # Interface Mode Control
            #{'cmd': 0x11, 'data': bytes([0]), 'delay': 120},            # Sleep OUT
            #{'cmd': 0x3A, 'data': bytes([0x55])},                       # Interface Pixel Format (55 = 16 bits)
            #{'cmd': 0xB6, 'data': bytes([0x0A, 0x02, 0x3B])},           # Display Function Control
            #{'cmd': 0xC2, 'data': bytes([0x44])},                       # Power Control 3, Normal Mode
            #{'cmd': 0xC5, 'data': bytes([0x00, 0x00, 0x00, 0x00])},     # VCOM Control
            #{'cmd': 0xE0, 'data': bytes([0x0F, 0x1F, 0x1C, 0x0C, 0x0F, 0x08, 0x48, 0x98, 0x37, 0x0A, 0x13, 0x04, 0x11, 0x00, 0x00])},   # Positive Gamma Correction
            #{'cmd': 0xE1, 'data': bytes([0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75, 0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00])},   # Negative Gamma Correction
            #{'cmd': 0xE2, 'data': bytes([0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75, 0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00])},   # Digital Gamma Control
            #{'cmd': 0x36, 'data': bytes([rot | colormode])},            # Memory Access Control
            #{'cmd': 0x11, 'data': bytes([0]), 'delay': 120},            # Sleep OUT
            #{'cmd': 0x29, 'data': bytes([0]), 'delay': 120}             # Display ON

            # lvgl_esp32_drivers & Bodmer's config (not working)
            {'cmd': 0x11, 'data': bytes([0]), 'delay': 120},            # Sleep OUT
            {'cmd': 0x3A, 'data': bytes([0x55])},                       # Interface Pixel Format (55 = 16 bits)
            {'cmd': 0xC2, 'data': bytes([0x44])},                       # Memory Write
            {'cmd': 0xC5, 'data': bytes([0x00, 0x00, 0x00, 0x00])},     # VCOM Control
            {'cmd': 0xE0, 'data': bytes([0x0F, 0x1F, 0x1C, 0x0C, 0x0F, 0x08, 0x48, 0x98, 0x37, 0x0A, 0x13, 0x04, 0x11, 0x00, 0x00])},   # Positive Gamma Correction
            {'cmd': 0xE1, 'data': bytes([0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75, 0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00])},   # Negative Gamma Correction
            {'cmd': 0x20, 'data': bytes([0])},                          # Inversion OFF
            {'cmd': 0x36, 'data': bytes([rot | colormode])},            # Memory Access Control
            {'cmd': 0x29, 'data': bytes([0]), 'delay': 150}             # Display ON

            # Waveshare_ILI9486 config (not working)
            #{'cmd': 0xC0, 'data': bytes([0x19, 0x1A])},                 # Power Control 1
            #{'cmd': 0xC1, 'data': bytes([0x45, 0x00])},                 # Power Control 2
            #{'cmd': 0xC2, 'data': bytes([0x33])},                       # Power Control 3, Normal Mode
            #{'cmd': 0xC5, 'data': bytes([0x00, 0x28])},                 # VCOM Control
            #{'cmd': 0xB1, 'data': bytes([0xA0, 0x11])},                 # Frame Rate Control
            #{'cmd': 0xB4, 'data': bytes([0x02])},                       # Display Inversion Control
            #{'cmd': 0xB6, 'data': bytes([0x00, 0x42, 0x3B])},           # Display Function Control
            #{'cmd': 0xE0, 'data': bytes([0x1F, 0x25, 0x22, 0x0B, 0x06, 0x0A, 0x4E, 0xC6, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])},   # Positive Gamma Correction
            #{'cmd': 0xE1, 'data': bytes([0x1F, 0x3F, 0x3F, 0x0F, 0x1F, 0x0F, 0x46, 0x49, 0x31, 0x05, 0x09, 0x03, 0x1C, 0x1A, 0x00])},   # Negative Gamma Correction
            #{'cmd': 0x3A, 'data': bytes([0x55])},                       # Interface Pixel Format (55 = 16 bits)
            #{'cmd': 0x11, 'data': bytes([0]), 'delay': 120},            # Sleep OUT
            #{'cmd': 0x20, 'data': bytes([0])},                          # Inversion OFF
            #{'cmd': 0x36, 'data': bytes([rot | colormode])},            # Memory Access Control
            #{'cmd': 0x29, 'data': bytes([0]), 'delay': 150} 

            # way5's stm32 config (not working)
            #{'cmd': 0xB0, 'data': bytes([0x00])},                       # Interface Mode Control
            #{'cmd': 0x3A, 'data': bytes([0x55])},                       # Interface Pixel Format (55 = 16 bits)
            #{'cmd': 0xE0, 'data': bytes([0x0F, 0x1F, 0x1C, 0x0C, 0x0F, 0x08, 0x48, 0x98, 0x37, 0x0A, 0x13, 0x04, 0x11, 0x00, 0x00])},   # Positive Gamma Correction
            #{'cmd': 0xE1, 'data': bytes([0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75, 0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00])},   # Negative Gamma Correction
            #{'cmd': 0xE2, 'data': bytes([0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75, 0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00])},   # Digital Gamma Control
            #{'cmd': 0x36, 'data': bytes([rot | colormode])},            # Memory Access Control
            #{'cmd': 0x38, 'data': bytes([0])},                          # Idle Mode OFF
            #{'cmd': 0xB1, 'data': bytes([0xB0, 0x11])},                 # Frame Rate Control     
            #{'cmd': 0xC2, 'data': bytes([0x55])},                       # Power Control 3, Normal Mode
            #{'cmd': 0xB4, 'data': bytes([0x02])},                       # Display Inversion Control
            #{'cmd': 0xB6, 'data': bytes([0x02, 0x22, 0x3B])},           # Display Function Control
            #{'cmd': 0x11, 'data': bytes([0]), 'delay': 150},            # Sleep OUT
            #{'cmd': 0x29, 'data': bytes([0]), 'delay': 150}             # Display ON

            # My own config (not working, too)
            #{'cmd': 0xB0, 'data': bytes([0x00])},                       # Interface Mode Control
            #{'cmd': 0xC0, 'data': bytes([0x13, 0x13])},                 # Power Control 1
            #{'cmd': 0xC1, 'data': bytes([0x42, 0x30])},                 # Power Control 2
            #{'cmd': 0xC2, 'data': bytes([0x44])},                       # Power Control 3, Normal Mode
            #{'cmd': 0xC5, 'data': bytes([0x00, 0x00, 0x00, 0x00])},     # VCOM Control
            #{'cmd': 0x36, 'data': bytes([rot | colormode])},            # Memory Access Control
            #{'cmd': 0x3A, 'data': bytes([0x55])},                       # Interface Pixel Format (55 = 16 bits)
            #{'cmd': 0xB1, 'data': bytes([0xB0, 0x17])},             
            #{'cmd': 0xE0, 'data': bytes([0x0F, 0x1F, 0x1C, 0x0C, 0x0F, 0x08, 0x48, 0x98, 0x37, 0x0A, 0x13, 0x04, 0x11, 0x00, 0x00])},   # Positive Gamma Correction
            #{'cmd': 0xE1, 'data': bytes([0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75, 0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00])},   # Negative Gamma Correction
            #{'cmd': 0xE2, 'data': bytes([0x0F, 0x32, 0x2E, 0x0B, 0x0D, 0x05, 0x47, 0x75, 0x37, 0x06, 0x10, 0x03, 0x24, 0x20, 0x00])},   # Digital Gamma Control
            #{'cmd': 0x2A, 'data': bytes([0x00, 0x00, 0x01, 0x3F])},     # Column Address Set
            #{'cmd': 0x2B, 'data': bytes([0x00, 0x00, 0x01, 0xDF])},     # Page Address Set
            #{'cmd': 0x2C, 'data': bytes([0])},
            #{'cmd': 0xB7, 'data': bytes([0x07])},                       # Entry Mode Set
            #{'cmd': 0xB6, 'data': bytes([0x0A, 0x02, 0x3B])},           # Display Function Control
            #{'cmd': 0x11, 'data': bytes([0]), 'delay': 120},            # Sleep OUT
            #{'cmd': 0x29, 'data': bytes([0]), 'delay': 120}             # Display ON
        ]

        super().__init__(miso, mosi, clk, cs, dc, rst, power, backlight, backlight_on, power_on,
            spihost, mhz, factor, hybrid, width, height, colormode, rot, invert, double_buffer, half_duplex,
            asynchronous=asynchronous, initialize=initialize)
amirgon commented 2 years ago

I've been able to make the display work with Bodmer's TFT_eSPI library. When trying that configuration, as well as other people's and even my own, the screen does not even change a little when initializing the driver.

I suggest you use a Logic Analyzer to see what happens on the SPI lines.
Compare the working driver vs. your driver and see what are the differences.