ESP32-S2 WiFi fails to connect when I2C device is connected

Hello Friends, Happy Monday!
I spent most of the weekend researching this problem. I found a few posts in this thread that were similar but the solutions in those did not help in this case. I have reviewed posts on other forums such as the Espressif community, Arduino forums, etc. These have suggested similar solutions, none of which had any effects. YAML will be at the end of the post.

Problem Description:
I am using an ESP32-S2-DevKitM-1U (Espressif, not a clone). The ESPHome webapp detects it as an esp32-s2-saola-1. Everything works fine until an I2C device is connected to it. When I connect the I2C device (LCD Display) the board boots and the display shows the test message but it never connects to HA or ESPHome.

Component Hardware:
2 - external relays configured as GPIO switches
A rotary encoder (push button of the encoder is configured as a binary sensor).
16X2 LCD display with a PCF8574 controller (I2C)
Status_LED Light (added for troubleshooting)

Power Supply:
Variable bench power supply set to 5.0vdc, current limited to 3.0A (shows current consumption of 100mA with all devices connected).

The LCD requires 5.0vdc so it is powered directly from the bench power supply. The sda and scl pins are connected directly to the MCU.

Troubleshooting:
I have tried several different configurations in the i2c: block with no changes. These different options have been tried one at a time and with all of them together.

To test that the displays I’m working with are good I configured a D1 Mini clone (esp8266) with the display, a button (binary sensor) and two Dallas DS18B20 temperature sensors. These work fine and are visible in HA and ESPHome with all components connected.

Additional Thoughts:
In one of the Arduino forums I visited it was suggested the the voltages on the I2C buss could be at fault. Since the LCD requires 5.0vdc to operate I’m assuming the control pins on the PCF8574 are also operating at 5.0vdc. I don’t see any power regulation on that component. The only way I know to change this is to use a level shifter between the pins on the PCF8574 and the MCU. I haven’t done this yet because the 5.0vdc setup is working fine on the D1 Mini I’m using for troubleshooting. Any comments on this?

I have tried to view the logs coming from the MCU via USB while it is failing to connect to WiFi. I really don’t see anything I recognize as useful. This is all that is displayed:
(Windows 11 using the identified COM port).

PS P:\esphome> esphome logs --device COM6 .\test-esph-esp32s2-e4e8.yaml
INFO ESPHome 2024.6.1
INFO Reading configuration .\test-esph-esp32s2-e4e8.yaml...
INFO Detected timezone 'America/Phoenix'
INFO Starting log output from COM6 with baud rate 115200
[08:20:14]ESP-ROM:esp32s2-rc4-20191025
[08:20:14]Build:Oct 25 2019
[08:20:14]rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
[08:20:14]SPIWP:0xee
[08:20:14]mode:DIO, clock div:1
[08:20:14]load:0x3ffe6100,len:0x524
[08:20:14]load:0x4004c000,len:0xa70
[08:20:14]load:0x40050000,len:0x292c
[08:20:14]entry 0x4004c18c

YAML:

binary_sensor:
  - platform: gpio #rotary encoder button
    pin:
      number: 9
      mode:
        input: True
        pullup: True
      inverted: True
    filters:
      - delayed_on: 50ms
    id: btn_menu

switch: #relays
  - platform: gpio
    name: "Zone 1"
    pin: 1
    id: rly_zone1
    restore_mode: RESTORE_DEFAULT_OFF
  - platform: gpio
    name: "Zone 2"
    pin: 2
    id: rly_zone2
    restore_mode: RESTORE_DEFAULT_OFF

sensor:
  - platform: rotary_encoder
    id: rot_enc
    pin_a: 7
    pin_b: 8
  ###!!! Debug
  # - platform: debug
  #   free:
  #     name: "Heap Free"

i2c:
  sda: 15
  scl: 16
  scan: False #added based on community suggestion
  frequency: 800kHz #added based on community suggestion
  setup_priority: -100 #added based on community suggestion

display:
  - platform: lcd_pcf8574
    dimensions: 16x2
    address: 0x27
    setup_priority: -100 #added based on community suggestion
    lambda: |-
      it.print("Hello World!!");

###
# Debugging details
###
# debug:
#   update_interval: 5s

# text_sensor:
#   - platform: debug
#     device:
#       name: "Device Info"
#     reset_reason:
#       name: "Reset Reason"

Thank you in advance for any comments or suggestions!

-James

Did You tried I2C on another pins ?

1 Like

Yes, I have tried several different pin combinations. I just found the details for the ‘default pin layout’ in the Espressif GitHub repo for Arduino ESP32 S2. They show the default designation for SDA and SCL to be 8 and 9 respectively.

The ESP32 uses a matrix GPIO assignment so in theory almost any pin combination should be able to be used.

I don’t have very high hopes for any different but I’ll give it a try.

Well, I am completely baffled!! I never tried GPIO 8 and 9 because I was using them for the rotary encoder features. I moved the rotary encoder to 12 and 13 with the encoder button on 14 so I could put the I2C pins on SDA=8 and SCL=9 and it works!!

:exploding_head: :exploding_head: :exploding_head:

This leaves more questions than answers for me:

  • Why say in the docs that you can use any pins for I2C without calling out what the defaults are?
  • Why not document the defaults in the datasheet instead of leaving them in an obscure GitHub repository?
  • Or… is this maybe an ESPHome issue? Meaning, is the YAML not being interpreted to properly reassign the I2C pins? (I’m not picking on the devs, I love the platform!)
  • Or (probably most likely)… Did I miss a step somewhere in my config to properly assign the intended I2C pins.

I did go ahead and turn off the I2C scan on boot as well as setting the frequency for the display higher. (At the default frequency I was getting component blocking messages.)

i2c:
  sda: 8
  scl: 9
  scan: False
  frequency: 800kHz
  # setup_priority: -100

display:
  - platform: lcd_pcf8574
    dimensions: 16x2
    address: 0x27
    # setup_priority: -100
    lambda: |-
      it.print("Hello World!!");

Now to move forward to building the menu system.

1 Like

I dicovered something even more weird - Wi-Fi works as long as there is NO MORE THAN ONE i2c device connected to the ESP board. weird, very weird.

I can assure you that many people have been using both esp8266 and esp32 devices with more than one i2c device for years.

If you are having an issue and want help, please create a new issue, do not resurrect a long dead thread.

1 Like