Skip to content

Two Issues with ESP32-S3-BOX-3: GT911 Touch Offset and SD Card Driver Problems #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kk8900 opened this issue Apr 9, 2025 · 5 comments

Comments

@kk8900
Copy link

kk8900 commented Apr 9, 2025

Hello,

I'm encountering two issues while using the ESP32-S3-BOX-3 development board from Espressif. I hope someone can help me out. The development board documentation can be found here: [ESP-BOX AIoT Development Framework](https://github.com/espressif/esp-box).

Issue 1: GT911 Touch Offset

The display works fine, but there is a touch offset. The touch only works correctly when I touch about 5-10 mm below the slider. I have referred to [GT911 Initialization failed and it cannot be used with board](https://github.com/espressif/esp-box/issues/XXX), but the problem still persists.

Code to Test Display and Touch Functions

import screen
import lvgl as lv

scrn = lv.screen_active()
scrn.set_style_bg_color(lv.color_hex(0x000000), 0)
slider = lv.slider(scrn)
slider.set_size(300, 50)
slider.center()

label = lv.label(scrn)
label.set_text('HELLO LVGL_MICROPYTHON!')
label.align(lv.ALIGN.CENTER, 0, -50)

screen.py

import lcd_bus
from micropython import const
import machine
import lcd_utils

spi_bus = machine.SPI.Bus(
    host=1,
    mosi=6,
    miso=-1,
    sck=7,
)

display_bus = lcd_bus.SPIBus(
    spi_bus=spi_bus,
    freq=40000000,
    dc=4,
    cs=5
)

import ili9341
import lvgl as lv

ili9341.ILI9341._ORIENTATION_TABLE = (
    0x0,
    0x60,
    0x40 | 0x80,
    0x20 | 0x40 | 0x80
)

display = ili9341.ILI9341(
    data_bus=display_bus,
    display_width=320,
    display_height=240,
    backlight_pin=47,
    color_space=lv.COLOR_FORMAT.RGB565,
    color_byte_order=ili9341.BYTE_ORDER_BGR,
    rgb565_byte_swap=True,
)

import i2c
import task_handler
import gt911, pointer_framework

display.init(2)

i2c_bus = i2c.I2C.Bus(host=0, scl=18, sda=8, freq=400000, use_locks=False)
touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=0x5D, reg_bits=gt911.BITS)

indev = gt911.GT911(touch_dev, startup_rotation=pointer_framework.lv.DISPLAY_ROTATION._180)

display.set_backlight(1)

if not indev.is_calibrated:
    indev.calibrate()
    indev._cal.mirrorX = False
    indev._cal.mirrorY = True
    indev._cal.save()

indev.enable_input_priority()

display.set_rotation(lv.DISPLAY_ROTATION._180)

th = task_handler.TaskHandler()

Issue 2: SD Card Driver

