HASwitchPlate / openHASP

HomeAutomation Switchplate based on lvgl for ESP32
https://www.openhasp.com
MIT License
679 stars 174 forks source link

Scrambled display on ESP32-2432S028 #544

Open rodavrow opened 11 months ago

rodavrow commented 11 months ago

Perform all steps below and tick them with [x]

Describe the bug

I flashed the ESP32-2432S028 using the web tool with esp32-2432s028r_full_4MB_v0.7.0-rc6_2f4092b.bin - issue is as seen with the screen being misaligned, mirrored and unresponsive to touch.

I then flashed using the latest Github actions nightly to esp32-2432s028r_full_4MB_v0.7.0-rc8_f28627c.bin - issue is the same.

Console operates as expected.

The sample code that the device was originally running operated as expected, both display and touchscreen functioned normally. So the device does not appear to be faulty.

To Reproduce

Flash the ESP32-2432S028 Sunton board with any version of the firmware.

Expected behavior

The screen should display and operate normally.

Screenshots or video

20230915_105711 20230915_105654

rodavrow commented 11 months ago

OK, I may have found the issue. I tried loading ESP-Home using some example code for this board, and I believe this new revision with the USB-C Controller may have a different display controller.

It appears it used to be ILI9341 based on the code I used, but when I loaded the firmware I had exactly the same display issue. I then changed the configration in ESP-Home to ILI9342 it now works as expected.

I will attempt to see what I need to change in openHASP and test.

rodavrow commented 11 months ago

I'm a bit lost on how to implement the ILI9342 driver, can anyone assist please?

FreezyExp commented 10 months ago

just set width as height and rotate the screen see https://github.com/HASwitchPlate/openHASP/issues/550#issuecomment-1737523475

rodavrow commented 10 months ago

Thanks! I felt that the colors were wrong though. Not sure if relevant to this as referenced here:

https://forum.arduino.cc/t/i-have-problems-to-use-my-tft-screen-2-4-ili9342-help-me-please/455398

I tryed a lot of libraries for ILI9341, none works, except maybe one.

I say maybe because :

colors are inverted, black is 0xFFFF and wite 0X0000 , rgb565. texte is miroired and biggining from right side portrait screen is displayed and splited in lanscape screen or lanscape screen is diplayed and splited in portrait screen

yeyeto2788 commented 10 months ago

The colors are also inverted, BGR instead of RGB I faced the same issue yesterday trying to adapt the board and make it work.

https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display/issues/40

Grey-Lancaster commented 7 months ago

+1 needs to be a dropdown on the web install page for the ili9342 as ili9341 does not work

yeyeto2788 commented 7 months ago

Hey @Grey-Lancaster I got it to work with the following code. You still need to configure screen rotation and mirroring through WiFi AP.

Here you have the binary compile in case you're interested. esp32-2432s028r_full_4MB_v0.7.0-rc9_c200edf.bin.zip

I had to modify a configuration file in order to get it working user_setups/esp32/esp32-2832s028.ini

;***************************************************;
;       Sunton ESP32-WROOM custom dev board with    ;
;               - ILI9341 TFT SPI 4-WIRE            ;
;               - XPT2046 touch controller          ;
;***************************************************;

[esp32-2432s028r]
extends = arduino_esp32_v2
board = esp32dev
monitor_port = COM4       ; Change to the correct port
upload_port = COM4
upload_protocol = esptool
upload_flags =
    --erase-all

build_flags =
    ${arduino_esp32_v2.build_flags}
    ${esp32.no_ps_ram}

;region -- TFT_eSPI build options ------------------------
    ; -D USER_SETUP_LOADED=1
    -D LGFX_USE_V1=1
    -D ILI9342_DRIVER=1
    -D INVERT_COLORS=1
    -D TFT_ROTATION=0 ; 0=0, 1=90, 2=180 or 3=270 degree
    -D TFT_WIDTH=320
    -D TFT_HEIGHT=240
    -D TFT_RST=-1
    -D TFT_SCLK=14
    -D TFT_DC=2
    -D TFT_CS=15
    -D TFT_MOSI=13
    -D TFT_MISO=12
    -D TFT_BCKL=21
    -D SUPPORT_TRANSACTIONS
    -D SPI_FREQUENCY=55000000
    -D SPI_READ_FREQUENCY=20000000
    -D TOUCH_OFFSET_ROTATION=0  ; 1=swap xy, 2=invert x, 4=inverty

    -D ESP32_2432S028R=1
