diff --git a/Adafruit_BME280.cpp b/Adafruit_BME280.cpp index 1f5ce32..cb06850 100644 --- a/Adafruit_BME280.cpp +++ b/Adafruit_BME280.cpp @@ -117,9 +117,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; } /**************************************************************************/ @@ -149,7 +155,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 @@ -613,3 +620,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 5aed6d5..5113c4a 100644 --- a/Adafruit_BME280.h +++ b/Adafruit_BME280.h @@ -35,7 +35,13 @@ @brief default I2C address */ /**************************************************************************/ - #define BME280_ADDRESS (0x77) + #define BME280_ADDRESS (0x77) // Primary I2C Address +/**************************************************************************/ +/*! + @brief alternate I2C address +*/ +/**************************************************************************/ + #define BME280_ADDRESS_ALTERNATE (0x76) // Alternate Address /*=========================================================================*/ /**************************************************************************/ @@ -219,7 +225,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 1ada946..9fb8c43 100644 --- a/examples/bme280test/bme280test.ino +++ b/examples/bme280test/bme280test.ino @@ -36,15 +36,21 @@ unsigned long delayTime; void setup() { Serial.begin(9600); + while(!Serial); // 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); }