ILI9341 display not working with ESP Home

Hi all,
for more that a week I am struggling to get the ILI9341 display working with ESP32 DevKit v1 and ESP Home.

The board is connected like this:

MOSI: GPIO 23
MISO: GPIO 19
SCK: GPIO 18
CS: GPIO 15
DC: GPIO 2
RST: GPIO 4
VCC (3.3V): 3.3V pin on ESP32
GND: GND pin on ESP32
LED: 3.3V pin on ESP32

In the Arduino IDE software, I am using the basic code for testing, if the display itself works fine or if it´s faulty. Everything works well, here is the basic code.

#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>

#define TFT_DC 2
#define TFT_CS 15
#define TFT_RST 4

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

void setup() {
  Serial.begin(115200);
  tft.begin();
  tft.fillScreen(ILI9341_BLUE);
}

void loop() {
  // Doing nothing
}

This code works well and the display lights blue after uploafing the code.

I am absolutely not able to do the same in ESP Home.

esphome:
  name: esphome-web-786bac
  friendly_name: ESPHome TFT display
  min_version: 2024.11.0
  name_add_mac_suffix: false

esp32:
  board: esp32dev
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:
- platform: esphome

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

spi:
  clk_pin: GPIO18
  mosi_pin: GPIO23

display:
  - platform: ili9xxx
    model: ILI9341
    cs_pin: GPIO15
    dc_pin: GPIO2
    reset_pin: GPIO4
    rotation: 0
    invert_colors: false
    lambda: |-
      it.fill(Color(255, 0, 0));

I have tried this option, but it is not supporting lambda function.

lvgl:
  buffer_size: 25%

Tried these options separately, different data rates, also not helping:

data_rate: 20MHz

OR

color_palette: 8BIT

Tried different models, TFT, ILI, nothing working:

model: TFT 2.4

OR

model: ili9341

Wiring is OK as it works in Arduino IDE.

Still gives me errors in the log and I am desperate how to make it to work.

[22:57:49][C][logger:177]: Logger:
[22:57:49][C][logger:178]:   Max Level: DEBUG
[22:57:49][C][logger:179]:   Initial Level: DEBUG
[22:57:49][C][logger:181]:   Log Baud Rate: 115200
[22:57:49][C][logger:182]:   Hardware UART: UART0
[22:57:49][C][spi:068]: SPI bus:
[22:57:49][C][spi:069]:   CLK Pin: GPIO18
[22:57:49][C][spi:070]:   SDI Pin: 
[22:57:49][C][spi:071]:   SDO Pin: GPIO23
[22:57:49][C][spi:076]:   Using HW SPI: SPI2_HOST
[22:57:49][C][ili9xxx:091]: ili9xxx
[22:57:49][C][ili9xxx:091]:   Rotations: 0 °
[22:57:49][C][ili9xxx:091]:   Dimensions: 240px x 320px
[22:57:49][C][ili9xxx:092]:   Width Offset: 0
[22:57:49][C][ili9xxx:093]:   Height Offset: 0
[22:57:49][C][ili9xxx:099]:   Color mode: 16bit
[22:57:49][C][ili9xxx:108]:   Data rate: 40MHz
[22:57:49][C][ili9xxx:110]:   Reset Pin: GPIO4
[22:57:49][C][ili9xxx:111]:   CS Pin: GPIO15
[22:57:49][C][ili9xxx:112]:   DC Pin: GPIO2
[22:57:49][C][ili9xxx:114]:   Color order: BGR
[22:57:49][C][ili9xxx:115]:   Swap_xy: NO
[22:57:49][C][ili9xxx:116]:   Mirror_x: YES
[22:57:49][C][ili9xxx:117]:   Mirror_y: NO
[22:57:49][C][ili9xxx:118]:   Invert colors: NO
[22:57:49][C][ili9xxx:121]:   => Failed to init Memory: YES!
[22:57:49][C][ili9xxx:123]:   Update Interval: 1.0s
[22:57:49][E][component:082]:   Component display is marked FAILED
[22:57:49][C][mdns:116]: mDNS:
[22:57:49][C][mdns:117]:   Hostname: esphome-web-786bac
[22:57:49][C][esphome.ota:073]: Over-The-Air updates:
[22:57:49][C][esphome.ota:074]:   Address: esphome-web-786bac.local:3232
[22:57:49][C][esphome.ota:075]:   Version: 2
[22:57:49][C][safe_mode:018]: Safe Mode:
[22:57:49][C][safe_mode:019]:   Boot considered successful after 60 seconds
[22:57:49][C][safe_mode:021]:   Invoke after 10 boot attempts
[22:57:49][C][safe_mode:022]:   Remain in safe mode for 300 seconds
[22:57:49][C][api:140]: API Server:
[22:57:49][C][api:141]:   Address: esphome-web-786bac.local:6053
[22:57:49][C][api:145]:   Using noise encryption: NO
[22:58:43][I][safe_mode:041]: Boot seems successful; resetting boot loop counter
[22:58:43][D][esp32.preferences:114]: Saving 1 preferences to flash...
[22:58:43][D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed

Any ideas, what could be wrong?

This setup works fine for me.

esphome:
  name: mcu32-display
  friendly_name: xxxxxx

esp32:
  board: esp32dev
  framework:
    type: arduino


wifi:
  ssid: xxxxxxx
  password: xxxxxx

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Mcu32 Display Fallback Hotspot"
    password: "xxxxxxxxxxxxx"

captive_portal:

# Enable logging
logger:
  logs:
    component: ERROR

# Enable Home Assistant API
api:


ota:
  - platform: esphome
    password: "xxxxxxxxxxxx"
  
spi:
 clk_pin: 18
 mosi_pin: 23
 miso_pin: 19
  
  
display:
  - platform: ili9xxx
    model: ILI9341
    cs_pin: 14
    dc_pin: 27
    reset_pin: 33
    rotation: 270
    invert_colors: false
    color_palette: 8BIT
    color_order: bgr
    id: tft_display

Hi,
thanks a lot for your answer.
Unfortunately does not work for me.
All wiring done exactly from your code, nothing, only white screen.

Trying this idea, which I found in some topic, also does not work :neutral_face:

firebass08 James
Apr '22

For future folks need a jump on the screen pins.
SCK to the TCLK
MOSI to the TDO
MISO to the TDIN
In subsequent post in the same thread was this information;

amrut
Sep '23
Just for every one here. This is how I got solved it with the help of @pepe59

ESPHome version 2023.8.2

mosi_pin is connected to SDI(MOSI) and T_DIN
miso_pin is only connected to T_DO only.
clk_pin is connected to SCK and T_CLK
Please make sure you connect the T_IRQ to the interrupt_pin. It is required for the touch to work

Can you please give me your full wiring?
Do you have touchscreen pins also connected?
I do not need them now, I need to get the display to work in basic mode.

Yes, I also use a touch layer on another ILI display.
This is basic

spi:
 clk_pin: 18 # ILI/ SCK
 mosi_pin: 23 # ILI/ SDI(MOSI) 
 miso_pin: 19 # ILI/ SDO(MISO) 
 
display:
  - platform: ili9xxx
    model: ILI9341
    cs_pin: 14 # ILI/ CS 
    dc_pin: 27 # ILI/ DC
    reset_pin: 33 # ILI/ Reset 
    rotation: 270
    invert_colors: false
    color_palette: 8BIT
    color_order: bgr
    id: id: tft_display

    
# Define a PWM output on the ESP32
output:
  - platform: ledc
    pin: 32 # ILI/ LED
    id: gpio_32_backlight_pwm

The only difference is that you are using the esp-idf framework and I am using arduino.

1 Like

And that could be, from my point of view, an issue.
I do not understand, why when I prepare the board for first use via the https://web.esphome.io, it installs esp-idf framework.
Then I took control by ESP Home and it installs arduino.

I have problems with simple adding the new board to ESP Home, because it always freezes when I add a new board - still showing “preparing installation”, 10 minutes and it freezes.
Then I look into the code of the board, and it looks like everything was installed correctly, but I simply do not believe it.

Yet a different story, I will struggle with that.

Now I am trying to get another new ESP board with arduino and test your code…

Will give the results…

Oh man, this is crazy as f*ck :weary:

I completely reflashed the new board, starting with the https://web.esphome.io
Then I took control via ESP Home in HA.
It freezed as always, but there was some basic code loaded.
I was able to connect to the board from ESP Home via USB COM6.

The only thing I did was to change one word, as expected:

framework:
    type: esp-idf

Changed to

framework:
    type: arduino

And guess what - it is working.

How this stupid thing could took me more than a week to get it running.
I really do not understand there is such a big difference.
And why ESP Home installs as main the esp-idf framework and not arduino framework.

Well, job done, now I can play finally…thanks very much for your help.