Need help with m5stack

Edited to add: Somehow I was missing the cs_pin: 14 line, and that is what it needed. Now I get a picture of a Shuttle on the screen. Now to keep playing.


Hi, all.

I just got an M5stack core (gen1, the black one with silver buttons), and I am trying to use it with Home Assistant and ESPHome.

I have been able to adopt it, and I can push code to it, and the buttons are recognized, but I am not able to get anything to display on the LCD screen no matter what I do.

Below is my code. As you can see by the code, I took some inspiration from this post about using the M5stack with ESPHome.

shuttle is just an image that I uploaded, 169x240 pixels, to try that, since I wasn’t able to get text to display. I tried this after failing with the blog post above, and after failing with the “Hello World” (see below).

Looking at the logs, I do see that the m5stack is getting the temperature from Home Assistant. One first idea I have is to use this to display various sensor values from HA, but at the moment I am stuck getting anything to show on the LCD.

esphome:
  name: esphome-web-6a0ed4
  friendly_name: m5stack

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxx="

ota:


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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Web-6A0Ed4"
    password: "xxx"

captive_portal:
    
spi:
  clk_pin: 18
  mosi_pin: 23
  miso_pin: 19

color:
  - id: my_red
    red: 100%
    green: 3%
    blue: 5%

font:
  - file: "Roboto-Medium.ttf"
    id: font_roboto_medium22
    size: 22
    glyphs: '!"%()+,-_.:°0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz/³µ'

image:
  - file: "images/shuttle.jpg"
    id: shuttle
    type: RGB24

display:
  - platform: ili9xxx
    model: ili9341
    dc_pin: 27
    reset_pin: 33
    lambda: |-
      it.image(0, 0, id(shuttle));

sensor:
  - platform: homeassistant
    id: rv_temp
    entity_id: sensor.esphome_web_7f8bdc_mancave_temperature
  
binary_sensor:
  - platform: gpio
    id: M5_BtnB
    pin:
      number: 38
      inverted: true
    on_click:
      then:
        - switch.toggle: backlight

# GPIO pin of the display backlight
switch:
  - platform: gpio
    pin: 32
    name: "Backlight"
    id: backlight
    restore_mode: ALWAYS_ON

In addition to the display block you see above, I also tried this:

display:
  - platform: ili9xxx
    model: ili9341
    dc_pin: 27
    reset_pin: 33
    lambda: |-
      it.image(0, 0, id(shuttle));
      it.fill(Color::BLACK);
      it.print(0, 0, id(font_roboto_medium22), id(my_red), TextAlign::TOP_LEFT, "Hello World!");

I also tried this, from the blog post linked above:

display:
  - platform: ili9xxx
    id: m5stack_display
    model: M5Stack
    cs_pin: 14
    dc_pin: 27
    reset_pin: 33
    rotation: 0
    lambda: |-
      Color RED(1,0,0);
      Color BLUE(0,0,1);
      Color WHITE(1,1,1);
      it.rectangle(0,  0, it.get_width(), it.get_height(), BLUE);
      it.rectangle(0, 22, it.get_width(), it.get_height(), BLUE);
      it.print(it.get_width() / 2, 11, id(font_roboto_medium22), RED, TextAlign::CENTER, "Test");

So far, nothing I have done has produced any image or text on the LCD screen. The only thing I see is the LCD backlight toggling by the push of that button.

Anybody see what I’m doing wrong here? Also, can anyone confirm that I am using the correct esp32 board?

Well, I guess all I needed was another half hour on Google… finally got the display sorted: I can display text, and color and text direction are now correct.

display:
  - platform: ili9xxx
    model: M5STACK
    cs_pin: 14
    dc_pin: 27
    reset_pin: 33
    rotation: 0
    lambda: |-
      Color RED(1,0,0);
      Color BLUE(0,0,1);
      Color WHITE(1,1,1);
      it.rectangle(0,  0, it.get_width(), it.get_height(), BLUE);
      it.rectangle(0, 22, it.get_width(), it.get_height(), BLUE);
      it.print(it.get_width() / 2, it.get_height() / 2, id(font_roboto_medium44), id(my_red), TextAlign::CENTER, "Test");