esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

RP2040 Display issues #4478

Open pascal-parent opened 1 year ago

pascal-parent commented 1 year ago

The problem

I am trying to use a Waveshare 2.8inch Touch Display Module for Raspberry Pi Pico, 262K Colors, 320×240, SPI (ST7789). Each time I enable the display the connection to Home Assistant drops but I can still update it via OTA, often even if the ESPHome dashboard says it's offline. This prevents me from using the platform: homeassistant sensors as it is disconnected.

Which version of ESPHome has the issue?

2023.4.2

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2023.4.6

What platform are you using?

RP2040

Board

Raspberry Pi Pico W

Component causing the issue

SPI/WIFI

Example YAML snippet

#VARIABLES
substitutions:
  device_name: "esphome-kitchen-display"
  device_internal_name: "esphome_kitchen_display"
  device_friendly_name: ESPHome Kitchen Display
  device_ip_address: 192.168.0.209

# Board Configuration
esphome:
  name: ${device_name}
  friendly_name: ${device_friendly_name}

rp2040:
  board: rpipicow
  framework:
    platform_version: https://github.com/maxgerhardt/platform-raspberrypi.git

#-------------------------------------------------------------------------------
# Enable logging
#-------------------------------------------------------------------------------
logger:

#-------------------------------------------------------------------------------
# Enable Home Assistant API
#-------------------------------------------------------------------------------
api:
  reboot_timeout: 0s
  encryption:
    key: !secret api_encryption_key

ota:
  safe_mode: true
  password: !secret web_server_password

#-------------------------------------------------------------------------------
# WiFi
#-------------------------------------------------------------------------------
wifi:
  networks:
    - ssid: !secret wifi_ssid
      password: !secret wifi_password

  power_save_mode: none

  manual_ip:
    static_ip: ${device_ip_address}
    gateway: 192.168.0.x
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ${device_friendly_name}
    password: !secret web_server_password

time:
  - platform: homeassistant
    id: internal_time

#-------------------------------------------------------------------------------
# Status led
#-------------------------------------------------------------------------------
status_led:
  pin:
    number: GPIO0
    # inverted: true

#-------------------------------------------------------------------------------
# I2C / SPI
#-------------------------------------------------------------------------------
i2c:
  sda: 4
  scl: 5
  scan: False

spi:
  clk_pin: GPIO10
  mosi_pin: GPIO11
  miso_pin: GPIO12

#-------------------------------------------------------------------------------
# Templates
#-------------------------------------------------------------------------------
text_sensor:
  - platform: template
    name: Uptime Human Readable
    id: ${device_internal_name}_uptime_human
    icon: mdi:clock-start

  - platform: wifi_info
    ip_address:
      name: IP Address
      id: ${device_internal_name}_ip_address
    ssid:
      name: Connected SSID
      id: ${device_internal_name}_connected_ssid
    mac_address:
      name: Mac Wifi Address
      id: ${device_internal_name}_mac_address

sensor:
  #-------------------------------------------------------------------------------
  # Custom Sensors
  #-------------------------------------------------------------------------------
  - platform: homeassistant
    name: "Grid"
    id: grid_power
    entity_id: sensor.power_usage

  - platform: homeassistant
    name: "Solar"
    id: solar_power
    entity_id: sensor.ss_pv1_power

  - platform: homeassistant
    name: "Battery"
    id: battery_power
    entity_id: sensor.ss_battery_power

  - platform: homeassistant
    name: "Battery"
    id: inverter_power
    entity_id: sensor.ss_essential_power

  #-------------------------------------------------------------------------------
  # ESP Generic Sensors
  #-------------------------------------------------------------------------------
  # WiFi
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    id: ${device_internal_name}_wifi_signal_sensor
    update_interval: 120s

  # Uptime
  - platform: uptime
    name: "Uptime Sensor"
    id: ${device_internal_name}_uptime_sensor
    update_interval: 120s
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: ${device_internal_name}_uptime_human
            state: !lambda |-
              int seconds = round(id(${device_internal_name}_uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? to_string(days) + "d " : "") +
                (hours ? to_string(hours) + "h " : "") +
                (minutes ? to_string(minutes) + "m " : "") +
                (to_string(seconds) + "s")
              ).c_str();

#-------------------------------------------------------------------------------
# Binary Sensors
#-------------------------------------------------------------------------------
binary_sensor:
  # ESP Status
  - platform: status
    name: "Status"
    id: ${device_internal_name}_device_status

#-------------------------------------------------------------------------------
# Switch
#-------------------------------------------------------------------------------
switch:
  # Restart Command
  - platform: restart
    name: "Restart"
    id: ${device_internal_name}_device_restart

