ESPhome + BME680, coding problem, "Communication with BME680 failed"

hello
Sorry if my question is very simple. I am trying to setup my BME680+ESP8266 with the ESPhome in the hass.io server.
The problem is that the 8266 dont connect to my wifi. The code I “produced” is a big mashup from other forums and quotes. So I cant really explain much of it beside trying to mix the wifi setup from an LED project I had with the sensor readings.

I can see the readings on the Serial Monitor on arduino id so I think it is only the wifi that is the problem so far. Sorry I can still very new at this.


const char* ssid = "xxx";
const char* password = "xxx";
const char* mqtt_server = "hass.io server ip";
const char* mqtt_username = "xxx";
const char* mqtt_password = "xxx";
const int mqtt_port = 1883;


#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <PubSubClient.h>

 
#define SEALEVELPRESSURE_HPA (1013.25)
 
Adafruit_BME680 bme; // I2C
 
void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println(F("BME680 test"));
 
  if (!bme.begin(0x76)) 
  {
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    while (1);
  }
 
  // Set up oversampling and filter initialization
  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150); // 320*C for 150 ms
}
 
void loop() 
{
  if (! bme.performReading()) 
  {
    Serial.println("Failed to perform reading :(");
    return;
  }
  Serial.print("Temperature = ");
  Serial.print(bme.temperature);
  Serial.println(" *C");
 
  Serial.print("Pressure = ");
  Serial.print(bme.pressure / 100.0);
  Serial.println(" hPa");
 
  Serial.print("Humidity = ");
  Serial.print(bme.humidity);
  Serial.println(" %");
 
  Serial.print("Gas = ");
  Serial.print(bme.gas_resistance / 1000.0);
  Serial.println(" KOhms");
 
  Serial.print("Approx. Altitude = ");
  Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");
 
  Serial.println();
  delay(2000);
}

My hardware:
NodeMCU 3v ESP8266
pimonori BME680

and arduino id is set to board NodeMCU 1.0 (ESP-12E Module)
Main source of the copied code: http://www.esp8266learning.com/bme680-environment-sensor-and-esp8266-example.php

Thanks for the time and I hope you can help me. Have a nice day and happy new year.

You posted in the ESPHome category but that isn’t ESPHome it’s an Arduino sketch.

Why not just use ESPhome, it’s much easier. Just a few lines of YAML for each of the sensor, api and board type.

1 Like

Hello Tom

Thanks for the answer and happy new year. Sorry maybe I should have been more specific.

I am running Hass.io on raspberry pi 4, with the ESPhome add on.

And then I would like to have the esp8266 + bme860 running over WiFi, some random place in the house.

I am grateful for the link, that code goes to the configuration.yaml file in Hass.io I guess? I am not that used to it.

But I first need to have the esp8266 running on the WiFi to add it to the esphome addon.

Or maybe I am misunderstanding the process completely? I am in a bit of a loss sorry.

Maybe if you could, do you know a good place for getting help with arduino sketches ?

(I tried to add that code, just to be sure, on Arduino Id to transfer it to the board but got a error code while checken for errors.)

Sorry I keep editing because I am a bit dyslexic. But I might have found a topic in this forum that might be useful. I check it out tomorrow and I have more free time.

No. That configuration goes in a file that is compiled and loaded onto the esp board.

Instead of writing a sketch all you have to do is add simple yaml for the board type you are using sensor, wifi connection, and api (to connect to hone assistant). ESP home then takes that info and does all the work for you by creating the binary file to load onto the ESP board.

See;

Also have a Look at the main esphome index page. It lists a bunch of sensors and devices. Click on one to go to an example yaml config you can use.

3 Likes

hello Tom

I hope you had a good start of the new year. I am sorry I have to ask you again for your assistant. So I tried my to play around ESPhome now, but I get an error when I try to validate the file and I cant seem to find other examples on the ESPhome BME680 information about that.

INFO Reading configuration /config/esphome/bme680.yaml...
Failed config

sensor.bme680: [source /config/esphome/bme680.yaml:25]
  
  Component sensor.bme680 requires component i2c.
  platform: bme680
  temperature: 
    name: BME680 Temperature
    oversampling: 16x
  pressure: 
    name: BME680 Pressure
  humidity: 
    name: BME680 Humidity
  gas_resistance: 
    name: BME680 Gas Resistance
  address: 119
  update_interval: 60s

so I looked at the ESPhome guides and found this page:

and I tried to do a little copy paste job again, while looking at the correct pins.

