From 874147604f9cb719966656f0f699faef39dbd2ef Mon Sep 17 00:00:00 2001 From: Rick Sellens Date: Fri, 26 Apr 2019 12:28:33 -0400 Subject: [PATCH 1/4] begin() fail gracefully try 0x76 address as well. record _sensorID --- Adafruit_BME280.cpp | 22 ++++++++++++++++++++-- Adafruit_BME280.h | 3 ++- examples/bme280test/bme280test.ino | 12 +++++++++--- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Adafruit_BME280.cpp b/Adafruit_BME280.cpp index b4cd953..b11338c 100644 --- a/Adafruit_BME280.cpp +++ b/Adafruit_BME280.cpp @@ -116,9 +116,15 @@ bool Adafruit_BME280::begin(uint8_t addr, TwoWire *theWire) /**************************************************************************/ bool Adafruit_BME280::begin(void) { + bool status = false; _i2caddr = BME280_ADDRESS; _wire = &Wire; - return init(); + status = init(); + if(!status){ + _i2caddr = BME280_ADDRESS_ALTERNATE; + status = init(); + } + return status; } /**************************************************************************/ @@ -148,7 +154,8 @@ bool Adafruit_BME280::init() } // check if sensor, i.e. the chip ID is correct - if (read8(BME280_REGISTER_CHIPID) != 0x60) + _sensorID = read8(BME280_REGISTER_CHIPID); + if (_sensorID != 0x60) return false; // reset the device using soft-reset @@ -612,3 +619,14 @@ float Adafruit_BME280::seaLevelForAltitude(float altitude, float atmospheric) return atmospheric / pow(1.0 - (altitude/44330.0), 5.255); } + +/**************************************************************************/ +/*! + Returns Sensor ID found by init() for diagnostics + @returns Sensor ID 0x60 for BME280, 0x56, 0x57, 0x58 BMP280 +*/ +/**************************************************************************/ +uint32_t Adafruit_BME280::sensorID(void) +{ + return _sensorID; +} diff --git a/Adafruit_BME280.h b/Adafruit_BME280.h index 4f8cd0f..fc4f5b5 100644 --- a/Adafruit_BME280.h +++ b/Adafruit_BME280.h @@ -35,6 +35,7 @@ */ /**************************************************************************/ #define BME280_ADDRESS (0x77) + #define BME280_ADDRESS_ALTERNATE (0x76) /*=========================================================================*/ /**************************************************************************/ @@ -218,7 +219,7 @@ class Adafruit_BME280 { float readAltitude(float seaLevel); float seaLevelForAltitude(float altitude, float pressure); - + uint32_t sensorID(void); protected: TwoWire *_wire; //!< pointer to a TwoWire object diff --git a/examples/bme280test/bme280test.ino b/examples/bme280test/bme280test.ino index e8b5563..f2eae8e 100644 --- a/examples/bme280test/bme280test.ino +++ b/examples/bme280test/bme280test.ino @@ -35,15 +35,21 @@ unsigned long delayTime; void setup() { Serial.begin(9600); + delay(4000); // time to get serial running Serial.println(F("BME280 test")); - bool status; + unsigned status; // default settings // (you can also pass in a Wire library object like &Wire2) status = bme.begin(); if (!status) { - Serial.println("Could not find a valid BME280 sensor, check wiring!"); + Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!"); + Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16); + Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n"); + Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n"); + Serial.print(" ID of 0x60 represents a BME 280.\n"); + Serial.print(" ID of 0x61 represents a BME 680.\n"); while (1); } @@ -79,4 +85,4 @@ void printValues() { Serial.println(" %"); Serial.println(); -} \ No newline at end of file +} From d698103a6ac643d22290d096f7096cf664e3b653 Mon Sep 17 00:00:00 2001 From: sellensr Date: Fri, 26 Apr 2019 16:33:26 -0400 Subject: [PATCH 2/4] Added Documentation Comments to Adafruit_BME280.h --- Adafruit_BME280.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Adafruit_BME280.h b/Adafruit_BME280.h index fc4f5b5..8e21aea 100644 --- a/Adafruit_BME280.h +++ b/Adafruit_BME280.h @@ -34,8 +34,8 @@ @brief default I2C address */ /**************************************************************************/ - #define BME280_ADDRESS (0x77) - #define BME280_ADDRESS_ALTERNATE (0x76) + #define BME280_ADDRESS (0x77) // Primary I2C Address + #define BME280_ADDRESS_ALTERNATE (0x76) // Alternate Address /*=========================================================================*/ /**************************************************************************/ From 8ab293829a74037a6bc7c333fd06a6a504d55a84 Mon Sep 17 00:00:00 2001 From: sellensr Date: Fri, 26 Apr 2019 16:44:42 -0400 Subject: [PATCH 3/4] Update Adafruit_BME280.h Dox block at line 38 --- Adafruit_BME280.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Adafruit_BME280.h b/Adafruit_BME280.h index 8e21aea..f5dbe91 100644 --- a/Adafruit_BME280.h +++ b/Adafruit_BME280.h @@ -35,6 +35,11 @@ */ /**************************************************************************/ #define BME280_ADDRESS (0x77) // Primary I2C Address +/**************************************************************************/ +/*! + @brief alternate I2C address +*/ +/**************************************************************************/ #define BME280_ADDRESS_ALTERNATE (0x76) // Alternate Address /*=========================================================================*/ From 46eb77e7637214a98c6b6416306624106b9f6b87 Mon Sep 17 00:00:00 2001 From: sellensr Date: Fri, 26 Apr 2019 20:04:05 -0400 Subject: [PATCH 4/4] change delay() to !Serial in BME280test.ino --- examples/bme280test/bme280test.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/bme280test/bme280test.ino b/examples/bme280test/bme280test.ino index f2eae8e..c7d0ffb 100644 --- a/examples/bme280test/bme280test.ino +++ b/examples/bme280test/bme280test.ino @@ -35,7 +35,7 @@ unsigned long delayTime; void setup() { Serial.begin(9600); - delay(4000); // time to get serial running + while(!Serial); // time to get serial running Serial.println(F("BME280 test")); unsigned status;