BME688 - Arduino MKR WiFi 1010 Communication failure I2C

Hello,

I am trying to get raw data from the BME688 sensor on a Sparkfun board on the Arduino MRK WiFi 1010 board using Arduino IDE 2.0.3 and I2C protocol. I have installed both BME68x and BSEC2 from GitHub. I am not sure if I actually need BSEC2 if I only need raw data and not iaq.

I can compile and upload the parallel_mode, sequential_mode and forced_mode examples and I get the same error in the Serial monitor:

Sensor error:Communication failure

I guess that the error comes from the code below:

#ifndef PIN_CS
#define PIN_CS SS
#endif

/* initializes the sensor based on SPI library */

bme.begin(PIN_CS, Wire);

I modified the line: " bme.begin(PIN_CS, SPI); " to " bme.begin(PIN_CS, Wire); " such that I2C protocol is used instead of SPI.

Any help please?

Many thanks!

The device to device wiring is completely different for the SPI and I2C protocols. Different pins, different number of wires.

In the getting started guides, Sparkfun usually shows the wiring for both options on their modules (if both are available), but of course not for every possible Arduino board.

Also, carefully check the device library you are using to make absolutely sure that this line is correct:

bme.begin(PIN_CS, Wire);

Other libraries use other ways of passing that information, for example, this one is common (note the '&'):

bme.begin(PIN_CS, &Wire);

Hello jremington,
Thank you for your reply!

I am pretty sure that the hardware connections for I2C protocol are correct because I have used the Bosch BSEC2 with the basic.ino example and I can get readings. The problem occurs when I use the parallel_mode.ino from the BME68x library.

I searched for "bme.begin" in both BSEC and BME68x libraries folders and it only appears in the parallel_mode, sequential_mode and forced_mode examples, which is odd because I download the latest version of the libraries from GitHub.

Any ideas please?

Thanks!

I2C scanner

What did the I2C scanner report?

How many postings will you be opening up on the same issue?

Your device is a SPI device. I2C IS NOT EQUAL to SPI.

Hello,

I am trying to use the BME688 sensors using Sparkfun breakout boardand BSEC2 library on Arduino IDE 1.8.19 and esp32 pico d4 dev kit with I2C protocol. I followed the instructions on GitHub for the BSEC2 library. I can get the generic_examples > basic.ino to work on MKR Wifi 1010 board but on the esp32 pico d4 dev kit I get the following error when compiling:

undefined reference to `bsec_sensor_control'
collect2: error: ld returned 1 exit status
exit status 1

May I please ask for help on this?

Thank you,

Christoforos

Please post your full sketch and full error message, using code tags for both

Full sketch:

/**
 * Copyright (C) 2021 Bosch Sensortec GmbH
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 */

/* If compiling this examples leads to an 'undefined reference error', refer to the README 
 * at https://github.com/BoschSensortec/Bosch-BSEC2-Library
 */
/* The new sensor needs to be conditioned before the example can work reliably. You may run this
 * example for 24hrs to let the sensor stabilize.
 */

/**
 * basic.ino sketch :
 * This is an example for illustrating the BSEC virtual outputs and
 * which has been designed to work with Adafruit ESP8266 Board
 */

#include <bsec2.h>

/* Macros used */
#define PANIC_LED   LED_BUILTIN
#define ERROR_DUR   1000

/* Helper functions declarations */
/**
 * @brief : This function toggles the led when a fault was detected
 */
void errLeds(void);

/**
 * @brief : This function checks the BSEC status, prints the respective error code. Halts in case of error
 * @param[in] bsec  : Bsec2 class object
 */
void checkBsecStatus(Bsec2 bsec);

/**
 * @brief : This function is called by the BSEC library when a new output is available
 * @param[in] input     : BME68X sensor data before processing
 * @param[in] outputs   : Processed BSEC BSEC output data
 * @param[in] bsec      : Instance of BSEC2 calling the callback
 */
void newDataCallback(const bme68xData data, const bsecOutputs outputs, Bsec2 bsec);

/* Create an object of the class Bsec2 */
Bsec2 envSensor;

/* Entry point for the example */
void setup(void)
{
    /* Desired subscription list of BSEC2 outputs */
    bsecSensor sensorList[] = {
            BSEC_OUTPUT_IAQ,
            BSEC_OUTPUT_RAW_TEMPERATURE,
            BSEC_OUTPUT_RAW_PRESSURE,
            BSEC_OUTPUT_RAW_HUMIDITY,
            BSEC_OUTPUT_RAW_GAS,
            BSEC_OUTPUT_STABILIZATION_STATUS,
            BSEC_OUTPUT_RUN_IN_STATUS
    };

    /* Initialize the communication interfaces */
    Serial.begin(115200);
    Wire.begin();
    pinMode(PANIC_LED, OUTPUT);

    /* Valid for boards with USB-COM. Wait until the port is open */
    while(!Serial) delay(10);

    /* Initialize the library and interfaces */
    if (!envSensor.begin(BME68X_I2C_ADDR_LOW, Wire))
    {
        checkBsecStatus(envSensor);
    }

    /* Subsribe to the desired BSEC2 outputs */
    if (!envSensor.updateSubscription(sensorList, ARRAY_LEN(sensorList), BSEC_SAMPLE_RATE_LP))
    {
        checkBsecStatus(envSensor);
    }

    /* Whenever new data is available call the newDataCallback function */
    envSensor.attachCallback(newDataCallback);

    Serial.println("BSEC library version " + \
            String(envSensor.version.major) + "." \
            + String(envSensor.version.minor) + "." \
            + String(envSensor.version.major_bugfix) + "." \
            + String(envSensor.version.minor_bugfix));
}

/* Function that is looped forever */
void loop(void)
{
    /* Call the run function often so that the library can 
     * check if it is time to read new data from the sensor  
     * and process it.
     */
    if (!envSensor.run())
    {
        checkBsecStatus(envSensor);
    }
}

void errLeds(void)
{
    while(1)
    {
        digitalWrite(PANIC_LED, HIGH);
        delay(ERROR_DUR);
        digitalWrite(PANIC_LED, LOW);
        delay(ERROR_DUR);
    }
}

void newDataCallback(const bme68xData data, const bsecOutputs outputs, Bsec2 bsec)
{
    if (!outputs.nOutputs)
    {
        return;
    }

    Serial.println("BSEC outputs:\n\ttimestamp = " + String((int) (outputs.output[0].time_stamp / INT64_C(1000000))));
    for (uint8_t i = 0; i < outputs.nOutputs; i++)
    {
        const bsecData output  = outputs.output[i];
        switch (output.sensor_id)
        {
            case BSEC_OUTPUT_IAQ:
                Serial.println("\tiaq = " + String(output.signal));
                Serial.println("\tiaq accuracy = " + String((int) output.accuracy));
                break;
            case BSEC_OUTPUT_RAW_TEMPERATURE:
                Serial.println("\ttemperature = " + String(output.signal));
                break;
            case BSEC_OUTPUT_RAW_PRESSURE:
                Serial.println("\tpressure = " + String(output.signal));
                break;
            case BSEC_OUTPUT_RAW_HUMIDITY:
                Serial.println("\thumidity = " + String(output.signal));
                break;
            case BSEC_OUTPUT_RAW_GAS:
                Serial.println("\tgas resistance = " + String(output.signal));
                break;
            case BSEC_OUTPUT_STABILIZATION_STATUS:
                Serial.println("\tstabilization status = " + String(output.signal));
                break;
            case BSEC_OUTPUT_RUN_IN_STATUS:
                Serial.println("\trun in status = " + String(output.signal));
                break;
            default:
                break;
        }
    }
}

void checkBsecStatus(Bsec2 bsec)
{
    if (bsec.status < BSEC_OK)
    {
        Serial.println("BSEC error code : " + String(bsec.status));
        errLeds(); /* Halt in case of failure */
    }
    else if (bsec.status > BSEC_OK)
    {
        Serial.println("BSEC warning code : " + String(bsec.status));
    }

    if (bsec.sensor.status < BME68X_OK)
    {
        Serial.println("BME68X error code : " + String(bsec.sensor.status));
        errLeds(); /* Halt in case of failure */
    }
    else if (bsec.sensor.status > BME68X_OK)
    {
        Serial.println("BME68X warning code : " + String(bsec.sensor.status));
    }
}

I cannot upload the full error message because there are too many characters. Here is the last part of the error message:

/Users/christoforospanteli/Documents/Arduino/libraries/Bosch_BSEC2_Library/src/bsec2.cpp:138: undefined reference to `bsec_sensor_control'
collect2: error: ld returned 1 exit status

Using library BSEC2 Software Library at version 1.1.2200 in folder: /Users/christoforospanteli/Documents/Arduino/libraries/Bosch_BSEC2_Library 
Using library Wire at version 2.0.0 in folder: /Users/christoforospanteli/Library/Arduino15/packages/esp32/hardware/esp32/2.0.0/libraries/Wire 
Using library SPI at version 2.0.0 in folder: /Users/christoforospanteli/Library/Arduino15/packages/esp32/hardware/esp32/2.0.0/libraries/SPI 
Using library BME68x Sensor library at version 1.1.40407 in folder: /Users/christoforospanteli/Documents/Arduino/libraries/BME68x_Sensor_library 
exit status 1

Compilation error: exit status 1

Thank you!

Did the example programs work?

In reference to the code posted in post#3, why does the OP put the instantaition so far down the list? Put the code near the top so ALL references to the envSensor are valid instead of being out of scope.

/* Create an object of the class Bsec2 */
Bsec2 envSensor;

?

On a ESP32 put the callback into IRAM

void IRAM_ATTR newDataCallback(const bme68xData data, const bsecOutputs outputs, Bsec2 bsec)
{

Serial.prints from the callback is not advised. Think of the callback as a ISR.

That should be near the top as well.

Dear Idahowalker,
Thanks for your reply.
The example sketch is what I am using. The basic example works for MRK WiFi 1010 but doesn't compile for esp32.

The code in post#3 is unchanged from the example from BSEC2 library. I am not sure if I even need BSEC2 since I only want raw data from the BME688 sensor. When I try to upload the BME68x parallel_mode.ino example, I get the following error from both MKR and esp32:

> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
> configsip: 188777542, SPIWP:0xee
> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
> mode:DIO, clock div:1
> load:0x3fff0030,len:1100
> ho 0 tail 12 room 4
> load:0x40078000,len:12308
> load:0x40080400,len:3076
> entry 0x400805ec
> Sensor error:Communication failure

I am using I2C protocol. SDA pin 21 and SCL pin 22 on esp32 pico d4 kit. I also modify the lines:

SPI.begin();

To

Wire.begin();

and

bme.begin(PIN_CS, SPI);

To

bme.begin(PIN_CS, Wire);

I was hoping this would make this work.

Many thanks!

I2C scanner

What did the I2C scanner report?

Hello,

I am trying to use the BME688 sensor from Bosch to detect VOCs. I am using the Sparkfun 19096 breakout board, Arduino IDE 1.8.19 and SV-Zanshin library, as recommended. I can read the Temperature, Humidity and Pressure data on the serial monitor but the altitude and gas resistance data are wrong. They show negative numbers (-41.73 and -999.35 for alt and gas, respectively), which I assume it’s variable overflow, and the values don’t change. I can fix the issue with the negative number by modifying the data types and scaling the reading down. However, the fact that the sensor gas resistance reading doesn’t change at all even after 48 hours burn in and exposure to acetone and IPA is worrisome. Here is the full list of the specifications I am using.

System:

macOS Monterey 12.6.2

Arduino IDE version 1.8.19

Sensor:

Bosch BME688

Breakout board:

Sparkfun 19096

Libraries:

Adafruit - github > adafruit/Adafruit_BME680 - This doesn’t find the sensor.

SV-Zanshin - github > Zanduino/BME680

Bosch - github > BoschSensortec/Bosch-BME68x-Library - This doesn’t find the sensor.

Development board:

esp32 pico d4 kit

esp32 WROOM32

Tutorial followed:

Sparkfun - learn.sparkfun > tutorials/sparkfun-environmental-sensor-breakout---bme68x-qwiic-hookup-guide

Random Tutorials - randomnerdtutorials > esp32-bme680-sensor-arduino - This doesn’t find the sensor.

Arduino Example used:

BME688 I2C demo

Questions:

  1. How to interpret gas sensor raw data? What does it measure (resistance in Ohms)?

  2. Can I use the Sparkfun 19096 on Arduino UNO with 5V supply and logic?

  3. Why does the gas sensor reading not change? Is it incompatibility with the Arduino IDE version, development board or communication protocol?

Apologies if this was answered already.

Many thanks! Greatly appreciated!

  1. From their example sketch
  Serial.print("Gas = ");
  Serial.print(bme.gas_resistance / 1000.0);
  Serial.println(" KOhms");
  1. Page 7
    https://media.digikey.com/pdf/Data%20Sheets/Sparkfun%20PDFs/Environmental_Sensor%20_Breakout_BME68x_Qwiic_Hookup_Guide_Web.pdf

  2. The libraries should have examples (FILE >> EXAMPLES >> (Adafruit or Bosch)BME???

Hello xfpd,

Thank you for the reply!

1 and 2 got it! Thanks a lot!

Now, for 3: Yes, there are examples and I am using the I2C Demo from the SV-Zanshin library (attached), the only one that gives me some data, so far. I tried the Adafruit and BOSCH but they can't find the sensor. I guess this is because the Adafruit and BOSCH libraries use SPI communication and I need to either change the code for I2C or change the Sparkfun board for SPI.
What do you think?

Many thanks!

Your two or more topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you also take a few moments to Learn How To Use The Forum.

It will help you get the best out of the forum in the future.

  • Your OS and version can be valuable information, please include it along with extra security you are using.

  • Always list the version of the IDE you are using and the board version if applicable.

  • Use quote or add error messages as an attachment NOT a picture.

  • How to insert an image into your post. ( Thanks @sterretje )

  • Add your sketch where applicable but please use CODE TAGS ( </> )

  • Add a SCHEMATIC were needed even if it is hand drawn

  • Add working links to any specific hardware as needed (NOT links to similar items)

  • Remember that the people trying to help cannot see your problem so give as much information as you can

COMMON ISSUES

  • Ensure you have FULLY inserted the USB cables.

  • Check you have a COMMON GROUND where required. ( Thanks @Perry)

  • Where possible use USB 2.0 ports or a USB 2.0 POWERED HUB to rule out USB 3.0 issues.

  • Try other computers where possible.

  • Try other USB leads where possible.

  • You may not have the correct driver installed. CH340/341 or CP2102 or FT232 VCP Drivers - FTDI

  • There may be a problem with the board check or remove your wiring first.

  • Remove any items connected to pins 0 and 1.

COMPUTER RELATED

  • Close any other serial programs before opening the IDE.

  • Ensure you turn off any additional security / antivirus just to test.

  • There may be a problem with the PC try RESTARTING it.

  • You may be selecting the wrong COM port.

  • Avoid cloud/network based installations where possible OR ensure your Network/Cloud software is RUNNING.

  • Clear your browsers CACHE.

  • Close the IDE before using any other serial programs.

  • Preferably install IDE’s as ADMINISTRATOR or your OS equivalent

ARDUINO SPECIFIC BOARDS

  • CH340/341 based clones do not report useful information to the “get board info” button.

  • NANO (Old Types) some require you to use the OLD BOOTLOADER option.

  • NANO (ALL Types) See the specific sections lower in the forum.

  • NANO (NEW Types) Install your board CORE’s.

  • Unless using EXTERNAL PROGRAMMERS please leave the IDE selection at default “AVRISP mkII”.

  • Boards using a MICRO usb connector need a cable that is both DATA and CHARGE. Many are CHARGE ONLY.

CREATE editor install locations.

  • On macOs ~/Applications/ArduinoCreateAgent-1.1/ArduinoCreateAgent.app/Contents/MacOS/config.ini

  • On Linux ~/ArduinoCreateAgent-1.1/config.ini

  • On Windows C:\Users[your user]\AppData\Roaming\ArduinoCreateAgent-1.1

Performing the above actions may help resolve your problem without further help.

Language problem ?

Try a language closer to your native language:

Thanks to all those who helped and added to this list.

Dear Idahowalker,
Thanks for the tip!
Here is what the I2C scanner report said:

> --- Scan started ---
> I2C device found at address 0x60  !
> I2C device found at address 0x6B  !
> I2C device found at address 0x76  !
> --- Scan finished ---

Apologies! This is my first time using the Arduino forum. I thought by asking more specific questions on different topics would be easier.

Which device are you referring to? The BME688 sensor breakout or the Arduino MRK or esp32 boards?

Many thanks!

Dear Ballscrwebob,

I apologies for this! This is my first time using the Arduino forum. I thought by asking more specific questions on different topics would be easier.

Thanks!

Cool it looks like the device is being detected. What happened when you tried to use the sample code, did that work?

As note that the I2C scanner finds your device means the device is communicating.

So, I compiled and uploaded the check.ino example but the Serial monitor returned nothing.

The Execute.ino example gives me this error when compiling:

error: uninitialized const 'address' 

and the code it is referring to is:

const byte address;

I think the address should be what the scanner showed, right? So, I replaced "address" with "0x76" but it gives me this error:

error: expected unqualified-id before numeric constant
 const byte 0x76;

Any ideas?

Post images of your project. Post a schematic.

Disconnect everything else from the MCU, except for the BME688. Run the scanner. Note the address. Look up on the internet the I2C address range of the BME688, does your address match? Get the example working with just the BME connected to the MCU.

Do you need pull up resistors?

Quite trying to edit libraries.

Go to the BME git hub site that makes the library you are using and ask them why it don't work.

Thanks a lot for the tips!
I attach a PDF with the schematics and photo of my circuit. The only thing connected to the MKR is the BME688 board.
The default address of the BME688 board is 0x76.
BME688_circuit.pdf (3.2 MB)

I will ask them on GitHub as well.