Do you have an m5stick-c working with current esphome?

I’ve had only partial success working with esphome on my m5stick-c. (I am aware of all the stuff in this thread: Support for AXP192 power management chip?).

I’m using the latest released esphome (1.14.5). Before getting started with my own stuff, I tried using the YAML files from both the water leak sensor project and the generic YAML file from the github repo with the custom component definitions. In both cases, esphome produces an “expects a dictionary” error without pointing to anything specific. That happens with both the dashboard GUI editor and CLI. Since other people have presumably used those files in the past (I mean, it’s not a hoax, is it? :slight_smile:), I wonder if something about the current esphome released version breaks things. Or maybe others have used the esphome beta or dev branches? Beats me (so far). I’ve done a lot of fiddling, but I can only get esphome to accept it by getting rid of all of the sensor: block.

My second problem is that I cannot get anything at all to display on the built-in display. I’ve done some troubleshooting, and I can see that some kind of data is being sent to the display API calls. Since my m5stick-c is recently bought, it has me wondering if maybe some slight hardware change inside it has gummed up the works.

So, anybody have one of these working with the current release of esphome? Any suggestions for things to try?

I should mention that I can tell from the logs and LED that button presses are working as expected, so it’s not a case of the overall device not running properly under esphome.

Some progress, but still a puzzler.

I uploaded the sample config to a second m5stick-c, and the stripped down graphics immediately displayed. Yay. However, when I long-pressed the power button and shut the device off, then pressed again to turn it on, the display stayed blank. Logging still shows activity for button presses, so I know the device came back on. Uploading the code again did not help. The screen stays blank. esphome logging reports:

[W][ota:036]: Last Boot was an unhandled reset, will proceed to safe mode in 8 restarts

I discovered that if I used the Arduino IDE to upload any of the m5stick-c samples that use the display, they all work fine. Furthermore, after doing that, I can upload with esphome again and the display works.

From this I hypothesize that it’s some kind of glitch somewhere in display initialization code in the esphome sample from the https://github.com/airy10/esphome-m5stickC repo. My tinkering continues.

Three posts and not a line of code, and one line of log.

The YAML file I am using is from https://github.com/airy10/esphome-m5stickC/blob/d1edf14b5e0c336b24ac1dc6af1d3355f022605a/sample-config/m5stickc.yaml, with the following changes:

  • different font file
  • removed the sensor: block because of the validation error I mentioned
  • simplified display output due to the removed sensor: block

The code for the custom components is an exact copy of the items in this directory: https://github.com/airy10/esphome-m5stickC/tree/master/components/st7735 (I am not using the axp192 custom component because of the validation error).

substitutions:
  devicename: m5stick
  upper_devicename: M5StickC

esphome:
  name: $devicename
  platform: ESP32
  board: m5stick-c
  platformio_options:
    upload_speed: 1500000

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
  ap:
    ssid: $devicename Fallback Hotspot
    password: !secret wifi_password

captive_portal:

logger:

api:

ota:

web_server:

binary_sensor:

  - platform: gpio
    pin:
      number: GPIO37
      inverted: true
    name: ${upper_devicename} Button A
    on_press:
      then:
        - light.turn_on: led1
    on_release:
      then:
        - light.turn_off: led1
        
  - platform: gpio
    pin:
      number: GPIO39
      inverted: true
    name: ${upper_devicename} Button B
    on_press:
      then:
        - light.turn_on: led1
    on_release:
      then:
        - light.turn_off: led1


# internal LED
light:
  - platform: monochromatic
    output:  builtin_led
    name: ${upper_devicename} Led
    id: led1

output:
  - platform: ledc
    pin: 10
    inverted: true
    id: builtin_led


# internal IR Transmitter
remote_transmitter:
  - pin:
      number: GPIO9
    carrier_duty_percent: 50%
    id: internal


spi:
  clk_pin: GPIO13
  mosi_pin: GPIO15

i2c:
   - id: bus_a
     sda: GPIO21
     scl: GPIO22
     scan: True

font:
  - file: '../font/misc/DroidSansMono.ttf'
    id: font1
    size: 8

  - file: '../font/misc/DroidSansMono.ttf'
    id: font2
    size: 36

  - file: '../font/misc/DroidSansMono.ttf'
    id: font3
    size: 14

# builtin 80x160 TFT
display:
  - platform: st7735
    cs_pin: GPIO5
    dc_pin: GPIO23
    reset_pin: GPIO18
    rotation: 270
    update_interval: 2s
    lambda: |-
      it.print(80, 0, id(font1), ST77XX_WHITE, TextAlign::TOP_CENTER, "M5Stick Test");
      //} else {
        it.print(80, 40, id(font2), ST77XX_RED, TextAlign::CENTER, "No Wifi");
      //}
      // Print time in HH:MM format
      it.strftime(80, 60, id(font3), ST77XX_BLUE, TextAlign::TOP_CENTER, "%H:%M", id(sntp_time).now());

time:
  - platform: homeassistant
    id: homeassistant_time
  - platform: sntp
    id: sntp_time

NVM.

It was the removing of the axp192 references that seems to have been behind the screen not waking up properly. The reason I removed that (and, in fact, all of the sensor: block) was because esphome was complaining about a YAML problem that I couldn’t isolate except by doing that.

