Full Guide to read BME680 via BSEC2 on esp8266

Hello!

I wanted to share my painful experience with BME680. This tiny wonderful sensor is really tricky to get it work on an ESP8266 using the latest BSEC libraries from Bosch. On esphome.io there’s a good documentation (BME68x Temperature, Humidity, Pressure & Gas Sensor via BSEC2 — ESPHome) but it’s lacking some tricks to make it work flawless with 8266 boards. I’ve spent a full day trying to make it work, but here’s everything I did, just in case someone else want to try this great sensor.

Wiring scheme:

BME680 ESP8266 NodeMCUv2
VCC 3V3
GND GND
SCL D1
SDA D2
SDO Not Connected
CS Not Connected

Then we have to setup the yaml configuration, we’ll copy and paste more or less the same stuff found on esphome.io:

i2c:

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

sensor:
  - 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: bme68x_bsec2
    iaq_accuracy:
      name: "BME68x IAQ Accuracy"
  - 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"};
      }

Now we have to specify some instructions to the compiler, in order to make BSEC2 works with low memory boards like ESP8266.
Look at the beginning of your file for the section

esphome:

Under this section you have to add the following lines:

 platformio_options:
    build_flags:
      - -DPIO_FRAMEWORK_ARDUINO_MMU_CACHE16_IRAM48_SECHEAP_SHARED

This will instruct the compiler to create a correct firmware for the ESP32

If you don’t add these lines the board will not boot up and flashes its blue led multiple times in a reboot cycle

Now you are ready to flash the firmware to the board!!

But wait… Once you have flashed the board, in my case, the board lost the wifi configuration and I had to access the AP to reconfigure it to access my wifi network… and done!

You can also add these lines to the wifi configuration, in order to make it join the network automatically:

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

now you have your BME680 working with the latest Bosch library on the same ESP8266 hardware you were using before!

3 Likes

Thank you, you most likely saved me days and days of bug hunting.

1 Like