From 7df979ed2503e813a1d885153d36db837f57dd8f Mon Sep 17 00:00:00 2001 From: arendst Date: Sun, 3 Dec 2017 16:17:47 +0100 Subject: [PATCH] Fix BME280 calculation (#1051) * Fix BME280 calculation (#1051) --- sonoff/_releasenotes.ino | 3 ++- sonoff/sonoff.ino | 8 -------- sonoff/xsns_09_bmp.ino | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 348368dd6..85ba74766 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,9 +1,10 @@ /* 5.10.0a * Add (experimental) support for sensor SHT3x * Add (experimental) support for iTead SI7021 temperature and humidity sensor (#735) + * Fix BME280 calculation (#1051) * Change ADS1115 default voltage range from +/-2V to +/-6V (#1289) * Add multipress support and more user configurable options to Sonoff Dual R2 (#1291) - * Fix missed learned key if learned data contains 0x55 (End of Transmission) flag (#1095, #1294) + * Fix Sonoff Bridge missed learned key if learned data contains 0x55 (End of Transmission) flag (#1095, #1294) * * 5.10.0 20171201 * Upgrade library ArduinoJson to 5.11.2 diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index d7af116d4..0d1a7e377 100644 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -2644,14 +2644,6 @@ void setup() Serial.println(); seriallog_level = LOG_LEVEL_INFO; // Allow specific serial messages until config loaded -/* - snprintf_P(version, sizeof(version), PSTR("%d.%d.%d"), VERSION >> 24 & 0xff, VERSION >> 16 & 0xff, VERSION >> 8 & 0xff); - if (VERSION & 0x1f) { - idx = strlen(version); - version[idx] = 96 + (VERSION & 0x1f); - version[idx +1] = 0; - } -*/ SettingsLoad(); SettingsDelta(); diff --git a/sonoff/xsns_09_bmp.ino b/sonoff/xsns_09_bmp.ino index 4a2cafc53..21679e50e 100644 --- a/sonoff/xsns_09_bmp.ino +++ b/sonoff/xsns_09_bmp.ino @@ -172,6 +172,7 @@ double Bmp180ReadPressure() #define BME280_REGISTER_CONTROLHUMID 0xF2 #define BME280_REGISTER_CONTROL 0xF4 +#define BME280_REGISTER_CONFIG 0xF5 #define BME280_REGISTER_PRESSUREDATA 0xF7 #define BME280_REGISTER_TEMPDATA 0xFA #define BME280_REGISTER_HUMIDDATA 0xFD @@ -235,6 +236,7 @@ boolean Bmx280Calibrate() Bme280CalibrationData.dig_P7 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P7); Bme280CalibrationData.dig_P8 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P8); Bme280CalibrationData.dig_P9 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P9); +/* if (BME280_CHIPID == bmp_type) { Bme280CalibrationData.dig_H1 = I2cRead8(bmp_address, BME280_REGISTER_DIG_H1); Bme280CalibrationData.dig_H2 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_H2); @@ -247,6 +249,23 @@ boolean Bmx280Calibrate() I2cWrite8(bmp_address, BME280_REGISTER_CONTROLHUMID, 0x05); // 16x oversampling (Adafruit) } I2cWrite8(bmp_address, BME280_REGISTER_CONTROL, 0xB7); // 16x oversampling, normal mode (Adafruit) +*/ + if (BME280_CHIPID == bmp_type) { // #1051 + Bme280CalibrationData.dig_H1 = I2cRead8(bmp_address, BME280_REGISTER_DIG_H1); + Bme280CalibrationData.dig_H2 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_H2); + Bme280CalibrationData.dig_H3 = I2cRead8(bmp_address, BME280_REGISTER_DIG_H3); + Bme280CalibrationData.dig_H4 = (I2cRead8(bmp_address, BME280_REGISTER_DIG_H4) << 4) | (I2cRead8(bmp_address, BME280_REGISTER_DIG_H4 + 1) & 0xF); + Bme280CalibrationData.dig_H5 = (I2cRead8(bmp_address, BME280_REGISTER_DIG_H5 + 1) << 4) | (I2cRead8(bmp_address, BME280_REGISTER_DIG_H5) >> 4); + Bme280CalibrationData.dig_H6 = (int8_t)I2cRead8(bmp_address, BME280_REGISTER_DIG_H6); + + I2cWrite8(bmp_address, BME280_REGISTER_CONTROL, 0x00); // sleep mode since writes to config can be ignored in normal mode (Datasheet 5.4.5/6 page 27) + // Set before CONTROL_meas (DS 5.4.3) + I2cWrite8(bmp_address, BME280_REGISTER_CONTROLHUMID, 0x01); // 1x oversampling + I2cWrite8(bmp_address, BME280_REGISTER_CONFIG, 0xA0); // 1sec standby between measurements (to limit self heating), IIR filter off + I2cWrite8(bmp_address, BME280_REGISTER_CONTROL, 0x27); // 1x oversampling, normal mode + } else { + I2cWrite8(bmp_address, BME280_REGISTER_CONTROL, 0xB7); // 16x oversampling, normal mode (Adafruit) + } return true; }