esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

invert_colors not working on ILI9488 #6146

Closed gvdhoven closed 2 weeks ago

gvdhoven commented 1 month ago

The problem

I have connected an ILI9488 display which is white when turned on (i was expecting it to be black just like an OLED screen). The image i am displaying is an PNG file with an alpha channel and is showing up with inverted colors. I have tried the invert_colors option but that does not seem to do anything.

This is the image i am trying to display: logo

This is how it shows up: IMG20240812201906

I have double checked all connections and the display is brand new - bought here. Interesting point to note is that that specific website mentions there is a bug with ESP32 for this display, and that the following line should be commented out; if defined(ESP8266) || defined (ARDUINO_ARCH_ARC32) || defined(ESP32) in the file ILI9488.cpp but i don't know if that information helps.

Which version of ESPHome has the issue?

2024.7.3

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

n/a

What platform are you using?

ESP32

Board

S2-mini

Component causing the issue

display

Example YAML snippet

#--------------------------------------------------------------------------------
# Substitutions used further down in the code
#--------------------------------------------------------------------------------
substitutions:
  fwVersion: '1.0'

  # Display pins
  gpioDisplayTouchCs: GPIO33
  gpioDisplayCs: GPIO10
  gpioDisplayDc: GPIO34
  gpioSpiMosi: GPIO35
  gpioSpiClk: GPIO36
  gpioSpiMiso: GPIO37
  gpioDisplayRes: GPIO38
  gpioDisplayBlk: GPIO39
  gpioDisplayTouchInterupt: GPIO40

#--------------------------------------------------------------------------------
# Global variables used further down in the code
#--------------------------------------------------------------------------------
globals:
  - id: recent_touch
    type: bool
    restore_value: no
    initial_value: "true"

# Setup SPI bus
spi:
  miso_pin: ${gpioSpiMiso}
  mosi_pin: ${gpioSpiMosi}
  clk_pin: ${gpioSpiClk}

# Setup display
image:
  - file: "assets/poolboy/logo.png"
    id: poolboy_logo
    type: RGBA

display:
- platform: ili9xxx
  id: my_display
  model: ILI9488
  cs_pin: ${gpioDisplayCs}
  dc_pin: ${gpioDisplayDc}
  reset_pin: ${gpioDisplayRes}
  dimensions: 480x320
  transform:
    mirror_x: true
    swap_xy: true
  lambda: |-
    it.image(0, 0, id(poolboy_logo));

# Setup touchscreen. On touch of the display turn the display on.
touchscreen:
- platform: xpt2046
  display: my_display
  update_interval: 50ms
  cs_pin: ${gpioDisplayTouchCs}
  interrupt_pin: ${gpioDisplayTouchInterupt}
  threshold: 400
  calibration:
    x_min: 178
    x_max: 3748
    y_min: 275
    y_max: 3924
  transform:
    mirror_x: true
    swap_xy: true
  on_touch:
      then:
        - light.turn_on: backlight
        - lambda: |-
            id(recent_touch) = true;

# Output pins
output:
  # Display backlight
  - platform: ledc
    pin: ${gpioDisplayBlk}
    id: backlight_pwm

# Light entities
light:
  # A monochromatic, dimmable light for the backlight
  - platform: monochromatic
    output: backlight_pwm
    name: "Display Backlight"
    id: backlight
    restore_mode: RESTORE_DEFAULT_ON

Anything in the logs that might be useful for us?

INFO ESPHome 2024.7.3
INFO Reading configuration /config/esphome-poolboy-dev.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing esphome-poolboy-dev (board: lolin_s2_mini; framework: arduino; platform: platformio/espressif32@5.4.0)
--------------------------------------------------------------------------------
HARDWARE: ESP32S2 240MHz, 320KB RAM, 4MB Flash
 - toolchain-riscv32-esp @ 8.4.0+2021r2-patch5 
 - toolchain-xtensa-esp32s2 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- WiFi @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- Update @ 2.0.0
|-- noise-c @ 0.1.4
|-- SPI @ 2.0.0
Compiling .pioenvs/esphome-poolboy-dev/src/main.cpp.o
Linking .pioenvs/esphome-poolboy-dev/firmware.elf
RAM:   [=         ]  13.4% (used 43776 bytes from 327680 bytes)
Flash: [=====     ]  51.0% (used 935994 bytes from 1835008 bytes)
Building .pioenvs/esphome-poolboy-dev/firmware.bin
Creating esp32s2 image...
Successfully created esp32s2 image.
esp32_create_combined_bin([".pioenvs/esphome-poolboy-dev/firmware.bin"], [".pioenvs/esphome-poolboy-dev/firmware.elf"])
Wrote 0xf49c0 bytes to file /config/.esphome/build/esphome-poolboy-dev/.pioenvs/esphome-poolboy-dev/firmware.factory.bin, ready to flash to offset 0x0
esp32_copy_ota_bin([".pioenvs/esphome-poolboy-dev/firmware.bin"], [".pioenvs/esphome-poolboy-dev/firmware.elf"])
========================= [SUCCESS] Took 7.76 seconds =========================
INFO Successfully compiled program.
INFO Connecting to 192.168.1.34
INFO Uploading /config/.esphome/build/esphome-poolboy-dev/.pioenvs/esphome-poolboy-dev/firmware.bin (936384 bytes)
Uploading: [============================================================] 100% Done...

INFO Upload took 12.28 seconds, waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 192.168.1.34 using esphome API
INFO Successfully connected to esphome-poolboy-dev @ 192.168.1.34 in 15.376s
INFO Successful handshake with esphome-poolboy-dev @ 192.168.1.34 in 0.076s
[20:32:04][I][app:100]: ESPHome version 2024.7.3 compiled on Aug 12 2024, 20:31:29

Additional information

No response

gvdhoven commented 1 month ago

p.s. i also tried the alternative model ILI9488_A with no luck.

clydebarrow commented 4 weeks ago

I don't see invert_colors in your config. What did you try? What do the logs say about the display config?

gvdhoven commented 4 weeks ago

I don't see invert_colors in your config. What did you try? What do the logs say about the display config? The logs say the config was valid (otherwise it would not compile off course)

I found out that "invert_colors" should be set to FALSE (!) and then it works as expected.

However, since this is a boolean value, my assumption was that it (already) defaults to false, so I (previously) only tried "invert_colors: true" which did not work as expected. So basically you have to explicitly mention that it defaults to false, otherwise it inverts colors by default (and who would want that?)

I did some digging in the source code and found out that:

So the fix would be to change: cv.Optional(CONF_INVERT_COLORS): cv.boolean,

To: cv.Optional(CONF_INVERT_COLORS, default=False): cv.boolean,

In the file: esphome/components/ili9xxx/display.py

I will raise a pull request.