Boot problems with NodeMCU and I2C display

Dear community,

I have a NodeMCU V2 ESP8266 12F with a OLED Display I2C SSD1306 Chip 128 x 64 Pixel.

If I remove the code for the display, the ESP loads and boots within 2 minutes and connects to HomeAssistant. Everything works and I can control the LEDs. But if I add the code for the display and the fonts, the ESP boots only spontaneously and needs at least 10-15 minutes for it. What am I doing wrong? I have also changed the notation of the GPIOs and used the internal D-names, but that doesn’t help either. Some times when I’m lucky and the ESP boots, it’s not connected to HA and I can’t upload new software over the air.

I found this kind of thread but I don’t know what to do - seems to be the same issue?: ESP8266 (NodeMCU v3) Wifi problem with I2C SSD1306 (SH1106 128x64)

Thanks for your help. Anna

Show code
esphome:
  name: esp-door

esp8266:
  board: nodemcuv2

sensor:
  - platform: dht
    pin: D6
    model: DHT22
    update_interval: 5min
    temperature:
      name: "Temperature"
      id: inside_temperature
      accuracy_decimals: 1
    humidity:
      name: "Humidity"
      id: inside_humidity
      accuracy_decimals: 1
      
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 5min


light:
  - platform: binary
    name: "Light Red"
    output: output_component1

  - platform: binary
    name: "Light Green"
    output: output_component2


output:
  - platform: gpio
    id: output_component1
    pin: D7

  - platform: gpio
    id: output_component2
    pin: D8


button:
  - platform: restart
    name: "Restart"
    
  - platform: safe_mode
    name: "Restart in Safe Mode"  


switch:
  - platform: template
    name: "ESPDisplay Demo"
    id: template_demo
    turn_on_action:
      - display.page.show: pageOnline
      - switch.template.publish:
          id: template_demo
          state: ON
    turn_off_action:
      - display.page.show: pageOFF
      - switch.template.publish:
          id: template_demo
          state: OFF

# Enable i2c and spi
i2c:
  sda: D0
  scl: D1

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    id: my_display
    pages:
    
    - id: pageOFF
      lambda: |-
        it.fill(COLOR_OFF);

    - id: pageOnline
      lambda: |-
        it.print(64, 0, id(font_19), TextAlign::TOP_CENTER, "Online");

font:
  - file: 'arial.ttf'
    id: font_19
    size: 19
    glyphs: ['&', '@', '!', ',', '.', '?', '"', '%', '(', ')', '+', '-', '_', ':', '°', '0',
       '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
       'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
       'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
       'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
       'u', 'v', 'w', 'x', 'y', 'z','å', 'Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', '/']


# Enable logging
logger:

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

ota:
  password: "xxx"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-doorFallback Hotspot"
    password: "xxx"

captive_portal:
    
    

Strange: Today it is starting but with these errors: Communication with SSD1306 failed!

Show code
Dependency Graph
|-- ESPAsyncTCP-esphome @ 1.2.3
|-- ESPAsyncWebServer-esphome @ 2.1.0
|   |-- ESPAsyncTCP-esphome @ 1.2.3
|   |-- Hash @ 1.0
|   |-- ESP8266WiFi @ 1.0
|-- DNSServer @ 1.1.1
|-- ESP8266WiFi @ 1.0
|-- ESP8266mDNS @ 1.2
|-- noise-c @ 0.1.4
|   |-- libsodium @ 1.10018.1
|-- Wire @ 1.0
Compiling /data/esp-door/.pioenvs/esp-door/src/main.cpp.o
Linking /data/esp-door/.pioenvs/esp-door/firmware.elf
RAM:   [=====     ]  46.0% (used 37720 bytes from 81920 bytes)
Flash: [=====     ]  51.9% (used 541757 bytes from 1044464 bytes)
Building /data/esp-door/.pioenvs/esp-door/firmware.bin
esp8266_copy_factory_bin(["/data/esp-door/.pioenvs/esp-door/firmware.bin"], ["/data/esp-door/.pioenvs/esp-door/firmware.elf"])
========================= [SUCCESS] Took 23.69 seconds =========================
INFO Successfully compiled program.
INFO Resolving IP address of esp-door.local
INFO  -> 192.168.178.33
INFO Uploading /data/esp-door/.pioenvs/esp-door/firmware.bin (545904 bytes)
INFO Compressed to 376945 bytes
Uploading: [============================================================] 100% Done...


INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from esp-door.local using esphome API
WARNING Can't connect to ESPHome API for esp-door.local: Error resolving IP address: [Errno -5] No address associated with hostname
INFO Trying to reconnect to esp-door.local in the background
INFO Successfully connected to esp-door.local
[15:13:12][I][app:102]: ESPHome version 2023.2.4 compiled on Feb 28 2023, 15:12:28
[15:13:12][C][wifi:504]: WiFi:
[15:13:12][C][wifi:362]:   Local MAC: C4:5B:BE:61:E7:98
[15:13:12][C][wifi:363]:   SSID: [redacted]
[15:13:12][C][wifi:364]:   IP Address: 192.168.178.33
[15:13:12][C][wifi:365]:   BSSID: [redacted]
[15:13:12][C][wifi:367]:   Hostname: 'esp-door'
[15:13:12][C][wifi:369]:   Signal strength: -56 dB ▂▄▆█
[15:13:12][C][wifi:373]:   Channel: 11
[15:13:12][C][wifi:374]:   Subnet: 255.255.255.0
[15:13:12][C][wifi:375]:   Gateway: 192.168.178.1
[15:13:12][C][wifi:376]:   DNS1: 192.168.178.1
[15:13:12][C][wifi:377]:   DNS2: 0.0.0.0
[15:13:12][C][logger:293]: Logger:
[15:13:12][C][logger:294]:   Level: DEBUG
[15:13:12][C][logger:295]:   Log Baud Rate: 115200
[15:13:12][C][logger:296]:   Hardware UART: UART0
[15:13:12][C][i2c.arduino:052]: I2C Bus:
[15:13:12][C][i2c.arduino:053]:   SDA Pin: GPIO16
[15:13:12][C][i2c.arduino:054]:   SCL Pin: GPIO5
[15:13:12][C][i2c.arduino:055]:   Frequency: 50000 Hz
[15:13:12][C][i2c.arduino:058]:   Recovery: bus successfully recovered
[15:13:12][I][i2c.arduino:068]: Results from i2c bus scan:
[15:13:12][I][i2c.arduino:070]: Found no i2c devices!
[15:13:12][C][gpio.output:010]: GPIO Binary Output:
[15:13:12][C][gpio.output:011]:   Pin: GPIO13
[15:13:12][C][gpio.output:010]: GPIO Binary Output:
[15:13:12][C][gpio.output:011]:   Pin: GPIO15
[15:13:12][C][template.switch:076]: Template Switch 'ESPDisplay Demo'
[15:13:12][C][template.switch:098]:   Restore Mode: restore defaults to OFF
[15:13:12][C][template.switch:060]:   Restore State: NO
[15:13:12][C][template.switch:061]:   Optimistic: NO
[15:13:12][C][light:104]: Light 'Light Red'
[15:13:12][C][light:104]: Light 'Light Green'
[15:13:12][C][dht:017]: DHT:
[15:13:12][C][dht:018]:   Pin: GPIO12
[15:13:12][C][dht:024]:   Model: DHT22 (or equivalent)
[15:13:12][C][dht:027]:   Update Interval: 300.0s
[15:13:12][C][dht:029]:   Temperature 'Temperature'
[15:13:12][C][dht:029]:     Device Class: 'temperature'
[15:13:12][C][dht:029]:     State Class: 'measurement'
[15:13:12][C][dht:029]:     Unit of Measurement: '°C'
[15:13:12][C][dht:029]:     Accuracy Decimals: 1
[15:13:12][C][dht:030]:   Humidity 'Humidity'
[15:13:12][C][dht:030]:     Device Class: 'humidity'
[15:13:12][C][dht:030]:     State Class: 'measurement'
[15:13:12][C][dht:030]:     Unit of Measurement: '%'
[15:13:12][C][dht:030]:     Accuracy Decimals: 1
[15:13:12][C][restart.button:017]: Restart Button 'Restart'
[15:13:12][C][safe_mode.button:022]: Safe Mode Button 'Restart in Safe Mode'
[15:13:12][C][safe_mode.button:022]:   Icon: 'mdi:restart-alert'
[15:13:12][C][ssd1306_i2c:023]: I2C SSD1306
[15:13:12][C][ssd1306_i2c:023]:   Rotations: 0 °
[15:13:12][C][ssd1306_i2c:023]:   Dimensions: 128px x 64px
[15:13:12][C][ssd1306_i2c:024]:   Address: 0x3C
[15:13:12][C][ssd1306_i2c:025]:   Model: SSD1306 128x64
[15:13:12][C][ssd1306_i2c:027]:   External VCC: NO
[15:13:12][C][ssd1306_i2c:028]:   Flip X: YES
[15:13:12][C][ssd1306_i2c:029]:   Flip Y: YES
[15:13:12][C][ssd1306_i2c:030]:   Offset X: 0
[15:13:12][C][ssd1306_i2c:031]:   Offset Y: 0
[15:13:12][C][ssd1306_i2c:032]:   Inverted Color: NO
[15:13:12][C][ssd1306_i2c:033]:   Update Interval: 1.0s
[15:13:12][E][ssd1306_i2c:036]: Communication with SSD1306 failed!
[15:13:13][C][captive_portal:088]: Captive Portal:
[15:13:13][C][mdns:108]: mDNS:
[15:13:13][C][mdns:109]:   Hostname: esp-door
[15:13:13][C][ota:093]: Over-The-Air Updates:
[15:13:13][C][ota:094]:   Address: esp-door.local:8266
[15:13:13][C][ota:097]:   Using Password.
[15:13:13][C][api:138]: API Server:
[15:13:13][C][api:139]:   Address: esp-door.local:6053
[15:13:13][C][api:141]:   Using noise encryption: YES
[15:13:13][C][wifi_signal.sensor:009]: WiFi Signal 'WiFi Signal'
[15:13:13][C][wifi_signal.sensor:009]:   Device Class: 'signal_strength'
[15:13:13][C][wifi_signal.sensor:009]:   State Class: 'measurement'
[15:13:13][C][wifi_signal.sensor:009]:   Unit of Measurement: 'dBm'
[15:13:13][C][wifi_signal.sensor:009]:   Accuracy Decimals: 0
[15:13:22][D][api:102]: Accepted 192.168.178.47
[15:13:23][D][api.connection:918]: Home Assistant 2023.2.5 (192.168.178.47): Connected successfully

