From 41f76cd1ef86392d59a2bfeb7252da682a211e1d Mon Sep 17 00:00:00 2001 From: Gregor K Date: Mon, 6 Feb 2017 17:11:32 +0100 Subject: [PATCH 1/6] Invalid version number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed version number to avoid Arduino complaining about “Invalid version found: 2.1.02” --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 14a29c5..fff7cd4 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=BME280 -version=2.1.02 +version=2.1.2 author=Tyler Glenn maintainer=Tyler Glenn sentence=Provides a library for reading and interpreting Bosch BME280 environmental sensor data over I2C and SPI. From 28bb4689a01cfa08de28c4bf2a74963e2004d5ee Mon Sep 17 00:00:00 2001 From: Gregor K Date: Mon, 6 Feb 2017 17:19:11 +0100 Subject: [PATCH 2/6] Integer overflow warning Compiler warning: integer overflow in expression. Changed 100*1000 to 100000.0 --- src/BME280.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BME280.cpp b/src/BME280.cpp index 501abff..007a8d1 100644 --- a/src/BME280.cpp +++ b/src/BME280.cpp @@ -113,7 +113,7 @@ float BME280::CalculatePressure(int32_t raw, int32_t t_fine, uint8_t unit){ final /= 101324.99766353; /* final pa * 1 atm/101324.99766353Pa */ break; case 0x4: /* bar */ - final /= 100*1000; /* final pa * 1 bar/100kPa */ + final /= 100000.0; /* final pa * 1 bar/100kPa */ break; case 0x5: /* torr */ final /= 133.32236534674; /* final pa * 1 torr/133.32236534674Pa */ From c53a08fcd027b48d859e69e592353277f740889e Mon Sep 17 00:00:00 2001 From: Gregor K Date: Mon, 6 Feb 2017 17:44:56 +0100 Subject: [PATCH 3/6] Change default constructor mode value Changed default mode value to 0x1 (forced mode), to be consistent with the comments in Arduino source file examples. --- src/BME280.h | 4 ++-- src/BME280I2C.h | 4 ++-- src/BME280Spi.h | 4 ++-- src/BME280SpiSw.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/BME280.h b/src/BME280.h index 4fc52cd..1f10069 100644 --- a/src/BME280.h +++ b/src/BME280.h @@ -82,8 +82,8 @@ class BME280{ public: /* ==== Constructor used to create the class. All parameters have default values. ==== */ - BME280(uint8_t tosr = 0x1, uint8_t hosr = 0x1, uint8_t posr = 0x1, uint8_t mode = 0x3, - uint8_t st = 0x5, uint8_t filter = 0x0, bool spiEnable = false); // Oversampling = 1, mode = normal, standby time = 1000ms, filter = none. + BME280(uint8_t tosr = 0x1, uint8_t hosr = 0x1, uint8_t posr = 0x1, uint8_t mode = 0x1, + uint8_t st = 0x5, uint8_t filter = 0x0, bool spiEnable = false); // Oversampling = 1, mode = forced, standby time = 1000ms, filter = none. /* ==== Method used at start up to initialize the class. ==== */ virtual bool begin()=0; diff --git a/src/BME280I2C.h b/src/BME280I2C.h index b63305a..0f318ce 100644 --- a/src/BME280I2C.h +++ b/src/BME280I2C.h @@ -54,9 +54,9 @@ class BME280I2C: public BME280{ public: /* ==== Constructor used to create the class. All parameters have default values. ==== */ - BME280I2C(uint8_t tosr = 0x1, uint8_t hosr = 0x1, uint8_t posr = 0x1, uint8_t mode = 0x3, + BME280I2C(uint8_t tosr = 0x1, uint8_t hosr = 0x1, uint8_t posr = 0x1, uint8_t mode = 0x1, uint8_t st = 0x5, uint8_t filter = 0x0, bool spiEnable = false, - uint8_t bme_280_addr = 0x76); // Oversampling = 1, mode = normal, standby time = 1000ms, filter = none. + uint8_t bme_280_addr = 0x76); // Oversampling = 1, mode = forced, standby time = 1000ms, filter = none. /* ==== Method used at start up to initialize the class. Starts the I2C interface. ==== */ virtual bool begin(); diff --git a/src/BME280Spi.h b/src/BME280Spi.h index 15ef335..bf1f111 100644 --- a/src/BME280Spi.h +++ b/src/BME280Spi.h @@ -60,8 +60,8 @@ class BME280Spi: public BME280{ public: /* ==== Constructor used to create the class. All parameters have default values. ==== */ - BME280Spi(uint8_t spiCsPin, uint8_t tosr = 0x1, uint8_t hosr = 0x1, uint8_t posr = 0x1, uint8_t mode = 0x3, - uint8_t st = 0x5, uint8_t filter = 0x0); // Oversampling = 1, mode = normal, standby time = 1000ms, filter = none. + BME280Spi(uint8_t spiCsPin, uint8_t tosr = 0x1, uint8_t hosr = 0x1, uint8_t posr = 0x1, uint8_t mode = 0x1, + uint8_t st = 0x5, uint8_t filter = 0x0); // Oversampling = 1, mode = forced, standby time = 1000ms, filter = none. /* ==== Method used at start up to initialize the class. Starts the I2C interface. ==== */ virtual bool begin(); diff --git a/src/BME280SpiSw.h b/src/BME280SpiSw.h index a784345..90f170d 100644 --- a/src/BME280SpiSw.h +++ b/src/BME280SpiSw.h @@ -67,7 +67,7 @@ class BME280SpiSw: public BME280{ public: /* ==== Constructor for software spi ==== */ BME280SpiSw(uint8_t spiCsPin, uint8_t spiMosiPin, uint8_t spiMisoPin, uint8_t spiSckPin, uint8_t tosr = 0x1, - uint8_t hosr = 0x1, uint8_t posr = 0x1, uint8_t mode = 0x3, uint8_t st = 0x5, uint8_t filter = 0x0); // Oversampling = 1, mode = normal, standby time = 1000ms, filter = none. + uint8_t hosr = 0x1, uint8_t posr = 0x1, uint8_t mode = 0x1, uint8_t st = 0x5, uint8_t filter = 0x0); // Oversampling = 1, mode = forced, standby time = 1000ms, filter = none. /* ==== Method used at start up to initialize the class. Starts the I2C interface. ==== */ virtual bool begin(); From 4113493209b8aba516bb4000e18ad1129b7007c5 Mon Sep 17 00:00:00 2001 From: Gregor K Date: Mon, 6 Feb 2017 17:48:28 +0100 Subject: [PATCH 4/6] Corrected example param values The example BME280I2C constructor values were wrong, correct order is tosr, hosr, posr and not posr, tosr, hosr. Also corrected the mode value to 3 were normal mode should be selected (according to comments). --- examples/BME280_Modes/BME280_Modes.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/BME280_Modes/BME280_Modes.ino b/examples/BME280_Modes/BME280_Modes.ino index 98ba689..7bc9398 100644 --- a/examples/BME280_Modes/BME280_Modes.ino +++ b/examples/BME280_Modes/BME280_Modes.ino @@ -43,13 +43,13 @@ BME280I2C bme; // Default : forced mode, standby time = 1000 // RMS Noise = 3.3 Pa/30 cm, 0.07 %RH // Data Output Rate 1/60 Hz -//BME280I2C bme(0, 1, 1); // Humidity Sensing : forced mode, 1 sample/second +//BME280I2C bme(1, 1, 0); // Humidity Sensing : forced mode, 1 sample/second // pressure ×0, temperature ×1, humidity ×1, filter off // Current Consumption = 2.9 μA // RMS Noise = 0.07 %RH // Data Output Rate = 1 Hz -//BME280I2C bme(5, 2, 1, 1, 0, 4); // Indoor Navigation : normal mode, standby time = 0.5ms +//BME280I2C bme(2, 1, 5, 3, 0, 4); // Indoor Navigation : normal mode, standby time = 0.5ms // pressure ×16, temperature ×2, humidity ×1, filter = x16 // Current Consumption = 633 μA // RMS Noise = 0.2 Pa/1.7 cm @@ -58,7 +58,7 @@ BME280I2C bme; // Default : forced mode, standby time = 1000 // Response Time (75%) = 0.9 s -//BME280I2C bme(3, 1, 0, 1, 0, 4); // Gaming : normal mode, standby time = 0.5ms +//BME280I2C bme(1, 0, 4, 3, 0, 4); // Gaming : normal mode, standby time = 0.5ms // pressure ×4, temperature ×1, humidity ×0, filter = x16 // Current Consumption = 581 μA // RMS Noise = 0.3 Pa/2.5 cm From e7af7c4ff41495350fb001649e08fe824ebc705c Mon Sep 17 00:00:00 2001 From: Gregor K Date: Mon, 6 Feb 2017 19:38:33 +0100 Subject: [PATCH 5/6] Running in forced mode Modified code so that when in forced mode the BME280 goes from sleep to forced mode just before reading the data. Original code had a bug, where the sensor was left in sleep mode and it was just reading the old stored measurements in the registers. --- src/BME280I2C.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/BME280I2C.cpp b/src/BME280I2C.cpp index 0715918..032cbc8 100644 --- a/src/BME280I2C.cpp +++ b/src/BME280I2C.cpp @@ -96,6 +96,7 @@ bool BME280I2C::ReadTrim() dig[ord++] = Wire.read(); } +#ifdef DEBUG_ON Serial.print("Dig: "); for(int i = 0; i < 32; ++i) { @@ -103,7 +104,7 @@ bool BME280I2C::ReadTrim() Serial.print(" "); } Serial.println(); - +#endif return ord == 32; } @@ -111,6 +112,10 @@ bool BME280I2C::ReadTrim() bool BME280I2C::ReadData(int32_t data[8]){ uint8_t ord = 0; + // for forced mode we need to write the mode to BME280 register before reading + if ( (mode == 0x01) || (mode == 0x10) ) + setMode(mode); + // Registers are in order. So we can start at the pressure register and read 8 bytes. Wire.beginTransmission(bme_280_addr); Wire.write(PRESS_ADDR); @@ -121,6 +126,7 @@ bool BME280I2C::ReadData(int32_t data[8]){ data[ord++] = Wire.read(); } +#ifdef DEBUG_ON Serial.print("Data: "); for(int i = 0; i < 8; ++i) { @@ -128,6 +134,7 @@ bool BME280I2C::ReadData(int32_t data[8]){ Serial.print(" "); } Serial.println(); +#endif return ord == 8; } From f6db78e2e56ecd9004b6107a0c808796fd859f2d Mon Sep 17 00:00:00 2001 From: Gregor K Date: Mon, 6 Feb 2017 22:39:41 +0100 Subject: [PATCH 6/6] Corrected typo Changed the BME280::press method to BME280::pres to be consistent with the README.md --- src/BME280.cpp | 2 +- src/BME280.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BME280.cpp b/src/BME280.cpp index 007a8d1..671e739 100644 --- a/src/BME280.cpp +++ b/src/BME280.cpp @@ -156,7 +156,7 @@ float BME280::temp(bool celsius){ return CalculateTemperature(rawTemp, t_fine, celsius); } -float BME280::press(uint8_t unit){ +float BME280::pres(uint8_t unit){ int32_t data[8]; int32_t t_fine; if(!ReadData(data)){ return NAN; } diff --git a/src/BME280.h b/src/BME280.h index 1f10069..ef6a37f 100644 --- a/src/BME280.h +++ b/src/BME280.h @@ -94,7 +94,7 @@ class BME280{ float temp(bool celsius = true); /* ==== Read the pressure from the BME280 and return a float with the specified unit. ==== */ - float press(uint8_t unit = 0x0); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi + float pres(uint8_t unit = 0x0); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi /* ==== Read the humidity from the BME280 and return a percentage as a float. ==== */ float hum();