begin() fail gracefully
try 0x76 address as well. record _sensorID
This commit is contained in:
parent
799dae5f0a
commit
874147604f
|
|
@ -116,9 +116,15 @@ bool Adafruit_BME280::begin(uint8_t addr, TwoWire *theWire)
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
bool Adafruit_BME280::begin(void)
|
bool Adafruit_BME280::begin(void)
|
||||||
{
|
{
|
||||||
|
bool status = false;
|
||||||
_i2caddr = BME280_ADDRESS;
|
_i2caddr = BME280_ADDRESS;
|
||||||
_wire = &Wire;
|
_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
|
// 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;
|
return false;
|
||||||
|
|
||||||
// reset the device using soft-reset
|
// 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);
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
*/
|
*/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
#define BME280_ADDRESS (0x77)
|
#define BME280_ADDRESS (0x77)
|
||||||
|
#define BME280_ADDRESS_ALTERNATE (0x76)
|
||||||
/*=========================================================================*/
|
/*=========================================================================*/
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
|
@ -218,7 +219,7 @@ class Adafruit_BME280 {
|
||||||
|
|
||||||
float readAltitude(float seaLevel);
|
float readAltitude(float seaLevel);
|
||||||
float seaLevelForAltitude(float altitude, float pressure);
|
float seaLevelForAltitude(float altitude, float pressure);
|
||||||
|
uint32_t sensorID(void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TwoWire *_wire; //!< pointer to a TwoWire object
|
TwoWire *_wire; //!< pointer to a TwoWire object
|
||||||
|
|
|
||||||
|
|
@ -35,15 +35,21 @@ unsigned long delayTime;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
delay(4000); // time to get serial running
|
||||||
Serial.println(F("BME280 test"));
|
Serial.println(F("BME280 test"));
|
||||||
|
|
||||||
bool status;
|
unsigned status;
|
||||||
|
|
||||||
// default settings
|
// default settings
|
||||||
// (you can also pass in a Wire library object like &Wire2)
|
// (you can also pass in a Wire library object like &Wire2)
|
||||||
status = bme.begin();
|
status = bme.begin();
|
||||||
if (!status) {
|
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);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue