STM32 and BME280. Not work humidity part sensor.

Thread Starter

Oleg Demkiv

Joined Feb 12, 2019
5
I get data from BME280.
Temperature and pressure is correct, but humidity data is not correct.

Reading calibrate coefficients..

dig_H1=(unsigned short)buf_calibration_data[24];
STATUS_BME280=HAL_I2C_Mem_Read(&hi2c1, BME280_ID<<1,(uint16_t)BME280_CALIB_26, (uint16_t) 1, buf_calibration_data, (uint16_t)10, 1000);
dig_H2=(signed short)buf_calibration_data[1]<<8|(signed short)buf_calibration_data[0];
dig_H3=(unsigned short)buf_calibration_data[2];
dig_H4=(signed short)buf_calibration_data[4]<<3|(signed short)buf_calibration_data[5];
dig_H5=(signed short)buf_calibration_data[6]<<11|(signed short)buf_calibration_data[7];
dig_H6=(signed short)buf_calibration_data[8];


Screenshot_6.png
Screenshot_7.png
alculation function I get from datasheet BME280.
uint32_t calulete_humidity(uint32_t adc_H)
{
double var_H;
var_H = (((double)t_fine)-76800.0);
var_H = (adc_H-(((double)dig_H4) * 64.0 + ((double)dig_H5) / 16384.0 * var_H)) *
(((double)dig_H2) / 65536.0 * (1.0 + ((double)dig_H6) / 67108864.0 * var_H *
(1.0 + ((double)dig_H3) / 67108864.0 * var_H)));
var_H = var_H * (1.0-((double)dig_H1) * var_H / 524288.0);
if (var_H > 100.0)
var_H = 100.0;
else if (var_H < 0.0)
var_H = 0.0;

sprintf(str_BME280,"HUMIDITY: %d________\r\n", (int)var_H); // convert in str
size=sizeof(str_BME280);
HAL_UART_Transmit(&huart1 , (uint8_t *)str_BME280, size, 0xFFF);

return var_H;
}
I thing ADC value humidity is wrong..
somebody have adc_h value???
 

wayneh

Joined Sep 9, 2010
17,496
I get data from BME280.
Temperature and pressure is correct, but humidity data is not correct.

Reading calibrate coefficients..

dig_H1=(unsigned short)buf_calibration_data[24];
STATUS_BME280=HAL_I2C_Mem_Read(&hi2c1, BME280_ID<<1,(uint16_t)BME280_CALIB_26, (uint16_t) 1, buf_calibration_data, (uint16_t)10, 1000);
dig_H2=(signed short)buf_calibration_data[1]<<8|(signed short)buf_calibration_data[0];
dig_H3=(unsigned short)buf_calibration_data[2];
dig_H4=(signed short)buf_calibration_data[4]<<3|(signed short)buf_calibration_data[5];
dig_H5=(signed short)buf_calibration_data[6]<<11|(signed short)buf_calibration_data[7];
dig_H6=(signed short)buf_calibration_data[8];


View attachment 170050
View attachment 170052
alculation function I get from datasheet BME280.
uint32_t calulete_humidity(uint32_t adc_H)
{
double var_H;
var_H = (((double)t_fine)-76800.0);
var_H = (adc_H-(((double)dig_H4) * 64.0 + ((double)dig_H5) / 16384.0 * var_H)) *
(((double)dig_H2) / 65536.0 * (1.0 + ((double)dig_H6) / 67108864.0 * var_H *
(1.0 + ((double)dig_H3) / 67108864.0 * var_H)));
var_H = var_H * (1.0-((double)dig_H1) * var_H / 524288.0);
if (var_H > 100.0)
var_H = 100.0;
else if (var_H < 0.0)
var_H = 0.0;

sprintf(str_BME280,"HUMIDITY: %d________\r\n", (int)var_H); // convert in str
size=sizeof(str_BME280);
HAL_UART_Transmit(&huart1 , (uint8_t *)str_BME280, size, 0xFFF);

return var_H;
}
I thing ADC value humidity is wrong..
somebody have adc_h value???
Isn’t adc_H the value from the sensor? It looks like a messy calculation is applied to convert from whatever is actually measured into %RH. I’d check it by hand to see what it’s doing.
 

Thread Starter

Oleg Demkiv

Joined Feb 12, 2019
5
Who can write real adc_H value ? I want check my calculation function. I think, my adc_H is less then we need(see screnshout)
 

jjw

Joined Dec 24, 2013
823
Show the code to get adc_H.
In the screen capture you have:
if var_H = - 24.99...
This must be wrong.
 
Who can write real adc_H value ? I want check my calculation function. I think, my adc_H is less then we need.
Rather than repeating the same text in your posts, why don't you go through your code line by line and compare it to the code that is available from the sensor manufacturer with the link already provided to you https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c

For example, once you have the raw data, do your calculations mirror those for the compensated values? Did you look at the code and datasheet regarding reading the raw data and compensation?

Alternatively, I would answer your repetitive question with, Yes, I can, but I'm not going to do it for you, sorry I can't be of more help.

C:
* @brief This internal API is used to compensate the raw humidity data and
* return the compensated humidity data in double data type.
*/
static double compensate_humidity(const struct bme280_uncomp_data *uncomp_data,
const struct bme280_calib_data *calib_data)
{
double humidity;
double humidity_min = 0.0;
double humidity_max = 100.0;
double var1;
double var2;
double var3;
double var4;
double var5;
double var6;
var1 = ((double)calib_data->t_fine) - 76800.0;
var2 = (((double)calib_data->dig_H4) * 64.0 + (((double)calib_data->dig_H5) / 16384.0) * var1);
var3 = uncomp_data->humidity - var2;
var4 = ((double)calib_data->dig_H2) / 65536.0;
var5 = (1.0 + (((double)calib_data->dig_H3) / 67108864.0) * var1);
var6 = 1.0 + (((double)calib_data->dig_H6) / 67108864.0) * var1 * var5;
var6 = var3 * var4 * (var5 * var6);
humidity = var6 * (1.0 - ((double)calib_data->dig_H1) * var6 / 524288.0);
if (humidity > humidity_max)
humidity = humidity_max;
else if (humidity < humidity_min)
humidity = humidity_min;
return humidity;
}
/*!
 
Top