Re: ESP8266 - BME280 Sensor Readings Wrong
Posted: Fri Mar 18, 2016 3:27 pm
The Sparkfun code is using a 64bit integer when reading temp. The ESP8266 is a 32-bit CPU core. There may be some weird rounding errors depending on how the Xtensa compiler is handling 64bit variables compared to the Atmel compiler.
Like I said, make sure the code is reading back the same raw values and calibration values for both the ESP8266 and the Arduino, then you can know for sure if it's the code that converts it to a degree C value.
Or just add this and run the function on both, if it doesn't return the same thing, then its the conversion code.
Like I said, make sure the code is reading back the same raw values and calibration values for both the ESP8266 and the Arduino, then you can know for sure if it's the code that converts it to a degree C value.
Or just add this and run the function on both, if it doesn't return the same thing, then its the conversion code.
Code: Select all
float BME280::readTest( void )
{
int32_t adc_T = 0x00AB1234; //fixed test value
//By datasheet, calibrate
int64_t var1, var2;
var1 = ((((adc_T>>3) - ((int32_t)calibration.dig_T1<<1))) * ((int32_t)calibration.dig_T2)) >> 11;
var2 = (((((adc_T>>4) - ((int32_t)calibration.dig_T1)) * ((adc_T>>4) - ((int32_t)calibration.dig_T1))) >> 12) *
((int32_t)calibration.dig_T3)) >> 14;
t_fine = var1 + var2;
float output = (t_fine * 5 + 128) >> 8;
output = output / 100;
return output;
}