trvrnrth / esphome-bsec-bme680

ESPHome component for the Bosch BME680 sensor via BSEC providing temperature, humidity, pressure and indoor air quality measurements.
85 stars 17 forks source link

i2c address 0x77 - Error and Safe Mode #25

Closed dmar29 closed 3 years ago

dmar29 commented 3 years ago

Hello, it´s my first time, that i write an issue on github. So sorry when i m doing it the wrong way. My BME680 comes with address 0x77. When i do so in the YAML-File, I got an Error-Message and the ESP goes in the Safe Mode. When i change the Config to 0x76 i have no Errors, but also no sensor-readings :-)

the normal config from esphome.io works with the address 0x77. so maybe it´s something in the bsec-framework? I just found a "hard entry" 0x76 in the init-File.

Sorry, that i made no Screenshots.

trvrnrth commented 3 years ago

I'm not sure what "hard entry" you're referring to but if you can provide your config and log output then I may be able to help you.

dmar29 commented 3 years ago

I'm not sure what "hard entry" you're referring to but if you can provide your config and log output then I may be able to help you.

This part in your init-File:

    cv.Optional(CONF_STATE_SAVE_INTERVAL, default='6hours'): cv.positive_time_period_minutes,
}).extend(i2c.i2c_device_schema(0x76))

i copy all of your example code in my configuration and this is the log-file:

[09:37:12][I][i2c:033]: Scanning i2c bus for active devices...
[09:37:12][I][i2c:040]: Found i2c device at address 0x3C
[09:37:12][I][i2c:040]: Found i2c device at address 0x77
[09:37:12][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'PIR Sensor'
[09:37:12][C][gpio.binary_sensor:015]:   Device Class: 'motion'
[09:37:12][C][gpio.binary_sensor:016]:   Pin: GPIO14 (Mode: INPUT)
[09:37:12][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Helligkeit'
[09:37:12][C][gpio.binary_sensor:016]:   Pin: GPIO12 (Mode: INPUT, INVERTED)
[09:37:12][C][logger:185]: Logger:
[09:37:12][C][logger:186]:   Level: DEBUG
[09:37:12][C][logger:187]:   Log Baud Rate: 115200
[09:37:12][C][logger:188]:   Hardware UART: UART0
[09:37:12][C][bme680_bsec.sensor:059]: BME680 via BSEC:
[09:37:12][C][bme680_bsec.sensor:061]:   BSEC Version: 1.4.8.0
[09:37:12][C][bme680_bsec.sensor:062]:   Address: 0x76
[09:37:12][E][bme680_bsec.sensor:066]: Communication failed with BSEC Status: 0, BME680 Status: -2

i think this is correct, because my sensor is at 0x77 and not 0x76. Here is the cofiguration with Adress 0x77:

esphome:
  name: senspack_buero
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "123"
  password: "123"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Senspack Buero Fallback Hotspot"
    password: "123"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "123"

ota:
  password: "123"

# i2c-Bus für die Übertragung ans Display und BME680
i2c:
  sda: D1
  scl: D2

bme680_bsec:
    # i2c address
    # -----------
    # Common values are:
    # - 0x76
    # - 0x77
    # Default: 0x76
    address: 0x77

    # Temperature offset
    # ------------------
    # Useful if device is in enclosure and reads too high
    # Default: 0
    temperature_offset: 0

    # IAQ calculation mode
    # --------------------
    # Available options:
    # - static (for fixed position devices)
    # - mobile (for on person or other moveable devices)
    # Default: static
    iaq_mode: static

    # Sample rate
    # -----------
    # Available options:
    # - lp (low power - samples every 3 seconds)
    # - ulp (ultra low power - samples every 5 minutes)
    # Default: lp
    sample_rate: lp

    # Interval at which to save BSEC state
    # ------------------------------------
    # Default: 6h
    state_save_interval: 6h

sensor:
  - platform: bme680_bsec
    temperature:
      # Temperature in °C
      name: "BME680 Temperature"
      filters:
        - median
    pressure:
      # Pressure in hPa
      name: "BME680 Pressure"
      filters:
        - median
    humidity:
      # Relative humidity %
      name: "BME680 Humidity"
      filters:
        - median
    gas_resistance:
      # Gas resistance in Ω
      name: "BME680 Gas Resistance"
      filters:
        - median
    iaq:
      # Indoor air quality value
      name: "BME680 IAQ"
      filters:
        - median
    iaq_accuracy:
      # IAQ accuracy as a numeric value of 0, 1, 2, 3
      name: "BME680 Numeric IAQ Accuracy"
    co2_equivalent:
      # CO2 equivalent estimate in ppm
      name: "BME680 CO2 Equivalent"
      filters:
        - median
    breath_voc_equivalent:
      # Volatile organic compounds equivalent estimate in ppm
      name: "BME680 Breath VOC Equivalent"
      filters:
        - median

text_sensor:
  - platform: bme680_bsec
    iaq_accuracy:
      # IAQ accuracy as a text value of Stabilizing, Uncertain, Calibrating, Calibrated
      name: "BME680 IAQ Accuracy"

# Bewegungsmelder einrichten
binary_sensor:
  - platform: gpio
    pin: D5
    name: "PIR Sensor"
    device_class: motion
    id: motion

# Sensor für Helligkeit mit digitaler Ausgabe (1/0)
# Es wird erst nach 100 ms auf Dunkel geschaltet, um ggf. kurze Abdeckungen zu vermeiden.
  - platform: gpio
    pin: 
      number: D6
      inverted: True
    name: "Helligkeit"
    filters:
      - delayed_off: 500ms

# Font für Display festlegen
font:
  - file: "Tahoma Regular font.ttf"
    id: my_font
    size: 12

# Display für die Anzeige
display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x32"
    reset_pin: D0
    address: 0x3C
    lambda: |-
      if (id(motion).state) {
      it.printf(0, 4, id(my_font), "Hallo und" );
      it.printf(0, 20, id(my_font), "Guten Tag" );
      }

and the log-file after upload:

INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from senspack_buero.local using esphome API
INFO Connecting to senspack_buero.local:6053 (192.168.178.24)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.178.24: timed out). Re-Trying in 1 seconds
INFO Connecting to senspack_buero.local:6053 (192.168.178.24)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.178.24: timed out). Re-Trying in 1 seconds
INFO Connecting to senspack_buero.local:6053 (192.168.178.24)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.178.24: [Errno 111] Connection refused). Re-Trying in 2 seconds

and a little bit of the log via usb:

INFO Reading configuration /config/esphome/senspack_buero.yaml...
INFO Starting log output from /dev/ttyUSB0 with baud rate 115200
[09:48:28][I][ota:046]: Boot seems successful, resetting boot loop counter.
[09:48:28][E][ota:375]: No OTA attempt made, restarting.
[09:48:28][I][app:132]: Forcing a reboot...
[09:48:28][W][wifi_esp8266:395]: Event: Disconnected ssid='123' bssid=[redacted] reason='Association Leave'
[09:48:28]
[09:48:28] ets Jan  8 2013,rst cause:4, boot mode:(3,6)
[09:48:28]
[09:48:28]wdt reset
[09:48:28]load 0x4010f000, len 3584, room 16 
[09:48:28]tail 0
[09:48:28]chksum 0xb0
[09:48:28]csum 0xb0
[09:48:28]v2843a5ac
[09:48:28]~ld
[09:48:28][I][logger:166]: Log initialized
[09:48:28][C][ota:366]: There have been 0 suspected unsuccessful boot attempts.
[09:48:28][I][app:029]: Running through setup()...
[09:48:28][D][binary_sensor:034]: 'PIR Sensor': Sending initial state OFF
[09:48:28][D][binary_sensor:034]: 'Helligkeit': Sending initial state ON
[09:48:28][C][bme680_bsec.sensor:025]: Setting up BME680 via BSEC...
[09:48:28][C][ssd1306_i2c:010]: Setting up I2C SSD1306...
[09:48:28]
[09:48:28]--------------- CUT HERE FOR EXCEPTION DECODER ---------------
[09:48:28]
[09:48:28]Exception (0):
WARNING Exception type: unknown
[09:48:28]epc1=0x7017701a epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
[09:48:28]
[09:48:28]>>>stack>>>
WARNING Found stack trace! Trying to decode it
[09:48:28]
[09:48:28]ctx: sys
[09:48:28]sp: 3fffedb0 end: 3fffffb0 offset: 0190
[09:48:28]3fffef40:  70177017 70177017 70177017 70177017  
[09:48:28]3fffef50:  70177017 70177017 ff177017 ffffffff  
[09:48:28]3fffef60:  dcffffff dc05dc05 ffffff05 dcffffff  
[09:48:28]3fffef70:  ff05dc05 ffffffff ffffffff ffffffff  
[09:48:28]3fffef80:  ffffffff ffffffff ffffffff ffffffff  
[09:48:28]3fffef90:  2cffffff 6098e901 72bbfb89 8f6306aa  
[09:48:28]3fffefa0:  402501d4 3fffef3c 40250185 3ffff678  
INFO Need to fetch platformio IDE-data, please stand by
INFO Running:  platformio run -d /config/esphome/senspack_buero -t idedata
WARNING Decoded 0x402501d4: cont_ret at cont.S.o
WARNING Decoded 0x40250185: cont_continue at cont.S.o
[09:48:44]3fffefb0:  3fffffc0 00000000 00000000 feefeffe  
trvrnrth commented 3 years ago

