Bosch Sensortec Community

    SOLVED

    BME280 reporting the same temperature of 22.1 degrees

    Highlighted
    New Poster

    BME280 reporting the same temperature of 22.1 degrees

    I have connected a BME280 sensor, but I get a constant value for temperature when requested. It reports a value of 22.1,

    I'm developing my code using ESP-IDF (using PlatformIO)

    I'm using teh Bosch BME280 drive (version 3.3.6). 

    It appears to connects without error and fetches the value of 22.1. I'm running the read inside a while loop, pausing one second between the setting of forced mode and the reading of the sensor registers. The read call back is executed three times; 1 byte, 1 byte then 8 bytes.

    Would posting the raw, uncomensated register values help?

    Does the value of 22.1 have any significance? 

     

    Tags (1)
    4 REPLIES 4
    Community Moderator

    Re: BME280 reporting the same temperature of 22.1 degrees

    Can you confirm that the init funtion (bme280_init()) is called and returns without any error/warning? If so, could you please share a snippet of your code including initialization, configuration of the sensor and data read-out?

    To verify your raw data and compensation formulas, you could use the spreadsheet shared here, although that should typically not be the case if using the official sensor API.

    Highlighted
    New Poster

    Re: BME280 reporting the same temperature of 22.1 degrees

    I grabbed the calibration data and uncompensated values from my code, whilst it was running and fed them into the spreadsheet. The temp of 22.1 matches, so the values it's reading do tally up.

    All calls to the bme280 library return a success result.

    I get a value of 524288 from the uncompensated temperature registers

    I get calibration values of  28462 26902 50 for T1, T2, T3

    The library then reports 2210 as the temperature, which corresponds to the spreadsheet you recommended.

    The BME280_I2C_bus_write and BME280_I2C_bus_read function pointers are invoked as expected (from my understanding of the I2C protocol.

    What am I missing?

    My code is like this:

    esp_err_t i2c_init()
    {
    i2c_config_t conf;
     
    conf.mode = I2C_MODE_MASTER;
    conf.sda_io_num = GPIO_NUM_21;
    conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
    conf.scl_io_num = GPIO_NUM_22;
    conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
    conf.master.clk_speed = 100000;

    i2c_param_config(I2C_NUM_0, &conf);
     
    return i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
    }
     
     

    void app_main() 

    {

    esp_err_t i2c_init_result = i2c_init();

    if(i2c_init_result != ESP_OK)
    {
    printf("Failed to initialize i2c");
    }

    struct bme280_dev bme280 = {
    .intf = BME280_SPI_INTF,
            .write = BME280_I2C_bus_write,
            .read = BME280_I2C_bus_read,
            .dev_id = BME280_I2C_ADDR_PRIM,
            .delay_ms = BME280_delay_msek
        };

    int8_t init_result = bme280_init(&bme280);

    if(init_result != BME280_OK)
    {
    printf("Init failed");
    }

    printf("Temperature Calibration (T1, T2, T3) %d %d %d\n", bme280.calib_data.dig_T1, bme280.calib_data.dig_T2, bme280.calib_data.dig_T3);

    bme280.settings.osr_h = BME280_OVERSAMPLING_1X;
    bme280.settings.osr_p = BME280_OVERSAMPLING_1X;
    bme280.settings.osr_t = BME280_OVERSAMPLING_1X;
    bme280.settings.filter = BME280_FILTER_COEFF_OFF;

    uint8_t settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL;

    int8_t settings_result = bme280_set_sensor_settings(settings_sel, &bme280);

    if(settings_result != BME280_OK)
    {
    printf("Settings failed");
    }

    while(1) {

    int8_t sensor_mode_result = bme280_set_sensor_mode(BME280_FORCED_MODE, &bme280);

    if(sensor_mode_result != BME280_OK)
    {
    printf("Something went wrong");
    }

    bme280.delay_ms(1000);

    struct bme280_data comp_data;

    int8_t data_result = bme280_get_sensor_data(BME280_ALL, &comp_data, &bme280);

    if(data_result != BME280_OK)
    {
    printf("Something went wrong");
    }
     
    #ifdef BME280_FLOAT_ENABLE
    printf("%0.2f C, %0.2f hPa, %0.2f%%\r\n", comp_data.temperature, comp_data.pressure, comp_data.humidity);
    #else
    printf("%d, %d, %d\r\n", comp_data.temperature, comp_data.pressure, comp_data.humidity);
    #endif
    }
    }
    Highlighted
    Community Moderator

    Re: BME280 reporting the same temperature of 22.1 degrees

    A quick overview at the code provided doesn't show anything outstanding in the process. On the other hand something that could generate unexpected behavior could be that you configure the ".intf" element as "BME280_SPI_INTF", while your code indicates you are rather using an I2C interface. If so, you could try configuring it as "BME280_I2C_INTF". If needed and if you have an oscillosope/logic analyser available, you could also confirm that your I2C frames look as expected (in particular the reg_addr element).

    Highlighted
    New Poster

    Re: BME280 reporting the same temperature of 22.1 degrees

    Changing the interface type was the exact issue! I don't know how I missed that.

    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