I2C breaks OTA uploads

Take a look at my Yaml file. For the life of me I can’t figure out why my OTA doesn’t work if I uncomment my I2C section and the BME280 sensor. If I keep them both #commented out, I’m able to wirelessly make changes. But as soon as I uncomment those two sections, it errors out on upload. Any ideas?

esphome:
  name: pwm-fan
  friendly_name: PWM Fan

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "Di1y5yHV7fNLfkZkwSgapFnEJqwXxct7c9HnWuIKsh0="

ota:
  platform: esphome
  password: !secret ota_password

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


  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Pwm-Fan Fallback Hotspot"
    password: "zHsYOevLxBzF"

#i2c:
#  sda: GPIO21 #21
#  scl: GPIO22 #22
#  scan: true

captive_portal:

one_wire:
  - platform: gpio
    pin: GPIO32  #32 

sensor:
#  - platform: bme280_i2c
#    temperature:
#      name: "BME280 Temperature"
#    pressure:
#     name: "BME280 Pressure"
#    humidity:
#      name: "BME280 Humidity"
#    address: 0x77

  - platform: pulse_counter
    pin: GPIO3 #W.FAN
    name: West_RPM
    id: fan_pulse_west
    unit_of_measurement: 'RPM' 
    filters:
      - multiply: 0.5
    count_mode:
      rising_edge: INCREMENT
      falling_edge: DISABLE
    update_interval: 3s

  - platform: pulse_counter
    pin: GPIO16 #E.FAN
    name: East_RPM
    id: fan_pulse_east
    unit_of_measurement: 'RPM' 
    filters:
      - multiply: 0.5
    count_mode:
      rising_edge: INCREMENT
      falling_edge: DISABLE
    update_interval: 3s

  - platform: dallas_temp
    address: 0xbb3ce1e38045ba28
    name: "Temperature #1"
    update_interval: 30s
  #  filters:
  #  - offset: 0
  - platform: dallas_temp
    address: 0x123ce1e38058c228
    name: "Temperature #2"
    update_interval: 30s

  - platform: dallas_temp
    address: 0xc800000041bb9128
    name: "Case Temp"
    update_interval: 10s

  - platform: dallas_temp
    address: 0xd63ce1e380825b28
    name: "Outside Temp"
    update_interval: 10s

output:
  - platform: ledc
    pin: GPIO1 #W.FAN
    frequency: 1000 Hz
    inverted: True
    id: fanhub_pwm_west

  - platform: ledc
    pin: GPIO17 #E.FAN
    frequency: 1000 Hz
    inverted: True
    id: fanhub_pwm_east

  - platform: gpio
    id: 'win_cr1'
    pin: GPIO26
  
  - platform: gpio
    id: 'win_cr2'
    pin: GPIO27

switch:
  - platform: output
    name: "wincr1"
    output: 'win_cr1'
    id: wincr1
  
  - platform: output
    name: "wincr2"
    output: 'win_cr2'
    id: wincr2

  - platform: gpio
    name: "Relay 1"
    pin: GPIO15
    inverted: True

  - platform: gpio
    name: "Relay 2"
    pin: GPIO13
    inverted: True

  - platform: gpio
    name: "Relay 3"
    pin: GPIO12
    inverted: True

  - platform: gpio
    name: "Relay 4"
    pin: GPIO14
    inverted: True

  - platform: gpio
    name: "Case Fan"
    pin: GPIO33
    inverted: False

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO4
      mode: INPUT_PULLUP
    name: "Greenhouse Window"
    filters:
      - delayed_on_off: 1000ms
    device_class: window

  - platform: gpio
    pin:
      number: GPIO18
      mode: INPUT_PULLUP
    name: "Greenhouse Door"
    device_class: door

fan:
  - platform: speed
    output: fanhub_pwm_west
    name: "West 8in Fan"

  - platform: speed
    output: fanhub_pwm_east
    name: "East 8in Fan"

A long shot, but did you try clean build? Many times it helps…

Did you try it without the “GPIO” just

i2c:
  sda: 21
  scl: 22
  scan: true

Show the errors it throws up. It might give a clue.

Yes, I’ve tired two different brand new dev boards, same issue.

Good idea, yes I’ve tried it both ways with no difference.

They mean cleaning the ESPhome build files.

1 Like

Ahh okay. I just tried that. Result was it cleaned two files out. Re-ran with the i2c components uncommented…no dice. Dang. I’m attaching the error below:

INFO Upload took 10.22 seconds, waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 192.168.50.140 using esphome API
WARNING Can't connect to ESPHome API for pwm-fan @ 192.168.50.140: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.50.140', port=6053))]: [Errno 113] Connect call failed ('192.168.50.140', 6053) (SocketAPIError)
INFO Trying to connect to pwm-fan @ 192.168.50.140 in the background

Okay…now this get’s interesting. So I’ve built a custom PCB that this ESP32 is the heart of. I just removed the ESP32 from the PCB and powered it via USB at the wall. Totally works, OTA works and then it starts logging after upload like usual…with all YAML uncommented.

So why would only the i2c YAML cause it to fail OTA when it’s secured in my custom PCB?

Found the issue guys. Traced the i2c routes and found a ground short. Thanks for all the help!

1 Like