esphome:
  name: bme680
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "xxx"
  password: "xxx"

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

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
sensor:
  - platform: bme680
      i2c:
       sda: GPIO5
       scl: GPIO4
    temperature:
      name: "BME680 Temperature"
      oversampling: 16x
    pressure:
      name: "BME680 Pressure"
    humidity:
      name: "BME680 Humidity"
    gas_resistance:
      name: "BME680 Gas Resistance"
    address: 0x77
    update_interval: 60s

and get the error

INFO Reading configuration /config/esphome/bme680.yaml...
ERROR Error while reading config: Invalid YAML syntax. Please see YAML syntax reference or use an online YAML syntax validator:

mapping values are not allowed here
  in "/config/esphome/bme680.yaml", line 26, column 10:
          i2c:
             ^

again i am very sorry to bother you again. I hope you will have a nice day.

Hi christoffer,
Maybe I can help you a bit here. I used the same setup for a while. And I think you can fix it if you use it like this:

esphome:
  name: bme680
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "xxx"
  password: "xxx"

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

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

i2c:
  sda: GPIO4
  scl: GPIO5
  id: mbe_sensor

sensor:
  - platform: bme680
    i2c_id: mbe_sensor
    address: 0x77
    temperature:
      name: "BME680 Temperature"
      oversampling: 16x
    pressure:
      name: "BME680 Pressure"
    humidity:
      name: "BME680 Humidity"
    gas_resistance:
      name: "BME680 Gas Resistance"
    update_interval: 60s

Hope it helps!

(note that i switched the I2C gpio-pins to the default on the ESPHome-documentation).

2 Likes

Hello rds

Thanks the code validates now. I can see that my spacing was all over the place.
Your code also help me to see how to insert the i2s code into the sensor code. thanks for the help
and thanks to you too tom. you where both very helpful


well I got it up and running now. But I seems to not be able to get any data showing in any cards. I also get a “Communication with BME680 failed!” when viewing the log.

[22:19:10][I][app:100]: ESPHome version 1.14.3 compiled on Jan  2 2020, 21:51:54
[22:19:10][C][i2c:028]: I2C Bus:
[22:19:10][C][i2c:029]:   SDA Pin: GPIO4
[22:19:10][C][i2c:030]:   SCL Pin: GPIO5
[22:19:10][C][i2c:031]:   Frequency: 50000 Hz
[22:19:10][I][i2c:033]: Scanning i2c bus for active devices...
[22:19:10][I][i2c:049]: Found no i2c devices!
[22:19:10][C][logger:175]: Logger:
[22:19:10][C][logger:176]:   Level: DEBUG
[22:19:10][C][logger:177]:   Log Baud Rate: 115200
[22:19:10][C][logger:178]:   Hardware UART: UART0
[22:19:11][C][bme680.sensor:208]: BME680:
[22:19:11][C][bme680.sensor:209]:   Address: 0x77
[22:19:11][E][bme680.sensor:211]: Communication with BME680 failed!
[22:19:11][C][bme680.sensor:213]:   IIR Filter: OFF
[22:19:11][C][bme680.sensor:214]:   Update Interval: 60.0s
[22:19:11][C][bme680.sensor:216]:   Temperature 'BME680 Temperature'
[22:19:11][C][bme680.sensor:216]:     Unit of Measurement: '°C'
[22:19:11][C][bme680.sensor:216]:     Accuracy Decimals: 1
[22:19:11][C][bme680.sensor:216]:     Icon: 'mdi:thermometer'
[22:19:11][C][bme680.sensor:217]:     Oversampling: 16x
[22:19:11][C][bme680.sensor:218]:   Pressure 'BME680 Pressure'
[22:19:11][C][bme680.sensor:218]:     Unit of Measurement: 'hPa'
[22:19:11][C][bme680.sensor:218]:     Accuracy Decimals: 1
[22:19:11][C][bme680.sensor:218]:     Icon: 'mdi:gauge'
[22:19:11][C][bme680.sensor:219]:     Oversampling: 16x
[22:19:11][C][bme680.sensor:220]:   Humidity 'BME680 Humidity'
[22:19:11](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[22:19:11](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[22:19:11](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[22:19:11][C][bme680.sensor:221]:     Oversampling: 16x
[22:19:11][C][bme680.sensor:222]:   Gas Resistance 'BME680 Gas Resistance'
[22:19:11][C][bme680.sensor:222]:     Unit of Measurement: 'Ω'
[22:19:11][C][bme680.sensor:222]:     Accuracy Decimals: 1
[22:19:11][C][bme680.sensor:222]:     Icon: 'mdi:gas-cylinder'
[22:19:11][C][bme680.sensor:226]:   Heater temperature=320°C duration=150ms
[22:19:11][C][captive_portal:169]: Captive Portal:
[22:19:11][C][ota:029]: Over-The-Air Updates:
[22:19:11][C][ota:030]:   Address: xxx.local:xxx
[22:19:11][C][api:095]: API Server:
[22:19:11][C][api:096]:   Address: xxx.local:xxx

So I read that one solution could be to set oversampling: 1x for all values. so that what I did but still got the same error:

source: BME280 communication failed

[22:33:28][C][i2c:028]: I2C Bus:
[22:33:28][C][i2c:029]:   SDA Pin: GPIO4
[22:33:28][C][i2c:030]:   SCL Pin: GPIO5
[22:33:28][C][i2c:031]:   Frequency: 50000 Hz
[22:33:28][I][i2c:033]: Scanning i2c bus for active devices...
[22:33:28][I][i2c:040]: Found i2c device at address 0x76
[22:33:28][C][logger:175]: Logger:
[22:33:28][C][logger:176]:   Level: DEBUG
[22:33:28][C][logger:177]:   Log Baud Rate: 115200
[22:33:28][C][logger:178]:   Hardware UART: UART0
[22:33:28][C][bme680.sensor:208]: BME680:
[22:33:28][C][bme680.sensor:209]:   Address: 0x77
[22:33:28][E][bme680.sensor:211]: Communication with BME680 failed!
[22:33:28][C][bme680.sensor:213]:   IIR Filter: OFF
[22:33:28][C][bme680.sensor:214]:   Update Interval: 60.0s
[22:33:28][C][bme680.sensor:216]:   Temperature 'BME680 Temperature'
[22:33:28][C][bme680.sensor:216]:     Unit of Measurement: '°C'
[22:33:28][C][bme680.sensor:216]:     Accuracy Decimals: 1
[22:33:28][C][bme680.sensor:216]:     Icon: 'mdi:thermometer'
[22:33:28][C][bme680.sensor:217]:     Oversampling: 1x
[22:33:28][C][bme680.sensor:218]:   Pressure 'BME680 Pressure'
[22:33:28][C][bme680.sensor:218]:     Unit of Measurement: 'hPa'
[22:33:28][C][bme680.sensor:218]:     Accuracy Decimals: 1
[22:33:28][C][bme680.sensor:218]:     Icon: 'mdi:gauge'
[22:33:28][C][bme680.sensor:219]:     Oversampling: 1x
[22:33:28][C][bme680.sensor:220]:   Humidity 'BME680 Humidity'
[22:33:28](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[22:33:28][C][bme680.sensor:220]:     Accuracy Decimals: 1
[22:33:28][C][bme680.sensor:220]:     Icon: 'mdi:water-percent'
[22:33:28][C][bme680.sensor:221]:     Oversampling: 1x
[22:33:28][C][bme680.sensor:222]:   Gas Resistance 'BME680 Gas Resistance'
[22:33:28][C][bme680.sensor:222]:     Unit of Measurement: 'Ω'
[22:33:28][C][bme680.sensor:222]:     Accuracy Decimals: 1
[22:33:28][C][bme680.sensor:222]:     Icon: 'mdi:gas-cylinder'
[22:33:28][C][bme680.sensor:226]:   Heater temperature=320°C duration=150ms
[22:33:28][C][captive_portal:169]: Captive Portal:
[22:33:28][C][ota:029]: Over-The-Air Updates:
[22:33:28][C][ota:030]:   Address: xxx.local:xxx
[22:33:28][C][api:095]: API Server:
[22:33:28][C][api:096]:   Address: xxx.local:xxx

I am sorry to be bothersome again.

1 Like

Hi Christoffer,

I saw your post before the edit so i did not get an notification, sorry about that!
It’s possible that your sensor is communicating over an alternative address.
can you edit your config with the following address:

sensor:
  - platform: bme680
    i2c_id: mbe_sensor
    address: 0x76
    temperature:
      name: "BME680 Temperature"
      oversampling: 16x
    pressure:
      name: "BME680 Pressure"
    humidity:
      name: "BME680 Humidity"
    gas_resistance:
      name: "BME680 Gas Resistance"
    update_interval: 60s
1 Like

Hello Rds

No need to be sorry, I am just happy you took the time to write. It can be a little confusing for a new comer like me. I could also have made a new post but I did want to over spam the forum with my simple problems.

But it work perfectly now, sadly I cant mark both your answers as the solution. I also looked up the change you made of changing the adress to 0x76 from my 0x77. It is gold for me to know that it is either 0x76 or 0x77 now :grinning:

thanks again for the response, it was very kind of you. have a great week.

from
Christoffer

proff of it working now:

[12:55:14][C][i2c:028]: I2C Bus:
[12:55:14][C][i2c:029]:   SDA Pin: GPIO4
[12:55:14][C][i2c:030]:   SCL Pin: GPIO5
[12:55:14][C][i2c:031]:   Frequency: 50000 Hz
[12:55:14][I][i2c:033]: Scanning i2c bus for active devices...
[12:55:14][I][i2c:040]: Found i2c device at address 0x76
[12:55:14][C][logger:175]: Logger:
[12:55:14][C][logger:176]:   Level: DEBUG
[12:55:14][C][logger:177]:   Log Baud Rate: 115200
[12:55:14][C][logger:178]:   Hardware UART: UART0
[12:55:14][C][bme680.sensor:208]: BME680:
[12:55:14][C][bme680.sensor:209]:   Address: 0x76
[12:55:14][C][bme680.sensor:213]:   IIR Filter: OFF
[12:55:14][C][bme680.sensor:214]:   Update Interval: 60.0s
[12:55:14][C][bme680.sensor:216]:   Temperature 'BME680 Temperature'
[12:55:14][C][bme680.sensor:216]:     Unit of Measurement: '°C'
[12:55:14][C][bme680.sensor:216]:     Accuracy Decimals: 1
[12:55:14][C][bme680.sensor:216]:     Icon: 'mdi:thermometer'
[12:55:14][C][bme680.sensor:217]:     Oversampling: 16x
[12:55:14][C][bme680.sensor:218]:   Pressure 'BME680 Pressure'
[12:55:14][C][bme680.sensor:218]:     Unit of Measurement: 'hPa'
[12:55:14][C][bme680.sensor:218]:     Accuracy Decimals: 1
[12:55:14][C][bme680.sensor:218]:     Icon: 'mdi:gauge'
[12:55:14][C][bme680.sensor:219]:     Oversampling: 16x
[12:55:14][C][bme680.sensor:220]:   Humidity 'BME680 Humidity'
[12:55:14][C][bme680.sensor:220]:     Unit of Measurement: '%'
[12:55:14](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[12:55:14](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[12:55:14](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[12:55:14][C][bme680.sensor:222]:   Gas Resistance 'BME680 Gas Resistance'
[12:55:14][C][bme680.sensor:222]:     Unit of Measurement: 'Ω'
[12:55:14][C][bme680.sensor:222]:     Accuracy Decimals: 1
[12:55:14][C][bme680.sensor:222]:     Icon: 'mdi:gas-cylinder'
[12:55:14][C][bme680.sensor:226]:   Heater temperature=320°C duration=150ms
[12:55:14][C][captive_portal:169]: Captive Portal:
[12:55:14][C][ota:029]: Over-The-Air Updates:
[12:55:14][C][ota:030]:   Address: bme680.local:8266
[12:55:14][C][api:095]: API Server:
[12:55:14][C][api:096]:   Address: bme680.local:6053
1 Like

Hi Christoffer,

Good to see that everything is working now!
I’m happy to help, you have a great week too!

1 Like

Thanks RDS Online,

I had the same problem with coding this ESP8266 and BME680 connected.
The initial pages are not so clear how to add these codes and how to overcome X markings that are problems in the code.

I am new to Home Assistant.

Thanks for the help!

Greet Jim

Does anyone know how to calibrate the pressure sensor? Its way off with mine. Should be 1029 and indicating 1013?

Hello Jimbo
I havent been calibrating my BME680 (because I have been lazy i guess) but I did some google fu.
also if you are interested here is a good article on reading the gas sensor:

But to then pressure, I have found this datasheet for the sensor:

If you look at page: 18, there is a formular that the chip use to calculate the pressure.

also worth noticing on page 3

Key parameters for pressure sensor
 RMS Noise 0.12 Pa, equiv. to 1.7 cm
 Offset temperature coefficient ±1.3 Pa/K, equiv. to ±10.9 cm at 1 °C temperature change

so maybe a combination of noise and that the other values are a bit off as well so that it set the calculation it does for showing the pressure value.
(I am not an expert so I might be wrong)

Hey guys,

@Keglekongen, I’m very happy you were able to get your sensor up and running.
I am now trying to do the exact same thing and I’m having what seems to be the same exact problem which led me here.
However, I’ve tried the steps here and it hasn’t helped solve my problem, I’m hoping I am just missing something.
Maybe someone could help me with this.
I’d be very grateful, as a newbie into custom devices and sensors for home automation.

I am running a nodemcuv2.
I have carefully connected a bme680 sensor, making sure to connect all the pins according the the info on the esphome website.

I have uploaded the following code to the nodemcu:

esphome:
  name: esp8266_1
  platform: ESP8266
  board: nodemcuv2

wifi:
  ssid: "my_wifi"
  password: "my_wifi_password"
  manual_ip:
    static_ip: 192.168.1.40
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 192.168.1.1
    dns2: 192.168.1.1

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

captive_portal:

# Enable logging
logger:

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

ota:
  password: "password"
    
# i2c  
i2c:
  sda: GPIO4
  scl: GPIO5
  scan: True
  id: bme_680

# bme680 sensor
sensor:
  - platform: bme680
    i2c_id: bme_680
    address: 0x76
    temperature:
      name: "BME680 Temperature"
      oversampling: 16x
    pressure:
      name: "BME680 Pressure"
    humidity:
      name: "BME680 Humidity"
    gas_resistance:
      name: "BME680 Gas Resistance"
    update_interval: 30s

and this is the result:

[03:24:32][C][i2c:028]: I2C Bus:
[03:24:32][C][i2c:029]:   SDA Pin: GPIO4
[03:24:32][C][i2c:030]:   SCL Pin: GPIO5
[03:24:32][C][i2c:031]:   Frequency: 50000 Hz
[03:24:32][I][i2c:033]: Scanning i2c bus for active devices...
[03:24:32][I][i2c:049]: Found no i2c devices!
[03:24:32][C][logger:175]: Logger:
[03:24:32][C][logger:176]:   Level: DEBUG
[03:24:32][C][logger:177]:   Log Baud Rate: 115200
[03:24:32][C][logger:178]:   Hardware UART: UART0
[03:24:32][C][bme680.sensor:208]: BME680:
[03:24:32][C][bme680.sensor:209]:   Address: 0x76
[03:24:32][E][bme680.sensor:211]: Communication with BME680 failed!
[03:24:32][C][bme680.sensor:213]:   IIR Filter: OFF
[03:24:32][C][bme680.sensor:214]:   Update Interval: 60.0s
[03:24:32][C][bme680.sensor:216]:   Temperature 'BME680 Temperature'
[03:24:32][C][bme680.sensor:216]:     Unit of Measurement: '°C'
[03:24:32][C][bme680.sensor:216]:     Accuracy Decimals: 1
[03:24:32][C][bme680.sensor:216]:     Icon: 'mdi:thermometer'
[03:24:32][C][bme680.sensor:217]:     Oversampling: 16x
[03:24:32][C][bme680.sensor:218]:   Pressure 'BME680 Pressure'
[03:24:32][C][bme680.sensor:218]:     Unit of Measurement: 'hPa'
[03:24:32][C][bme680.sensor:218]:     Accuracy Decimals: 1
[03:24:32][C][bme680.sensor:218]:     Icon: 'mdi:gauge'
[03:24:32][C][bme680.sensor:219]:     Oversampling: 16x
[03:24:32][C][bme680.sensor:220]:   Humidity 'BME680 Humidity'
[03:24:32](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[03:24:32](Message skipped because it was too big to fit in TCP buffer - This is only cosmetic)
[03:24:33][C][bme680.sensor:220]:     Icon: 'mdi:water-percent'
[03:24:33][C][bme680.sensor:221]:     Oversampling: 16x
[03:24:33][C][bme680.sensor:222]:   Gas Resistance 'BME680 Gas Resistance'
[03:24:33][C][bme680.sensor:222]:     Unit of Measurement: 'Ω'
[03:24:33][C][bme680.sensor:222]:     Accuracy Decimals: 1
[03:24:33][C][bme680.sensor:222]:     Icon: 'mdi:gas-cylinder'
[03:24:33][C][bme680.sensor:226]:   Heater temperature=320°C duration=150ms

I have tried the address 0x77 and 0x76, as well as a few other addresses that the logs show found an i2c device at different time, so I can’t figure out how to get this running.

Does anyone see anything I don’t that might be causing the problem?

Turns out I had a bad sensor.
Replaced it and everything works beautifully.

Hello
I am sorry I did not response. I had not used home assistant since they stop supporting Pi-hole so all the messeges had to going to my spam filter sadly. I am glad that you found the solution.

Thanks for the info. Sorry for the late reply. I just gave up on the BME680. To much hassle.