esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 36 forks source link

BME68x Temperature, Humidity, Pressure & Gas Sensor via BSEC2 nowork if not single i2c bus #6246

Open userosos opened 1 month ago

userosos commented 1 month ago

The problem

If i flash the firmware i can see it (the board not work with BME680):

[11:01:29][E][safe_mode:086]: Boot loop detected. Proceeding to safe mode
[11:01:29][E][component:164]: Component safe_mode set Error flag: unspecified

If i commetns:

#  - id: bus_bme680
#    sda: GPIO18
#    scl: GPIO19
#    scan: true

#bme68x_bsec2_i2c:
#  i2c_id: bus_bme680
#  address: 0x77
#  model: bme680
#  operating_age: 28d
#  sample_rate: LP
#  supply_voltage: 3.3V

# bme680
#  - platform: bme68x_bsec2
#    temperature:
#      name: "BME68x Temperature"
#    pressure:
#      name: "BME68x Pressure"
#    humidity:
#      name: "BME68x Humidity"
#    iaq:
#      name: "BME68x IAQ"
#      id: iaq
#    co2_equivalent:
#      name: "BME68x CO2 Equivalent"
#    breath_voc_equivalent:
#      name: "BME68x Breath VOC Equivalent"

#text_sensor:
#  - platform: template
#    name: "BME68x IAQ Classification"
#    lambda: |-
#      if ( int(id(iaq).state) <= 50) {
#        return {"Excellent"};
#      }
#      else if (int(id(iaq).state) >= 51 && int(id(iaq).state) <= 100) {
#        return {"Good"};
#      }
#      else if (int(id(iaq).state) >= 101 && int(id(iaq).state) <= 150) {
#        return {"Lightly polluted"};
#      }
#      else if (int(id(iaq).state) >= 151 && int(id(iaq).state) <= 200) {
#        return {"Moderately polluted"};
#      }
#      else if (int(id(iaq).state) >= 201 && int(id(iaq).state) <= 250) {
#        return {"Heavily polluted"};
#      }
#      else if (int(id(iaq).state) >= 251 && int(id(iaq).state) <= 350) {
#        return {"Severely polluted"};
#      }
#      else if (int(id(iaq).state) >= 351) {
#        return {"Extremely polluted"};
#      }
#      else {
#        return {"error"};
#      }

It work OK,

If i uncomment BME680 and comment bus_b and SHT4x:

  - id: bus_b
    sda: 14
    scl: 15
    scan: true

It work OK too. I think the problem is in creating more than two I2C buses.

Which version of ESPHome has the issue?

2024.8.3

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2024.9.1

What platform are you using?

ESP32

Board

ESP-wroom-32

Component causing the issue

I2C bus?

Example YAML snippet

esphome:
  name: esp-home-1
  friendly_name: esp_home_1
safe_mode:
esp32:
  board: esp32dev
  framework:
    type: arduino
external_components:
  - source: github://nrandell/dallasng
    components: [dallasng]

# Enable logging
logger:

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

ota:
  platform: esphome
  password: ""

wifi:
  networks:
  - ssid: !secret 1_wifi_ssid
    password: !secret 1_wifi_password
  - ssid: !secret 2_wifi_ssid
    password: !secret 2_wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-Home-1 Fallback Hotspot"
    password: "VoRqUtWRVStl"

captive_portal:

i2c:
  - id: bus_a
    sda: 32
    scl: 33
  - id: bus_b
    sda: 14
    scl: 15
    scan: true
  - id: bus_bme680
    sda: GPIO18
    scl: GPIO19
    scan: true

bme68x_bsec2_i2c:
  i2c_id: bus_bme680
  address: 0x77
  model: bme680
  operating_age: 28d
  sample_rate: LP
  supply_voltage: 3.3V

dallasng:
  - pin: 23
    id: hub_1
    update_interval: 1s
  - pin: 21
    id: hub_2
    update_interval: 1s

sensor:
i2c:
  - id: bus_a
    sda: 32
    scl: 33
  - id: bus_b
    sda: 14
    scl: 15
    scan: true
  - id: bus_bme680
    sda: GPIO18
    scl: GPIO19
    scan: true

bme68x_bsec2_i2c:
  i2c_id: bus_bme680
  address: 0x77
  model: bme680
  operating_age: 28d
  sample_rate: LP
  supply_voltage: 3.3V

dallasng:
  - pin: 23
    id: hub_1
    update_interval: 1s
  - pin: 21
    id: hub_2
    update_interval: 1s