#-------------------------------------------------------------------------------
# Display
#-------------------------------------------------------------------------------
display:
  - platform: st7789v
    id: ${device_internal_name}_display
    model: Custom
    backlight_pin: GPIO13
    cs_pin: GPIO9
    dc_pin: GPIO8
    reset_pin: GPIO15
    height: 320
    width: 240
    offset_height: 0
    offset_width: 0
    rotation: 270
    update_interval: 5s
    lambda: |-
      it.print(0, 0, id(roboto_20), "Hello World!");
      //it.strftime("%H:%M", id(internal_time).now());
      //it.printf(0, 0, "Inverter: %f w", id(inverter_power).state);
      ESP_LOGI("main", "Value of my sensor: %d", id(grid_power).state);
      //it.printf(0, 1, "Solar: %f w", id(solar_power).state);
      //it.printf(0, 2, "Baterry: %f w", id(battery_power).state);
      //it.printf(0, 3, "Grid total: %f w", id(grid_power).state);

font:
  - file: "gfonts://Roboto"
    id: roboto_20
    size: 20

color:
  - id: my_red
    red: 100%
    green: 0%
    blue: 0%
  - id: my_yellow
    red: 100%
    green: 100%
    blue: 0%
  - id: my_green
    red: 0%
    green: 100%
    blue: 0%
  - id: my_blue
    red: 0%
    green: 0%
    blue: 100%
  - id: my_gray
    red: 50%
    green: 50%
    blue: 50%

Anything in the logs that might be useful for us?

INFO Reading configuration /config/esphome/esphome-kitchen-display.yaml...
INFO Detected timezone 'Africa/Johannesburg'
INFO Starting log output from 192.168.0.209 using esphome API
INFO Successfully connected to 192.168.0.209
[22:04:11][D][api.connection:961]: Home Assistant 2023.4.6 (192.168.0.11): Connected successfully
[22:04:12][W][api.connection:085]: Home Assistant 2023.4.6 (192.168.0.11): Connection reset
[22:04:12][D][api.connection:961]: Home Assistant 2023.4.6 (192.168.0.11): Connected successfully
[22:04:12][I][app:102]: ESPHome version 2023.4.2 compiled on May  1 2023, 21:58:16
[22:04:12][C][status_led:019]: Status LED:
[22:04:12][C][status_led:020]:   Pin: GPIO0
[22:04:12][D][text_sensor:064]: 'Uptime Human Readable': Sending state '4m 7s'
[22:04:12][I][main:199]: Value of my sensor: 0
[22:04:19][D][time:044]: Synchronized time: 2023-05-01 22:04:11
[22:04:19][D][time:044]: Synchronized time: 2023-05-01 22:04:11
[22:04:19][C][wifi:505]: WiFi:
[22:04:19][C][wifi:363]:   Local MAC: 28:CD:C1:06:E4:F3
[22:04:19][C][wifi:364]:   SSID: [redacted]
[22:04:19][C][wifi:365]:   IP Address: 192.168.0.209
[22:04:19][C][wifi:366]:   BSSID: [redacted]
[22:04:19][C][wifi:368]:   Hostname: 'esphome-kitchen-display'
[22:04:19][C][wifi:370]:   Signal strength: -48 dB ▂▄▆█
[22:04:19][C][wifi:374]:   Channel: 10
[22:04:19][C][wifi:375]:   Subnet: 255.255.255.0
[22:04:19][C][wifi:376]:   Gateway: 192.168.0.1
[22:04:19][C][wifi:377]:   DNS1: 0.0.0.0
[22:04:19][C][wifi:378]:   DNS2: 0.0.0.0
[22:04:19][I][main:199]: Value of my sensor: 0
[22:04:27][D][api:102]: Accepted 192.168.0.11
[22:04:27][D][api.connection:961]: Home Assistant 2023.4.6 (192.168.0.11): Connected successfully
[22:04:27][C][logger:294]: Logger:
[22:04:27][C][logger:295]:   Level: DEBUG
[22:04:27][C][logger:296]:   Log Baud Rate: 115200
[22:04:27][C][logger:297]:   Hardware UART: USB_CDC
[22:04:27][I][main:199]: Value of my sensor: 0
[22:04:36][I][ota:113]: Boot seems successful, resetting boot loop counter.
[22:04:36][D][rp2040.preferences:117]: Saving preferences to flash...
[22:04:36][D][api.connection:163]: Home Assistant 2023.4.6 (192.168.0.11) requested disconnected
[22:04:36][D][time:044]: Synchronized time: 2023-05-01 22:04:27
[22:04:36][D][api.connection:163]: Home Assistant 2023.4.6 (192.168.0.11) requested disconnected
[22:04:36][W][api.connection:075]: 192.168.0.11: Socket operation failed: HANDSHAKESTATE_READ_FAILED errno=11
[22:04:36][C][i2c.arduino:053]: I2C Bus:
[22:04:36][C][i2c.arduino:054]:   SDA Pin: GPIO4
[22:04:36][C][i2c.arduino:055]:   SCL Pin: GPIO5
[22:04:36][C][i2c.arduino:056]:   Frequency: 50000 Hz
[22:04:36][C][i2c.arduino:065]:   Recovery: failed, SDA is held low on the bus
[22:04:36][I][main:199]: Value of my sensor: 0
[22:04:42][D][api:102]: Accepted 192.168.0.11
[22:04:42][D][api:102]: Accepted 192.168.0.11
[22:04:42][C][spi:101]: SPI bus:
[22:04:42][C][spi:102]:   CLK Pin: GPIO10
[22:04:42][C][spi:103]:   MISO Pin: GPIO12
[22:04:42][C][spi:104]:   MOSI Pin: GPIO11
[22:04:42][C][spi:106]:   Using HW SPI: NO
[22:04:42][I][main:199]: Value of my sensor: 0
[22:04:50][D][api.connection:163]: Home Assistant 2023.4.6 (192.168.0.11) requested disconnected
[22:04:50][C][template.text_sensor:021]: Template Sensor 'Uptime Human Readable'
[22:04:50][C][template.text_sensor:021]:   Icon: 'mdi:clock-start'
[22:04:50][I][main:199]: Value of my sensor: 0
[22:04:58][D][api:102]: Accepted 192.168.0.11
[22:04:58][C][uptime.sensor:031]: Uptime Sensor 'Uptime Sensor'
[22:04:58][C][uptime.sensor:031]:   Device Class: 'duration'
[22:04:58][C][uptime.sensor:031]:   State Class: 'total_increasing'
[22:04:58][C][uptime.sensor:031]:   Unit of Measurement: 's'
[22:04:58][C][uptime.sensor:031]:   Accuracy Decimals: 0
[22:04:58][C][uptime.sensor:031]:   Icon: 'mdi:timer-outline'
[22:04:58][I][main:199]: Value of my sensor: 0
[22:05:06][D][api.connection:961]: Home Assistant 2023.4.6 (192.168.0.11): Connected successfully
[22:05:06][D][api.connection:961]: Home Assistant 2023.4.6 (192.168.0.11): Connected successfully
[22:05:06][C][homeassistant.time:010]: Home Assistant Time:
[22:05:06][C][homeassistant.time:011]:   Timezone: 'SAST-2'
[22:05:06][I][main:199]: Value of my sensor: 0

