Wrong colors issue

Hi,
I just started using lvgl yesterday and so far everything went well, except for this.

Im using ESP32, GC9A01, ESP-idf, lvgl and drivers as components.

After configuring things up, I get weird colors. Please see pictures.

Expectation:
lv_ex_linemeter_1
Reality:

I have set the correct display driver on configuration, however not sure why this is happening.

Hey
Looks like you are using a SPI Display.
SPI is using 8 byte words. Your color Data is most time 16 bytes. But in SPI you transmit the bytes in the wrong order.
you must configure:
swap_color in your config file.

1 Like

Thanks, that was it : )

That solved part of the problem tho, colors are still weird, but less weird now:

Expectation:
lv_ex_gauge_1
Reality:

I have color depth set to 16, color swap turned on, vspi, half duplex, DIO mode.

Can you Upload some of your code?
Are you using some dark theme?
Which lvgl version?

1 Like

Can you create a LVGL Screen,
Which switches between red, green, blue, black and white. So you might see if the problem is still your communication to the display or some misconfig in lvgl.

Colors are switched but to the wrong values, I can get animations working fine.

I have light theme selected, but it doesn’t matter if I switch between dark or light, colors doesn’t change.

Im using lgvl 7.

Here is the debug output of lgvl helper:

entry 0x400806f4
I (31) boot: ESP-IDF v4.2.1-dirty 2nd stage bootloader
I (31) boot: compile time 15:25:46
I (31) boot: chip revision: 1
I (34) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (41) boot.esp32: SPI Speed      : 40MHz
I (46) boot.esp32: SPI Mode       : DIO
I (50) boot.esp32: SPI Flash Size : 16MB
I (55) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (64) boot: ## Label            Usage          Type ST Offset   Length
I (71) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (79) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (86) boot:  2 factory          factory app      00 00 00010000 00100000
I (94) boot: End of partition table
I (98) boot_comm: chip revision: 1, min. application chip revision: 0
I (105) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x0d010 ( 53264) map
I (134) esp_image: segment 1: paddr=0x0001d038 vaddr=0x3ffb0000 size=0x021b8 (  8632) load
I (138) esp_image: segment 2: paddr=0x0001f1f8 vaddr=0x40080000 size=0x00404 (  1028) load
0x40080000: _WindowOverflow4 at /Users//esp/esp-idf/components/freertos/xtensa/xtensa_vectors.S:1730

I (141) esp_image: segment 3: paddr=0x0001f604 vaddr=0x40080404 size=0x00a14 (  2580) load
I (151) esp_image: segment 4: paddr=0x00020020 vaddr=0x400d0020 size=0x30ab8 (199352) map
0x400d0020: _stext at ??:?

I (235) esp_image: segment 5: paddr=0x00050ae0 vaddr=0x40080e18 size=0x0ac00 ( 44032) load
I (261) boot: Loaded app from partition at offset 0x10000
I (261) boot: Disabling RNG early entropy source...
I (261) cpu_start: Pro cpu up.
I (265) cpu_start: Application information:
I (270) cpu_start: Project name:     blink
I (274) cpu_start: App version:      1
I (279) cpu_start: Compile time:     May 11 2021 14:37:11
I (285) cpu_start: ELF file SHA256:  fd79f73456c25b55...
I (291) cpu_start: ESP-IDF:          v4.2.1-dirty
I (296) cpu_start: Starting app cpu, entry point is 0x40081814
0x40081814: call_start_cpu1 at /Users//esp/esp-idf/components/esp32/cpu_start.c:287

I (0) cpu_start: App cpu up.
I (307) heap_init: Initializing. RAM available for dynamic allocation:
I (314) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (320) heap_init: At 3FFBAFB0 len 00025050 (148 KiB): DRAM
I (326) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (332) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (339) heap_init: At 4008BA18 len 000145E8 (81 KiB): IRAM
I (345) cpu_start: Pro cpu start user code
I (363) spi_flash: detected chip: gd
I (364) spi_flash: flash io: dio
I (364) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Configuring power ledI (372) gpio: GPIO[14]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (412) lvgl_helpers: Display hor size: 240, ver size: 240
I (412) lvgl_helpers: Display buffer size: 9600
I (412) lvgl_helpers: Initializing SPI master for display
I (422) lvgl_helpers: Configuring SPI host VSPI_HOST (2)
I (432) lvgl_helpers: MISO pin: -1, MOSI pin: 23, SCLK pin: 18, IO2/WP pin: -1, IO3/HD pin: -1
I (432) lvgl_helpers: Max transfer size: 19200 (bytes)
I (442) lvgl_helpers: Initializing SPI bus...
I (452) disp_spi: Adding SPI device
I (452) disp_spi: Clock speed: 40000000Hz, mode: 0, CS pin: 22
I (662) GC9A01: Initialization.
I (862) GC9A01: Enabling backlight.
I (862) GC9A01: Display orientation: PORTRAIT
I (862) GC9A01: 0x36 command value: 0x08

Code is taken straight from the gauge 1 example, unmodified.

Could it be, that this display is taking colors the other way round?
So: 0xffff is black and 0x0000 is white?
Or are you maybe sending the values inverted? So not byte swaped (which is done by color_swap) but bitwise inverted?

1 Like

Thats what Im suspecting, swapping the 2 bytes didn’t fully solve the problem because I think the whole values needs to be inverted. I can’t seem to find an option to invert colors.

I dont think there is an Option, at least non I know of.
You can invert the data in your display flush function. Or invert the data in you display library. You might need another buffer for this.
Or you invert the whole vspi :slight_smile: but then you might have to invert all commands first.

From the data sheet page 108 https://www.buydisplay.com/download/ic/GC9A01A.pdf, it seems that there is an inversion command available, I wonder it that could possibly solve the issue.

Thah would be the best solution! Looks like you just have to send the command 0x21 after init. You might want to check if maybe the library you are using is already doing this. :wink: if it does this is the reason for your inverted colors and you should send 0x20 instead.

1 Like

Indeed, that solved the problem. GC9A01.h already has #define GC9A01_INVERT_COLORS CONFIG_LV_INVERT_COLORS but CONFIG_LV_INVERT_COLORS wasn’t defined.

Defining it sets

   GC9A01_send_cmd(0x21);
#else
   GC9A01_send_cmd(0x20);
#endif
1 Like