Skip to content

Commit 12a6729

Browse files
authored
Merge pull request #85 from AgentZombie/temp-adjust-84
Provide temperature compensation #84
2 parents 6508738 + 25f8d5e commit 12a6729

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Adafruit_BME280.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ float Adafruit_BME280::readTemperature(void) {
419419
((int32_t)_bme280_calib.dig_T3)) >>
420420
14;
421421

422-
t_fine = var1 + var2;
422+
t_fine = var1 + var2 + t_fine_adjust;
423423

424424
float T = (t_fine * 5 + 128) >> 8;
425425
return T / 100;
@@ -540,6 +540,24 @@ float Adafruit_BME280::seaLevelForAltitude(float altitude, float atmospheric) {
540540
*/
541541
uint32_t Adafruit_BME280::sensorID(void) { return _sensorID; }
542542

543+
/*!
544+
* Returns the current temperature compensation value in degrees Celcius
545+
* @returns the current temperature compensation value in degrees Celcius
546+
*/
547+
float Adafruit_BME280::getTemperatureCompensation(void) {
548+
return float(((t_fine_adjust * 5) >> 8) / 100);
549+
};
550+
551+
/*!
552+
* Sets a value to be added to each temperature reading. This adjusted
553+
* temperature is used in pressure and humidity readings.
554+
* @param adjustment Value to be added to each tempature reading in Celcius
555+
*/
556+
void Adafruit_BME280::setTemperatureCompensation(float adjustment) {
557+
// convert the value in C into and adjustment to t_fine
558+
t_fine_adjust = ((int32_t(adjustment * 100) << 8)) / 5;
559+
};
560+
543561
/*!
544562
@brief Gets an Adafruit Unified Sensor object for the temp sensor component
545563
@return Adafruit_Sensor pointer to temperature sensor

Adafruit_BME280.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ class Adafruit_BME280 {
234234
float seaLevelForAltitude(float altitude, float pressure);
235235
uint32_t sensorID(void);
236236

237+
float getTemperatureCompensation(void);
238+
void setTemperatureCompensation(float);
239+
237240
Adafruit_Sensor *getTemperatureSensor(void);
238241
Adafruit_Sensor *getPressureSensor(void);
239242
Adafruit_Sensor *getHumiditySensor(void);
@@ -274,6 +277,9 @@ class Adafruit_BME280 {
274277
int8_t _miso; //!< for the SPI interface
275278
int8_t _sck; //!< for the SPI interface
276279

280+
int32_t t_fine_adjust = 0; //!< add to compensate temp readings and in turn
281+
//!< to pressure and humidity readings
282+
277283
bme280_calib_data _bme280_calib; //!< here calibration data is stored
278284

279285
/**************************************************************************/

0 commit comments

Comments
 (0)