Additional information

Furthermore, the RP4020's logs, which are accessible even though Home Assistant reports "Disconnected" and the logs report

When adding the device the device link is also missing.

Screenshot 2023-05-01 at 22 09 13

Oddly enough, the screen attached to the RP2040 works 100% albeit with a very slow refresh rate.

Once I remove the display section, I get reconnected and I get the home assistant data as shown bellow

Screenshot 2023-05-01 at 22 19 16

logs:

_INFO Processing unexpected disconnect from ESPHome API for 192.168.0.209 WARNING Disconnected from API INFO Successfully connected to 192.168.0.209 [22:14:12][D][api:102]: Accepted 192.168.0.11 [22:14:12][W][api.connection:085]: Home Assistant 2023.4.6 (192.168.0.11): Connection reset [22:14:12][D][homeassistant.sensor:024]: 'sensor.power_usage': Got state 2962.00 [22:14:12][D][sensor:109]: 'Grid': Sending state 2962.00000 with 1 decimals of accuracy [22:14:12][D][homeassistant.sensor:024]: 'sensor.ss_pv1_power': Got state 0.00 [22:14:12][D][sensor:109]: 'Solar': Sending state 0.00000 with 1 decimals of accuracy [22:14:12][D][homeassistant.sensor:024]: 'sensor.ss_battery_power': Got state 1223.00 [22:14:12][D][sensor:109]: 'Battery': Sending state 1223.00000 with 1 decimals of accuracy [22:14:12][D][homeassistant.sensor:024]: 'sensor.ss_essential_power': Got state 1101.00 [22:14:12][D][sensor:109]: 'Battery': Sending state 1101.00000 with 1 decimals of accuracy [22:14:12][D][api.connection:961]: Home Assistant 2023.4.6 (192.168.0.11): Connected successfully [22:14:12][D][time:044]: Synchronized time: 2023-05-01 22:14:12 [22:14:13][W][api.connection:087]: Home Assistant 2023.4.6 (192.168.0.11): Connection closed [22:14:13][D][api:102]: Accepted 192.168.0.11 WARNING 192.168.0.209: Connection error occurred: [Errno 104] Connection reset by peer INFO Processing unexpected disconnect from ESPHome API for 192.168.0.209 WARNING Disconnected from API WARNING 192.168.0.209: Connection error occurred: Timeout waiting for response for <class 'api_pb2.ConnectRequest'> after 30.0s WARNING Can't connect to ESPHome API for 192.168.0.209: Timeout waiting for response for <class 'apipb2.ConnectRequest'> after 30.0s INFO Trying to reconnect to 192.168.0.209 in the background

Then I lose connection to Home Assistant even though the ESPHome Dashboard says it's online.

I hope this is enough information, if you need any more don't hesitate to ask.

I am also aware you are working of the RP2040 integration and if a Beta, thank you for all the work you are doing.

PS: I used nearly the same code on a ESP32 Vroom with no issues.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

nathanp512 commented 1 year ago

https://github.com/esphome/issues/issues/4405 seems related rpipicow display/ili9xxx 480*320 displays breaks api (HA cannot connect)