;endregion

; -- Debugging options -----------------------------
;   -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG

lib_deps =
    ${arduino_esp32_v2.lib_deps}
    ${lovyangfx.lib_deps}

[env:esp32-2432s028r_4MB]
extends = esp32-2432s028r, flash_4mb
build_flags =
    ${esp32-2432s028r.build_flags}
    -D TOUCH_DRIVER=0x2046 ; XPT2606 Resistive touch panel driver
    -D HASP_USE_LGFX_TOUCH=1
    -D TOUCH_CS=33
    -D TOUCH_SCLK=25
    -D TOUCH_MOSI=32
    -D TOUCH_MISO=39
    -D TOUCH_SDA=-1
    -D TOUCH_SCL=-1
    -D TOUCH_IRQ=36
    -D SPI_TOUCH_FREQUENCY=2500000

; -- Debugging options -----------------------------
;   -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_VERBOSE

lib_deps =
    ${esp32-2432s028r.lib_deps}
    ;${tft_espi.lib_deps}
    ${lovyangfx.lib_deps}
    ;${goodix.lib_deps}
Grey-Lancaster commented 7 months ago

No clue, colors are terrible and touch is not working. And for some reason HA is not discovering it. Added the plate to yaml, uploaded pages.jason. Info says connected to mqtt

yeyeto2788 commented 7 months ago

For the touch, you need to calibrate it. In regards to HA no clue, haven't actually connected it to HA

oklona commented 7 months ago

Hmm... I just applied the fixes from ILI9341_2 as suggested by #550.

In plain English, I found the settings (lots of writecommands) here: [https://github.com/Bodmer/TFT_eSPI/issues/1172], and applied them to the init-function in lib/GxTFT/src/GxCTRL/GxCTRL_ILI9341/GxCTRL_ILI9341.cpp. Now my display (with USB-C, which seems to be the sign of the new revision of the board) actually comes up correctly after a regular rebuild/reflash!

So, this fix should probably be added to the official code. However, I am unsure what would be the best approach. I have seen some references to this TFT chip as ILI9342 instead of 9342, so the question is whether it should be implemented as a new driver (hugely based on the ILI9342 but with the init-function writing different values), or if the init function should just be updated for ILI9341. According to the TFT_eSPI post, it seems the changes should work for all displays, but obviously that should be tested and verified.

zalves commented 6 months ago

@yeyeto2788 Thank you for the firmware! Working perfectly. When horizontal, touch is always mirrored, just had to calibrate touching the opposite corners that where request in calibration.

fvanroie commented 6 months ago

I added a new ili9342 firmware, but can't test it myself. You can get it from the latest build in the Actions tab for testing.

Please let me know the result.

zalves commented 6 months ago

I've installed the ili9342 firmware and it still get part of the display scrambled, colors inverted.

IMG_1151

zalves commented 6 months ago

The box does come with a sticker saying 7789 but I've tried the firmware with st7789 and got a messy result also. image

image

Only thing that worked visually was @yeyeto2788 build, but it doesn't get discovered by home assistant.

fvanroie commented 6 months ago

I swapped the width and height like @FreezyExp suggested, feel free to test again.

zalves commented 6 months ago

I've tested, last build and display works fine :D configure display to 90º mirrored, calibrated touch by pressing opposite to target in calibration, otherwise it's inverted

Thank you @fvanroie

smirnowegor commented 3 months ago

I've tested, last build and display works fine :D configure display to 90º mirrored, calibrated touch by pressing opposite to target in calibration, otherwise it's inverted

Thank you @fvanroie

Hi! Did you calibrate it via GUI? when i calibrate device it works fine ... until device is rebooted. Than i have to calibrate it again