ESP32 SSD1306 128x64 not connecting

The first time I tried to install my code, it displayed my text on the OLED screen, but it complained about slow response times.  Now it's complaining about **Failed to connect to ESP32: Invalid head of packet (0xE0)**

My log looks like this:

INFO ESPHome 2023.12.7`
INFO Reading configuration /config/esp32-oled-96-test.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing esp32-oled-96-test (board: esp32dev; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch5
Dependency Graph
|-- AsyncTCP-esphome @ 2.0.1
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.1.0
|-- DNSServer @ 2.0.0
|-- ESPmDNS @ 2.0.0
|-- noise-c @ 0.1.4
|-- Wire @ 2.0.0
RAM:   [=         ]  12.5% (used 40952 bytes from 327680 bytes)
Flash: [=====     ]  50.8% (used 932073 bytes from 1835008 bytes)
========================= [SUCCESS] Took 6.80 seconds =========================
INFO Successfully compiled program.
esptool.py v4.6.2
Serial port /dev/ttyUSB1
Connecting......................................
ERROR Running command failed: Failed to connect to ESP32: Invalid head of packet (0xE0): Possible serial noise or corruption.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html
ERROR Please try running esptool.py --before default_reset --after hard_reset --baud 460800 --port /dev/ttyUSB1 --chip esp32 write_flash -z --flash_size detect 0x10000 /data/build/esp32-oled-96-test/.pioenvs/esp32-oled-96-test/firmware.bin 0x1000 /data/build/esp32-oled-96-test/.pioenvs/esp32-oled-96-test/bootloader.bin 0x8000 /data/build/esp32-oled-96-test/.pioenvs/esp32-oled-96-test/partitions.bin 0xe000 /cache/platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin locally.
INFO Upload with baud rate 460800 failed. Trying again with baud rate 115200.
esptool.py v4.6.2
Serial port /dev/ttyUSB1
Connecting......................................
ERROR Running command failed: Failed to connect to ESP32: Invalid head of packet (0xE0): Possible serial noise or corruption.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html
ERROR Please try running esptool.py --before default_reset --after hard_reset --baud 115200 --port /dev/ttyUSB1 --chip esp32 write_flash -z --flash_size detect 0x10000 /data/build/esp32-oled-96-test/.pioenvs/esp32-oled-96-test/firmware.bin 0x1000 /data/build/esp32-oled-96-test/.pioenvs/esp32-oled-96-test/bootloader.bin 0x8000 /data/build/esp32-oled-96-test/.pioenvs/esp32-oled-96-test/partitions.bin 0xe000 /cache/platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin locally.

My configuration file looks like this:

esphome:
  name: esp32-oled-96-test
  friendly_name: ESP32 OLED 96 Test

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

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

ota:
  password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp32-Oled-96-Test"
    password: "xxxxxxxxxxxxxx"


captive_portal:

font:
  - file: "gfonts://Roboto"
    id: roboto
    size: 15

i2c:
  sda: GPIO21
  scl: GPIO22

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
#   reset_pin: D0
    address: 0x3C
    lambda: |-
      it.print(0, 0, id(roboto), "Hello");
      it.print(15, 40, id(roboto), "WORLD");
    
I'm flying a little blind because there were no docs, other than what I could scrounge from the TEMU website.

I was able to install a regular ESP32 WROOM without too much difficulty. I have a second ESP 32 OLED board, so I'm tempted to flash it to see what happens.

That’s simply a warning - it does that for lots of components and you can ignore it.

Why are you mixing GPIO style and D style pin numbering? For ESP32 use GPIO only - much simpler.

This can be caused by selecting the wrong board type.

Finally - please fix your post. Logs and yaml are supposed to be inside preformatted text tags - not your comments. It’s next to unreadable and I reckon no-one else will look twice at your post unless you fix it…

Why isn’t this compulsory reading? How to help us help you - or How to ask a good question

Thanks, I did preformat the code sections, but it did not turn out as expected.

The Reset Pin is commented out, as it is not in the documentation I found. I tried GPIO15, but got a warning about using input pins and it did not make a difference anyway.

The odd thing is that the original code worked, except for the response time warning. I got the error when I tried to install the same code again. Of course the display no longer updates.

It’s possible the module is wrong, but the info I downloaded indicated this is an SSD 1306 128x64. Although the TEMU documentation is not the best.

Thanks for taking the time to decipher the above.

That’s just the display, certainly won’t stop an install. Only other thing I can suggest is to hold down the boot button during install.

I already tried holding down the boot button during install, but it didn’t help. I think I need to reset it to factory, but I don’t know how to do that.

I might try installing on my second device, so I can have two devices that don’t work. LOL.

I might see if the Arduino IDE helps, but I doubt it. The Arduino docs say it’s a U8G2_SSD1306_128X64_NONAME_F_SW_I2C, not sure how that translates to ESPHOME. I noticed the docs say the upload speed is 921600.

What esp board is it?

Please edit the first post to properly quote the yaml.

According to TEMU, this one:

I found this issue on GitHub, but the pin assignments did not align with the above, which seemed to work for the first install.

I updated the YAML, hopefully it’s more readable.

Thanks for the formatting :slight_smile:

How are you trying to flash? An inbuilt usb port or some sort of external serial port?

You say your original code works. Was that built by esphome? Or did you use arduino ide? Or was it already on the esp32?

ssd1306 is the display board.

u8g2 is an arduino library for displaying on that board. The esphome code is here SSD1306 OLED Display — ESPHome.

I flashed the original using the USB Port mapped to my ESP Home Docker. This seemed to work OK, except for the complaint about the delay. I tried to flash the SAME code with new display text and got the connect error. I can only assume the original install caused some kind of issue?

Have you tried via OTA? (please tell me you enabled OTA :slight_smile: )

Yes, I believe OTA is enabled, as it connected during the first install. I will try an OTA update, but I’m wondering if my USB Port Docker mapping is messed up. The ESP Home Docker got updated and the OS also had an update, so I will check the Docker settings tomorrow. (today). Should not be, but ZNFI.

The wireless update worked, other than the response time warning. Is this normal behaviour? The USB Port looks fine.