The value you see in the init is just used to set the default: https://github.com/esphome/esphome/blob/5c86f332b269fd3e4bffcbdf3359a021419effdd/esphome/components/i2c/__init__.py#L37

Do you get any more of the decoded stack trace in your USB log or is that the end of the output?

It would also be interesting to know if your setup works if you temporarily disable your other i2c display device.

dmar29 commented 3 years ago

it works without the display.

[12:05:00][C][captive_portal:169]: Captive Portal:
[12:05:00][C][ota:029]: Over-The-Air Updates:
[12:05:00][C][ota:030]:   Address: senspack_buero.local:8266
[12:05:00][C][ota:032]:   Using Password.
[12:05:00][C][api:095]: API Server:
[12:05:00][C][api:096]:   Address: senspack_buero.local:6053
[12:05:14][D][sensor:092]: 'BME680 Temperature': Sending state 20.94559 °C with 1 decimals of accuracy
[12:05:14][D][sensor:092]: 'BME680 Humidity': Sending state 35.07567 % with 1 decimals of accuracy
[12:05:14][D][sensor:092]: 'BME680 Pressure': Sending state 999.52002 hPa with 1 decimals of accuracy
[12:05:14][D][sensor:092]: 'BME680 Gas Resistance': Sending state 5533.00000 Ω with 0 decimals of accuracy
[12:05:14][D][sensor:092]: 'BME680 IAQ': Sending state 25.00000 IAQ with 0 decimals of accuracy
[12:05:14][D][sensor:092]: 'BME680 CO2 Equivalent': Sending state 500.00000 ppm with 1 decimals of accuracy
[12:05:14][D][sensor:092]: 'BME680 Breath VOC Equivalent': Sending state 0.50000 ppm with 1 decimals of accuracy
[12:05:29][D][sensor:092]: 'BME680 Temperature': Sending state 20.94559 °C with 1 decimals of accuracy
[12:05:29][D][sensor:092]: 'BME680 Humidity': Sending state 34.94994 % with 1 decimals of accuracy
[12:05:29][D][sensor:092]: 'BME680 Pressure': Sending state 999.52002 hPa with 1 decimals of accuracy
[12:05:29][D][sensor:092]: 'BME680 Gas Resistance': Sending state 5384.00000 Ω with 0 decimals of accuracy
[12:05:29][D][sensor:092]: 'BME680 IAQ': Sending state 25.00000 IAQ with 0 decimals of accuracy
[12:05:29][D][sensor:092]: 'BME680 CO2 Equivalent': Sending state 500.00000 ppm with 1 decimals of accuracy
[12:05:29][D][sensor:092]: 'BME680 Breath VOC Equivalent': Sending state 0.50000 ppm with 1 decimals of accuracy
trvrnrth commented 3 years ago

