Did anyone already trying to get ESPHome to work on LilyGo T-Embed

Does this device have a touch screen ?

I haven’t got a embed board but all other lilygo products I have ever bought has had pinout diagrams that is incorrect.
Usually the pins that are for their hardware is correct and only the exposed leftover pins are incorrect.
But it wouldn’t surprise me if this too is wrong.

pin_control.h is certainly different to the image.

Thanks and sorry for the late reply. I was busy in the last days

i changed it to

spi:
  clk_pin: GPIO12
  mosi_pin: GPIO11

display:
  - platform: st7789v
    model: Custom
    height: 320
    width: 170
    offset_height: 0
    offset_width: 0
    backlight_pin: GPIO15
    cs_pin: GPIO10
    dc_pin: GPIO13
    reset_pin: GPIO9

but unfortunately still no image

I have not yet tried this board in ESPHome, but I know that it is based on the t-display S3. It doesn’t use SPI to access the screen, but a faster parallel access. In Arduino you need to mod the standard eTFT-SPI lib from Bodmer to get it to work (faster than SPI).
So I presume that is the issue. Check this link T-Display S3 - How to install in Arduino IDE - YouTube from Volos Projects how to use it in the Arduino dev env.
Maybe someone got the T- display S3 working in ESPHome, that config should work for the T-embed.

Chris

I found this Unable to install to ESP32-S3 (LilyGO T-Display-S3) - #14 by landonr
It might work for the t-embed

Thank you. That’s a solution. The Display backlight worked, until I tried to customize it further. :sweat_smile:
I’m at least one step further. Backlight works, but no image visible. I hope it will soon be easier to equip the T-Embed with ESPHome

That would be completely contrary to the docs and the sample code.

Any luck with this? I just got one and see many possibilities haha.

Unfortunately not. Currently, I don’t have the motivation to try further

Following some of the links above it’s documented pretty well here (fairly basic text and rectangles)

and a more complex one here mostly C code within ESPHome lambdas

I got it to work using patched libraries from LilyGO’s GitHub repo for T-Embed and custom component from tdisplay3. I did have to add a switch for GPIO46. This GPIO is working as a power switch for board’s peripherals.

Looking at diff between upstream and LilyGO’s version of TFT_eSPI library, there aren’t many changes in LilyGO version, so it’s really weird that native ESPHome components do not work out of the box (they seem to be based on TFT_eSPI). Two differences I noticed are:

  • LiliyGO example code for T-Embed write ST7789_SLPOUT command in setup:
    tft.writecommand(0x11);
    
  • T-Embed’s version of TFT_eSPI seems to be running at a higher SPI frequency.

