Landscape not available with ILI9341 and ESP32?

Hi all,
I’m on quite a steep learning curve here during country lockdown. In the past I was only using arduino IDE, but now I learned ESP32, lvgl, python, github, and now micropython. So far so good.
But now I run in something stupid. After successfully building and downloading lv_micropython I can write code and design nice screens, but ONLY in portrait. I found a post about changing to landscape, but this doesn’t seem to work. When I try to use landscape mode I always get this:

AttributeError: type object ‘ili9341’ has no attribute ‘LANDSCAPE’

I tried it with ili9XXX, ili9341, directly MADCTL_MV, but so far no luck.
Can anyone point me in the right direction?

import lvgl as lv
import lvesp32
from ili9XXX import ili9341

disp = ili9341(

Hi @bvlet!

The best thing to do when you are not sure about the syntax, is examine the sources.
The LANDSCAPE constant is defined in so you can simply:

 from ili9XXX import ili9341, LANDSCAPE

When you say “no luck” do you mean that you get the same error when running the code? Other errors? Or do you mean that it runs without errors but does not do what you expect?

Sorry for my late reply, I was a bit busy last two days.
But I’m very thankful for your post! Because in the end the only thing I forgot to do was, to put “LANDSCAPE” in the import. After I did this, everything worked fine, and the syntax I used was correct after all.

I can’t believe I missed this point, I must have had some tunnel vision looking only at the initialization code. I kept getting the AttributeError in the REPL. I would’ve thought that


would do the same, but apparently not…

Thank you very much, I can go on now :slight_smile:


I have a file like this:

import lvgl as lv
from ili9XXX import ili9341, LANDSCAPE, PORTRAIT
from xpt2046 import xpt2046

MADCTL_MY = const(0x80)
MADCTL_MX = const(0x40)
MADCTL_ML = const(0x10)
MADCTL_MH = const(0x04)

display = None
touch = None

def getdisplay():
    global display
    global touch
    return getdisplay_landscape()

def getdisplay_landscape():
    global display
    global touch
    # Import ILI9341 driver and initialized it
    if display is not None:
        return display
    display = ili9341(miso=19, mosi=23, clk=18, cs=26, dc=5, rst=33, power=-1, backlight=-1, mhz=40, double_buffer=False, factor=8, hybrid=True, width=320, height=240, rot=LANDSCAPE)
    # Import XPT2046 driver and initalize it
    touch = xpt2046(cs=27, transpose=False, cal_x0=3865, cal_y0=329, cal_x1=399, cal_y1=3870)
    print("Display in landscape mode")

def getdisplay_portrait():
    global display
    global touch
    if display is not None:
        return display
    # Import ILI9341 driver and initialized it
    display = ili9341(miso=19, mosi=23, clk=18, cs=26, dc=5, rst=33, power=-1, backlight=-1, mhz=40, double_buffer=false, factor=8, hybrid=False, rot=MADCTL_MY)

    # Import XPT2046 driver and initialize it
    touch = xpt2046(cs=27, transpose=True, cal_x0=258, cal_y0=420, cal_x1=3884, cal_y1=3945)
    print("Display in portrait mode")