Interesting. I don't have an SSD1306 on hand to test with so I've ordered one. I've been meaning to have a play with the display stuff anyway so it's as good a device to start with as any! I'll report back once I have it and have had a chance to do some testing.

caddyblack commented 3 years ago

Just some information: I had similar event. After removing the display from the configuration it worked. I was assuming the display consumed too much processing time so the BME680 information was not processed correctly. I have no proof of it. I do have an MHZ-19 CO2 sensor in the same configuration as a reference. That combination is OK. All connected to a NodeMCU ESP8266.

trvrnrth commented 3 years ago

@caddyblack Thanks; that's useful to know. Your assumption sounds entirely plausible to me. It might be that the SSD1306 component needs to yield during it's write of display data.

SenexCrenshaw commented 3 years ago

Maybe @kbx81 can help. He helped with the latest code for the SSD1306

trvrnrth commented 3 years ago

@dmar29 Turns out it's not the display itself or the comms to it that are the issue here; it's loading in all the font glyphs that pushed things over the edge. I've made some improvements in #27 to reduce the RAM requirements of this component which has got things up and running for me on a test ESP8266 board.

You may also need to limit the glyphs loaded (see config) depending on what else you have loaded / if you add more fonts / images etc.

trvrnrth commented 3 years ago

@dmar29 I'd be grateful if you could try that branch out and let me know if that resolves things for you without any other changes :)

trvrnrth commented 3 years ago

Just for fun I stuck together a quick little example config to show some of the sensor output: bme680display

  - platform: bme680_bsec
    temperature:
      id: temperature
      name: "BME680 Temperature"
    pressure:
      id: pressure
      name: "BME680 Pressure"
    humidity:
      id: humidity
      name: "BME680 Humidity"
    gas_resistance:
      name: "BME680 Gas Resistance"
    iaq:
      id: iaq
      name: "BME680 IAQ"
    iaq_accuracy:
      id: iaq_accuracy_numeric
      name: "BME680 IAQ Accuracy Numeric"
    co2_equivalent:
      id: co2
      name: "BME680 CO2 Equivalent"
    breath_voc_equivalent:
      id: voc
      name: "BME680 Breath VOC Equivalent"

text_sensor:
  - platform: bme680_bsec
    iaq_accuracy:
      id: iaq_accuracy
      name: "BME680 IAQ Accuracy"

font:
  - file: "tahoma.ttf"
    id: tahoma_23
    size: 23
    glyphs: "0123456789."
  - file: "tahoma.ttf"
    id: tahoma_10
    size: 10

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    lambda: |-
      it.printf(0, -7, id(tahoma_23), "%.1f", id(temperature).state);
      it.print(47, -2, id(tahoma_10), "°C");

      it.printf(70, -7, id(tahoma_23), "%.1f", id(humidity).state);
      it.print(117, -2, id(tahoma_10), "%");

      it.printf(0, 21, id(tahoma_10), "IAQ: %.0f (%s)", id(iaq).state, id(iaq_accuracy).state.c_str());
      it.printf(0, 32, id(tahoma_10), "VOC: %.1f ppm", id(voc).state);
      it.printf(0, 43, id(tahoma_10), "CO2: %.1f ppm", id(co2).state);
      it.printf(0, 54, id(tahoma_10), "Pressure: %.1f hPa", id(pressure).state);
dmar29 commented 3 years ago

i tested it a view minutes ago. Works fine. Thank you.

trvrnrth commented 3 years ago

Awesome!