sensor:
  - platform: sht4x
    i2c_id: bus_b
    address: 0x44
    temperature:
      name: "SHT4x Temperature"
      id: SHT4x_temp
    humidity:
      name: "SHT4x Relative Humidity"
      id: SHT4x_hum
#  - platform: adc
#    pin: A0
#    name: "MQ8 H2 sensor"
#    update_interval: 60s
#    filters:
#      - multiply: 100
#    unit_of_measurement: "%"
#    icon: "mdi:percent"
  - platform: dht
    pin: GPIO22
    model: DHT11
    temperature:
      name: "Living Room Temperature DHT11"
      id: DHT_TEMP 
    humidity:
      name: "Living Room Humidity DHT11"
      id: DHT_HUM
    update_interval: 60s
  - platform: sgp4x
    i2c_id: bus_a
    address: 0x59
    update_interval: 60s
    voc:
      name: "VOC Index"
      device_class: "aqi"
      state_class: "measurement"
      unit_of_measurement: ""
      accuracy_decimals: 0
      icon: "mdi:radiator"
    nox:
      name: "NOx Index"
      device_class: "aqi"
      state_class: "measurement"
      unit_of_measurement: ""
      accuracy_decimals: 0
      icon: "mdi:radiator"
    compensation:
      humidity_source: SHT4x_hum
      temperature_source: SHT4x_temp
  - platform: dallasng
    dallasng_id: hub_1
    id: D23_temperature_Living
    address: 0x160516b00fb3ff28
    name: "D23 Livingroom Temperature dallas"
    unit_of_measurement: "°C"
    icon: "mdi:water-percent"
    device_class: "temperature"
    state_class: "measurement"

  - platform: internal_temperature
    name: "Internal Temperature"

  - platform: dallasng
    dallasng_id: hub_2
    id: D21_temperature_Living
    address: 0x300316b00d6dff28
    name: "D21 Livingroom Temperature dallas"
    unit_of_measurement: "°C"
    icon: "mdi:water-percent"
    device_class: "temperature"
    state_class: "measurement"

# bme680
  - platform: bme68x_bsec2
    temperature:
      name: "BME68x Temperature"
    pressure:
      name: "BME68x Pressure"
    humidity:
      name: "BME68x Humidity"
    iaq:
      name: "BME68x IAQ"
      id: iaq
    co2_equivalent:
      name: "BME68x CO2 Equivalent"
    breath_voc_equivalent:
      name: "BME68x Breath VOC Equivalent"

text_sensor:
  - platform: template
    name: "BME68x IAQ Classification"
    lambda: |-
      if ( int(id(iaq).state) <= 50) {
        return {"Excellent"};
      }
      else if (int(id(iaq).state) >= 51 && int(id(iaq).state) <= 100) {
        return {"Good"};
      }
      else if (int(id(iaq).state) >= 101 && int(id(iaq).state) <= 150) {
        return {"Lightly polluted"};
      }
      else if (int(id(iaq).state) >= 151 && int(id(iaq).state) <= 200) {
        return {"Moderately polluted"};
      }
      else if (int(id(iaq).state) >= 201 && int(id(iaq).state) <= 250) {
        return {"Heavily polluted"};
      }
      else if (int(id(iaq).state) >= 251 && int(id(iaq).state) <= 350) {
        return {"Severely polluted"};
      }
      else if (int(id(iaq).state) >= 351) {
        return {"Extremely polluted"};
      }
      else {
        return {"error"};
      }

Anything in the logs that might be useful for us?