Anyway, when I added ESPHome automation to write 0x11 on boot, I got some output on the screen (garbage and faint “Hello world” text"). Still need to setup development environment for ESPHome to experiment with SPI frequencies, but I’m moderately optimistic about this :smiley:

On the other hand, I might just hack together some custom components for TFT_eSPI and lvlg, and use that, we’ll see how it goes :smiley:

1 Like

I’m using the ESPHome code for the ST7789V component from October (or prior) to test this display and it has the same command on Setup but it’s still not working for me:


void ST7789V::setup() {
  ESP_LOGCONFIG(TAG, "Setting up SPI ST7789V...");
  this->spi_setup();
  this->dc_pin_->setup();  // OUTPUT

  this->init_reset_();

  this->write_command_(ST7789_SLPOUT);  // Sleep out
  delay(120);                           // NOLINT

Edit - I forgot to mention earlier that the reason I’m still using the OLD component for ST7789V is because I had issues with SPI for some new boards using the latest version, and the old version had fixed that, but not in this case.

The only success related to display on screen of T-embed i have so far is to flash the tft from examples of T-Embed’s official github repository here. T-Embed/example/tft at 1f7fbe0a88027a2251e59db1256ad5f81368aff3 · Xinyuan-LilyGO/T-Embed · GitHub
However, i had to replace the TFT_eSPI library in Arduino’s libraries folder with the one in lib folder of T-Embed github repository which is here T-Embed/lib/TFT_eSPI at 1f7fbe0a88027a2251e59db1256ad5f81368aff3 · Xinyuan-LilyGO/T-Embed · GitHub
Anybody managed to flash its own code on T-Embed and make screen working?

ok i got some sketches working now. Mainly as @lukasz-tuz mentioned, you have to ensure GPIO46 (POWER_ON PIN) is high and also you have to write command
tft.writecommand(0x11);
also better to use tft.init(); instead of tft.begin(); and due to some weird reason, i have to pull out the usb cable from power and then plug-in again to completely erase the cache of display screen from previously flashed sketch.

OK, after some trial and error I finally got the native ESPHome’s st7789v component to work with LilyGO’s T-Embed. Turns out, sending the SLPOUT command is required, but should be done as early as possible:

on_boot:
  priority: 800
  then:
    - lambda: |-
        id(disp).enable();
        id(disp).transfer_byte(0x11);
        id(disp).disable();

For the display itself, custom config for the st7789v can be used:

display:
  - platform: st7789v
    model: CUSTOM
    eightbitcolor: False
    rotation: 270
    width: 170
    height: 320
    offset_width: 0
    offset_height: 35
    backlight_pin: GPIO15
    cs_pin: GPIO10
    dc_pin: GPIO13
    reset_pin: GPIO9
    id: disp
    lambda: |-
      it.strftime(10, 20, id(roboto), "%H:%M", id(home_time).now());

Note how it’s not a 320x170 display, but a rotated 170x320 :smiley:

Here’s the full config, for future reference :slight_smile:

esphome:
  name: <project-name>
  platformio_options:
    # build_flags: |-
    #   -DARDUINO_USB_CDC_ON_BOOT=1 -DLV_CONF_INCLUDE_SIMPLE
    board_build.mcu: esp32s3
    board_build.name: "LilyGO T-Embed ESP32-S3"
    board_build.upload.flash_size: "16MB"
    board_build.upload.maximum_size: 16777216
    board_build.vendor: "LilyGO"
  on_boot:
    priority: 800
    then:
      - lambda: |-
          id(disp).enable();
          id(disp).transfer_byte(0x11);
          id(disp).disable();
      - switch.turn_on: power_on

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: !secret ota_password

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

spi:
  clk_pin: GPIO12
  mosi_pin: GPIO11

switch:
  - platform: gpio
    pin:
      number: GPIO46
      mode:
        output: True
    name: "Power On"
    id: power_on
  - platform: gpio
    pin:
      number: GPIO15
      mode:
        output: True
    name: "Display Backlight"
    id: backlight

time:
  - platform: homeassistant
    id: home_time


font:
  - file: "gfonts://Roboto"
    id: roboto
    size: 96

display:
  - platform: st7789v
    model: CUSTOM
    eightbitcolor: False
    rotation: 270
    width: 170
    height: 320
    offset_width: 0
    offset_height: 35
    backlight_pin: GPIO15
    cs_pin: GPIO10
    dc_pin: GPIO13
    reset_pin: GPIO9
    id: disp
    lambda: |-
      it.strftime(10, 20, id(roboto), "%H:%M", id(home_time).now());

sensor:
  - platform: rotary_encoder
    internal: True
    name: "Rotary Encoder"
    pin_a: GPIO02
    pin_b: GPIO01

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO00
      inverted: True
    name: "Rotary Button"
    internal: True
7 Likes

Thanks for your efforts on this! In addition to the config above, it sounds like I need to use the libraries from here. Any other patches or tweaks? Ultimately I’d like to get this working with the esphome-remote project.

The code above looks complete without any additional libraries.

Thanks for the code @lukasz-tuz, it’s working like a charm (the display).
I got almost everything working now, except for the LEDs because of the GPIO PINs used on the ESP32-S3 are not accepted by FastLED 3.3.2 code. Looks like version 3.5.0 has corrected the PINs mapping but I’m having a hard time using/changing to the newest version on ESPHome :frowning:

Ah, yes, the FastLED issue. When trying to enable the st7789 I learned about the external_components feature of ESPHome. That did not really help with the display, but creates an easy way to fix the LEDs.

  1. In your project directory, create esphome/components/fastled_base and esphome/components/fastled_spi directories.
  2. Copy ESPHome core component code (all files), e.g. from here (fastled_base), and here (fastled_spi)
  3. In your local version of fastled_base open __init__.py and simply bump the FastLED code:
    await light.register_light(var, config)
    cg.add_library("fastled/FastLED", "3.5.0")
    return var
  1. In your YAML file configure directory with external components:
external_components:
  - source:
      type: local
      path: esphome/components
  1. Configure LEDs as usual:
light:
  - platform: fastled_spi
    chipset: APA102
    data_pin: GPIO42
    clock_pin: GPIO45
    rgb_order: BGR
    num_leds: 7
    name: "T-Embed LED Ring"
    effects:
      - addressable_rainbow:
      - addressable_scan:

When building, ESPHome will use local fastled_spi definition, and will download 3.5.0 version of FastLED. For T-Embed, with ESP32S3, this is completely fine; seems that ESPHome keeps the version downgraded due to some issues coming up on ESP8266.

BTW, T-Embed makes for a great smart home remote :smiley: Some time ago I tried building my own version of such device, with OLED display and NeoPixel LED ring. It actually worked for a while, but there were stability issues on account of my poor soldering skills.

However, I was able to move ESPHome YAML from that device to T-Embed with very little changes (mostly related to different display controller), and now it works like a charm :smiley: Now I’m trying to get esphome-lvgl working, hoping to make a component that implements ESPHome’s Display Menu integration using fancy lvgl widgets.

EDIT: I just clicked the esphome-remote link. Oh well, looks like the home remote thing has already been done, and much better than my attempts at that :joy: Thanks for the link @lmatter!

3 Likes