I tried to use both SPI mode and SDMMC mode to drive the SD card, but neither worked. I also referred to [Mounting SD CARD with ELECROW 5" Display](https://github.com/elecrow/elecrow-5inch-lcd/issues/XXX), but still couldn't resolve the issue.

SPI MODE

import os
import machine
import vfs
import time

spi_bus = machine.SPI.Bus(
    host=2,  # SPI2 (HSPI)
    mosi=14,  # SD_CMD (DI) → IO14
    miso=9,  # SD_DAT0 (DO) → IO9
    sck=11,  # SD_CLK → IO11
)

try:
    sd = machine.SDCard(
        spi_bus=spi_bus,
        cs=12,  # SD_DAT3 (CS) → IO12
        freq=20000000
    )

    vfs.mount(sd, "/sd")
    print("SPI MODE")
    print(os.listdir("/"))
    print(os.listdir("/sd"))
except Exception as e:
    print(e)

SDMMC MODE

import os
import machine
import vfs
import time

try:
    sdcard = machine.SDCard(
        slot=1,
        clk=11,
        cmd=14,
        d0=9,
        d1=13,
        d2=42,
        d3=12,
        cd=-1,
        wp=-1,
        width=4,
        freq=400000
    )

    vfs.mount(sdcard, "/sd")
    print("SDMMC MODE")
    print(os.listdir("/"))
    print(os.listdir("/sd"))
except Exception as e:
    print(e)

I would really appreciate any help on these issues. Thank you!

@kdschlosser
Copy link
Collaborator

kdschlosser commented Apr 9, 2025

OK so with the SD card your host is wrong for the comment you have. You need to set that to 1.

  • SPI Host 1 = 0,
  • SPI Host 2 = 1
  • SPI Host 3 = 2

This is how it is done in the ESP32 SDK so I kept it that way.

The other thing is there is a speed limit for SPI SSD of 10mHz. You have it set to 20mHz

The touch is easy to fix. You are using the GT911 touch IC and that IC you have the ability to set the touch resolution. It doesn't come defaulted to what your display is so we need to change that...

add this code after you create the touch driver and before you do any display rotation. I also suggest having this code before the touch calibration and you are going to need to redo the calibration once this code is added.

if indev.hw_size != (320, 240):
    fw = indev.firmware_config
    fw.width = 320
    fw.height = 240
    fw.save()
    del fw

@kdschlosser
Copy link
Collaborator

Here is a link to all of the things you can adjust using that firmware config for the GT911 touch IC...

https://github.com/lvgl-micropython/lvgl_micropython/blob/main/api_drivers/common_api_drivers/indev/gt911_extension.py

Just remember to call save after you make changes to things.

@kdschlosser
Copy link
Collaborator

your SPI for the SDCard might have some pins that are flip flopped... Manufacturers are a pain with labeling inconsistencies between devices. You may want to flip flop these pins as a test.

    mosi=14,  # SD_CMD (DI) → IO14
    miso=9,  # SD_DAT0 (DO) → IO9

MOSI - Master Out Slave In
MISO = Master In Slave Out

DI = Data In
DO = Data Out
a lot of times SPI devices have their pins labeled as to what it needs to connect to in the MCU
MI = DI
MO = DO

I have seen this many times and it sure does make things confusing. The way SPI pins are named and how manufacturers tend to label things is what makes it confusing.

@kk8900
Copy link
Author

kk8900 commented Apr 20, 2025

OK so with the SD card your host is wrong for the comment you have. You need to set that to 1.

  • SPI Host 1 = 0,
  • SPI Host 2 = 1
  • SPI Host 3 = 2

This is how it is done in the ESP32 SDK so I kept it that way.

The other thing is there is a speed limit for SPI SSD of 10mHz. You have it set to 20mHz

The touch is easy to fix. You are using the GT911 touch IC and that IC you have the ability to set the touch resolution. It doesn't come defaulted to what your display is so we need to change that...

add this code after you create the touch driver and before you do any display rotation. I also suggest having this code before the touch calibration and you are going to need to redo the calibration once this code is added.

if indev.hw_size != (320, 240):
fw = indev.firmware_config
fw.width = 320
fw.height = 240
fw.save()
del fw

Thank you very much for your reply. I have been on a business trip recently and haven’t had the time to do the testing. I apologize for that.

I tried the code you provided, but the touch functionality still has significant issues. It seems that the touch is only working in a small area in the middle of the lower half of the screen, and other parts are not responsive. I’m not sure if this is a hardware issue. I’ll try flashing back to the official firmware and test it again.

The SD card has the same problem—it doesn’t get recognized by the driver. I also tested it with the official MicroPython firmware, but it still didn’t work. It might be a hardware design issue, which I can’t seem to resolve.

Thank you once again for your reply. Is there a community for lvgl-micropython where I can learn more?

@kdschlosser
Copy link
Collaborator

You are using what is called the CYD (Cheap Yellow Display) board. I believe I should have a config file set up for that display. I will check and see if I do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants