Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    ESP32 C3 BME680 BSCE2 Error Code -2

    ESP32 C3 BME680 BSCE2 Error Code -2

    ptrkx
    New Poster

    Hey everyone i have problems getting a bme680 to run on an esp32 c3. if i try the example code of the bsec2 library i get the error bme680 error code -2 in the output of the serial monitor...i use the i2c communication via sda and scl in the arduino ide

    I also tried to change: 

    BME68X_I2C_ADDR_LOW

    to 0x77 but sadly same output. error code -2

    Sample Code:

     

    /**
     * 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_ULP))
        {
            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));
        }
    }

     

     

     

     

     

    2 REPLIES 2

    BSTRobin
    Community Moderator
    Community Moderator

    Hi ptrkx,

    1.Ensure your BME680 hardware was correct, and check if BME680 pin 5(SDO) was connected to GND as you set I2C address to BME68X_I2C_ADDR_LOW;
    2. Could we know which BSEC version and example code you refer to?

    Hey i am using BSEC2 Library: https://github.com/boschsensortec/Bosch-BSEC2-Library/tree/master/examples/generic_examples/basic

    on Arduino IDE. 

    Hardware ESP32 C3 with BME680 via I2C 

    No problem with compiling, but seriell output is error code: -2

    Same problem when i connect SDO to GND

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist