I now have it working as I would expect. However, I believe I might have a defective ESP32, because it is very hard to upload a sketch. Let me explain in case it helps someone or if I can get an opinion that yes this is a bad part.
There were three things I should have given more thought to when the different code approaches weren’t working.
- I couldn’t visit the device from the ESPHome page.
- The device would blink when booting and would occasionally do so every once in a while.
- Pictures would only display when called in the else loop.
Once I bothered to hook it up to a serial monitor I realized it was failing to boot and entering into safe mode and the above three made sense:
- Limited wifi connectivity
- The blinking was the 10 boot attempts before entering safe mode and a timeout of 300 seconds before the next attemps.
- There was no connection to Home assistant so the binary or text sensor had no state so it entered the else loop.
On to the failing to boot and the serial monitor
The relevant portions are
e[0;36m[D][esp32_ble:279]: Enabling BLE...e[0m
Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
and
I was getting a
E (462) psram: PSRAM ID read error: 0xffffffff
as well. I still get that error. There is some discussion of this error on github:
E (243) psram: PSRAM ID read error: 0xffffffff E (243) cpu_start: Failed to init external RAM! (IDFGH-4457) · Issue #6288 · espressif/esp-idf (github.com)
I tried a few things from there i.e setting this
psram:
mode: quad
didn’t work. But finally I just tried disabling BLE since that was were it was crashing. That caused it to stop entering into safe mode.
esp32_ble:
enable_on_boot: false
I thought maybe I was just running out of RAM. However, it now is a chore to load new code. 9/10 times the code will fail to load. Was there something to do with safemode that made it easier to load code with flakey PSRAM?
Here is a representative sample of when it fails to load:
e[0;36m[D][esphome.ota:293]: Progress: 27.3%e[0m
e[0;36m[D][esphome.ota:293]: Progress: 29.3%e[0m
e[0;36m[D][esphome.ota:293]: Progress: 31.5%e[0m
E (54050) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (54050) task_wdt: - loopTask (CPU 1)
E (54050) task_wdt: Tasks currently running:
E (54050) task_wdt: CPU 0: IDLE
E (54050) task_wdt: CPU 1: IDLE
E (54050) task_wdt: Aborting.
abort() was called at PC 0x400fd84c on core 0
Backtrace:0x400839c1:0x3ffbe9fc |<-CORRUPTED
ELF file SHA256: 0000000000000000
Rebooting...
ets Jul 29 2019 12:21:46
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode: DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13132
load:0x40080400,len:3036
entry 0x400805e4
E (462) psram: PSRAM ID read error: 0xffffffff
e[0;32m[I][logger:156]: Log initializede[0m
entry 0x400805e4
E (462) psram: PSRAM ID read error: 0xffffffff
e[0;32m[I][logger:156]: Log initializede[0m
It is working exactly as I would expect right now, but I was going to use this device to track several doors, so I will still update the code and don’t want to have to fight loading the code to debug. Is it defective or am I missing something else? I should mention this is a ESP-wroom-32 from ideaspark with the 1.14 inch screen using the ST7789 driver.
Thanks.
PS the final code:
text_sensor:
- platform: homeassistant
id: shed_door
entity_id: binary_sensor.esphome_web_854c70_upper_shed_door
internal: true
on_value:
then:
color:
- id: my_black
red: 100%
green: 100%
blue: 100%
- id: my_red
red: 10%
green: 100%
blue: 10%
spi:
clk_pin: GPIO18
mosi_pin: GPIO23
image:
- file: "chicken.jpg"
id: chicken
resize: 200x200
type: RGB24
- file: "barn.jpg"
id: barn
resize: 200x200
type: RGB24
font:
- file: 'silkscreen.ttf'
id: font1
size: 8
- file: 'BebasNeue-Regular.ttf'
id: font2
size: 48
display:
- platform: ili9xxx
model: ST7789V
dc_pin: GPIO2
reset_pin: GPIO4
cs_pin: GPIO15
color_order: rgb
dimensions:
height: 250
width: 200
#offset_width: 40
offset_height: 40
#transform:
# swap_xy: true
# mirror_y: true
rotation: 270°
lambda: |-
it.fill(my_black);
if (id(shed_door).has_state()) {
if(id(shed_door).state == "on") {
it.image(130, 70, id(barn));
}
if(id(shed_door).state == "off") {
it.printf(130, 70, id(font1), id(my_red), "shed closed");
}
}
else {
it.printf(130, 70, id(font2), id(my_red), "ERROR");
}