Today, I started over with a fresh git clone of the repo (https://github.com/airy10/esphome-m5stickC/tree/master/components/st7735), using an exact copy of the sample YAML. After I changed the three lines to use a font I already had locally, it worked without further problems. I’ll probably never figure out what I did subtly wrong the first time around.

Sorry for any inconvenience if anyone was thinking about what the problem might have been!

Yeah S**t happens. Your final yaml file may help someone :slight_smile:

I’m getting “Platform not found: ‘display.st7735’.” and " Platform not found: ‘sensor.axp192’." when using the sample.yaml

Can you help me?

What version of esphome are you using?

ESPhome rev 1.15.3

The st7735 was introduced in 1.16 https://esphome.io/changelog/v1.16.0.html

I just saw that, I’m updating to 1.16.2, hopefully my errors disappear. I’ll let you know. Thanks.

Error log after updating to 1.16.2

Validate: m5stickc2.yaml
INFO Reading configuration /config/esphome/m5stickc2.yaml…
ERROR Unable to load custom component axp192.sensor:
Traceback (most recent call last):
File “/opt/esphome/esphome/config.py”, line 134, in _lookup_module
module = importlib.import_module(f’custom_components.{domain}’)
File “/usr/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 941, in _find_and_load_unlocked
File “”, line 219, in _call_with_frames_removed
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 674, in exec_module
File “”, line 781, in get_code
File “”, line 741, in source_to_code
File “”, line 219, in _call_with_frames_removed
File “/config/esphome/custom_components/axp192/init.py”, line 1

^
SyntaxError: invalid syntax
ERROR Unable to load custom component st7735.display:
Traceback (most recent call last):
File “/opt/esphome/esphome/config.py”, line 134, in _lookup_module
module = importlib.import_module(f’custom_components.{domain}’)
File “/usr/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 674, in exec_module
File “”, line 781, in get_code
File “”, line 741, in source_to_code
File “”, line 219, in _call_with_frames_removed
File “/config/esphome/custom_components/st7735/display.py”, line 7

^
SyntaxError: invalid syntax
WARNING ESP32: Pin 10 (9-10) might already be used by the flash interface in QUAD IO flash mode.
WARNING ESP32: Pin 10 (9-10) might already be used by the flash interface in QUAD IO flash mode.
WARNING ESP32: Pin 9 (9-10) might already be used by the flash interface in QUAD IO flash mode.
INFO Detected timezone ‘EST’ with UTC offset -5 and daylight savings time from 14 March 02:00:00 to 07 November 02:00:00
INFO Detected timezone ‘EST’ with UTC offset -5 and daylight savings time from 14 March 02:00:00 to 07 November 02:00:00
Failed config

sensor.axp192: [source /config/esphome/m5stickc2.yaml:64]

Platform not found: ‘sensor.axp192’.
platform: axp192
address: 52
i2c_id: bus_a
update_interval: 30s
battery_level:
name: M5Stick Battery Level
id: m5stick_batterylevel
display.st7735: [source /config/esphome/m5stickc2.yaml:125]

Platform not found: ‘display.st7735’.
platform: st7735
cs_pin: GPIO5
dc_pin: GPIO23
reset_pin: GPIO18
rotation: 270
lambda: |-
it.print(80, 0, id(font1), ST77XX_WHITE, TextAlign::TOP_CENTER, “M5Stick Test”);
if (id(wifi_dbm).has_state()) {
char str[128];
sprintf(str, “%.0f dBm”, id(wifi_dbm).state);
it.print(80, 40, id(font2), ST77XX_RED, TextAlign::CENTER, str);
//it.print(80, 40, id(font2), ST77XX_RED, TextAlign::CENTER, “%.0f dBm”, id(wifi_dbm).state);
} else {
it.print(80, 40, id(font2), ST77XX_RED, TextAlign::CENTER, “No Wifi”);
}
// Print time in HH:MM format
it.strftime(80, 60, id(font3), ST77XX_BLUE, TextAlign::TOP_CENTER, “%H:%M”, id(sntp_time).now());

My directory tree structure:ScreenHunter 126

I saw your question and the response here: https://github.com/airy10/esphome-m5stickC/issues/4#issuecomment-782873723

You need to have your YAML file one level above the custom_component directory. That’s probably why it couldn’t find the axp192 component. I’m not having any problems with axp192 with the custom_component files that same github repo.

It looks like there are significant differences between the st7735 component from airy10’s github repo and the official support for st7735 that’s now included in esphome. That official support is not very well documented, so I’m fooling around with trial and error and poking around in the code to try to figure out what’s needed.

I’ve got it working in black-and-white, though with the colors reversed (that is, the whole screen is white and drawing with COLOR_WHITE shows up as black on the screen). I assume that’s just some internal setting or init or something that needs a tweak. In other words, the display in M5Stick-C might not yet be directly supported.

Still fiddling. Here is what I have so far:

display:
  - platform: st7735
    model: INITR_MINI160X80
    rowstart: 0
    colstart: 0
    devicewidth: 0
    deviceheight: 0
    cs_pin: GPIO5
    dc_pin: GPIO23
    reset_pin: GPIO18
    rotation: 90

I also modified the lambda in the display configuration to only use COLOR_BLACK and COLOR_WHITE since the definitions of the colors from the custom component are no longer available.

I’m still confused as to the directory structure needed for axp192. My m5stickc3.yaml file is in the esphome directory along with all my other *.yaml files. I’ve tried compiling with the axp192 directory inside the custom_components and got an error. I move the axp192 directory up one level as you suggested and get the same error.

Here is my current structure:

Can you post the changes you made in your “lamda” ? I have mine commented out to get it to compile for now. Thanks.

I wasn’t suggesting you move your axp192. It should be directly under custom_componts. I was saying to move your YAML file up, which you have now done.

image

You just have to change all of the colors (ST77XX_WHITE, ST77XX_RED, ST77XX_BLUE) to COLOR_WHITE. That will show up as black on a white screen since it’s inverted on this device. If by some miracle you are seeing things on a black screen, then use COLOR_BLACK instead of COLOR_WHITE. I know that’s confusing, but it’s temporary until the display is working properly.

1 Like

That fixed my errors in the “lamda” section. The only existing error now is with the missing sensor.axp192