I2C bus on NodeMCU is on D1 (GPIO 5 - SCL) and D2 (GPIO 4 - SDA). D0 is a Wake pin and could be messing up your boot if something tries to talk to it. The logs say that there is no devices on the I2C bus so I suggest you reconfigure to D1 SCL, D2 SDA and verify that the display is connected to those pins.

Hi, thanks for your answer. Now it is working but the boot of the ESP tooks over 10 Minutes:

INFO Successfully compiled program.
INFO Resolving IP address of esp-door.local
INFO  -> 192.168.178.33
INFO Uploading /data/esp-door/.pioenvs/esp-door/firmware.bin (549152 bytes)
INFO Compressed to 378372 bytes
Uploading: [============================================================] 100% Done...


INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from esp-door.local using esphome API
WARNING Can't connect to ESPHome API for esp-door.local: Error resolving IP address: [Errno -5] No address associated with hostname
INFO Trying to reconnect to esp-door.local in the background

Sorry I have no specifics why it would make boot take longer if it works after booting. Maybe it’s an power issue? I remember back in the day using additional capacitor on ESP8266 3.3V power lines to smooth out wifi related power spikes. You can also try using external 3.3V voltage regulator. Other than that nothing comes to mind. I only used 64x48 SSD1306 based display with ESP8266 and did not have this issue.

After that time it works normally?
What happens if you remove the font?

Hi, after that everything is normal. I don’t know why. The crazy thing is that sometimes the boot process takes longer and sometimes shorter. Maybe it is not the boot process itself, but it takes so long until HA has recognized and connected the ESP again:

“INFO Trying to reconnect to esp-door.local in the background”