Leaving...
Hard resetting via RTS pin...
INFO Successfully uploaded program.
INFO Starting log output from /dev/ttyACM2 with baud rate 115200
[11:00:33][I][logger:156]: Log initialized
[11:00:33][C][safe_mode:079]: There have been 0 suspected unsuccessful boot attempts
[11:00:33][D][esp32.preferences:114]: Saving 1 preferences to flash...
[11:00:33][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[11:00:33][I][app:029]: Running through setup()...
[11:00:33][I][i2c.arduino:218]: Performing I2C bus recovery
[11:00:33][I][i2c.arduino:218]: Performing I2C bus recovery
[11:00:33][I][i2c.arduino:218]: Performing I2C bus recovery
[11:00:33][   119][E][Wire.cpp:448] endTransmission(): NULL TX buffer pointer
[11:00:38]E (10515) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
[11:00:38]E (10515) task_wdt:  - loopTask (CPU 1)
[11:00:38]E (10515) task_wdt: Tasks currently running:
[11:00:38]E (10515) task_wdt: CPU 0: IDLE
[11:00:38]E (10515) task_wdt: CPU 1: IDLE
[11:00:38]E (10515) task_wdt: Aborting.
[11:00:38]
[11:00:38]abort() was called at PC 0x40104a64 on core 0
[11:00:38]
[11:00:38]
[11:00:38]Backtrace:0x400843fd:0x3ffbea6c |<-CORRUPTED
WARNING Found stack trace! Trying to decode it
WARNING Decoded 0x400843fd: panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c:402
[11:00:38]
[11:00:38]
[11:00:38]
[11:00:38]
[11:00:38]ELF file SHA256: 0000000000000000
[11:00:38]
[11:00:38]Rebooting...
[11:00:38]ets Jul 29 2019 12:21:46
[11:00:38]
[11:00:38]rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[11:00:38]configsip: 0, SPIWP:0xee
[11:00:38]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[11:00:38]mode:DIO, clock div:2
[11:00:38]load:0x3fff0030,len:1184
[11:00:38]load:0x40078000,len:13132
[11:00:38]load:0x40080400,len:3036
[11:00:38]entry 0x400805e4
[11:00:38][I][logger:156]: Log initialized
[11:00:38][C][safe_mode:079]: There have been 1 suspected unsuccessful boot attempts
[11:00:38][D][esp32.preferences:114]: Saving 1 preferences to flash...
[11:00:38][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[11:00:38][I][app:029]: Running through setup()...
[11:00:38][I][i2c.arduino:218]: Performing I2C bus recovery
[11:00:38][I][i2c.arduino:218]: Performing I2C bus recovery
[11:00:38][I][i2c.arduino:218]: Performing I2C bus recovery
[11:00:38][   119][E][Wire.cpp:448] endTransmission(): NULL TX buffer pointer
[11:00:43]E (10515) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
[11:00:43]E (10515) task_wdt:  - loopTask (CPU 1)
[11:00:43]E (10515) task_wdt: Tasks currently running:
[11:00:43]E (10515) task_wdt: CPU 0: IDLE
[11:00:43]E (10515) task_wdt: CPU 1: IDLE
[11:00:43]E (10515) task_wdt: Aborting.
[11:00:43]
[11:00:43]abort() was called at PC 0x40104a64 on core 0
[11:00:43]
[11:00:43]
[11:00:43]Backtrace:0x400843fd:0x3ffbea6c |<-CORRUPTED
WARNING Found stack trace! Trying to decode it
WARNING Decoded 0x400843fd: panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c:402
[11:00:44]
[11:00:44]
[11:00:44]
[11:00:44]
[11:00:44]ELF file SHA256: 0000000000000000
[11:00:44]
[11:00:44]Rebooting...
[11:00:44]ets Jul 29 2019 12:21:46
[11:00:44]
[11:00:44]rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[11:00:44]configsip: 0, SPIWP:0xee
[11:00:44]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[11:00:44]mode:DIO, clock div:2
[11:00:44]load:0x3fff0030,len:1184
[11:00:44]load:0x40078000,len:13132
[11:00:44]load:0x40080400,len:3036
[11:00:44]entry 0x400805e4
[11:00:44][I][logger:156]: Log initialized
[11:00:44][C][safe_mode:079]: There have been 2 suspected unsuccessful boot attempts
[11:00:44][D][esp32.preferences:114]: Saving 1 preferences to flash...
[11:00:44][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[11:00:44][I][app:029]: Running through setup()...
[11:00:44][I][i2c.arduino:218]: Performing I2C bus recovery
[11:00:44][I][i2c.arduino:218]: Performing I2C bus recovery
[11:00:44][I][i2c.arduino:218]: Performing I2C bus recovery
[11:00:44][   119][E][Wire.cpp:448] endTransmission(): NULL TX buffer pointer

Additional information

I think the problem is in creating more than two I2C buses..

iay commented 2 days ago

I think the problem is in creating more than two I2C buses.

I think that's right. The ESP32 has two, and only two, I2C controller peripherals. It looks like the code that allocates resources for the esp-idf framework version of the i2c bus code checks that you don't attempt to create more than two, but the Arduino framework code does not check. I don't know whether it's supposed to work, but it would have to share one of the controller peripherals between two of the buses which sounds tricky.

Your simplest fix is probably to combine two of the buses, if the device addresses aren't the same.