Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion Adafruit_BME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Adafruit_BME280::Adafruit_BME280(int8_t cspin, int8_t mosipin, int8_t misopin,
bool Adafruit_BME280::begin(TwoWire *theWire) {
_wire = theWire;
_i2caddr = BME280_ADDRESS;
_sda = PIN_WIRE_SDA;
_scl = PIN_WIRE_SCL;
return init();
}

Expand All @@ -80,6 +82,8 @@ bool Adafruit_BME280::begin(TwoWire *theWire) {
bool Adafruit_BME280::begin(uint8_t addr) {
_i2caddr = addr;
_wire = &Wire;
_sda = PIN_WIRE_SDA;
_scl = PIN_WIRE_SCL;
return init();
}

Expand All @@ -92,6 +96,39 @@ bool Adafruit_BME280::begin(uint8_t addr) {
bool Adafruit_BME280::begin(uint8_t addr, TwoWire *theWire) {
_i2caddr = addr;
_wire = theWire;
_sda = PIN_WIRE_SDA;
_scl = PIN_WIRE_SCL;
return init();
}

/*!
* @brief Initialise sensor with given parameters / settings
* @param addr the I2C address the device can be found on
* @param sdapin the pin to use for I2C SDA
* @param sclpin the pin to use for I2C SCL
* @returns true on success, false otherwise
*/
bool Adafruit_BME280::begin(uint8_t addr, int8_t sdapin, int8_t sclpin) {
_i2caddr = addr;
_wire = &Wire;
_sda = sdapin;
_scl = sclpin;
return init();
}

/*!
* @brief Initialise sensor with given parameters / settings
* @param addr the I2C address the device can be found on
* @param sdapin the pin to use for I2C SDA
* @param sclpin the pin to use for I2C SCL
* @param theWire the I2C object to use
* @returns true on success, false otherwise
*/
bool Adafruit_BME280::begin(uint8_t addr, int8_t sdapin, int8_t sclpin, TwoWire *theWire) {
_i2caddr = addr;
_wire = theWire;
_sda = sdapin;
_scl = sclpin;
return init();
}

Expand All @@ -101,6 +138,8 @@ bool Adafruit_BME280::begin(uint8_t addr, TwoWire *theWire) {
*/
bool Adafruit_BME280::begin(void) {
bool status = false;
_sda = PIN_WIRE_SDA;
_scl = PIN_WIRE_SCL;
_i2caddr = BME280_ADDRESS;
_wire = &Wire;
status = init();
Expand All @@ -119,7 +158,7 @@ bool Adafruit_BME280::init() {
// init I2C or SPI sensor interface
if (_cs == -1) {
// I2C
_wire->begin();
_wire->begin(_sda, _scl);
} else {
digitalWrite(_cs, HIGH);
pinMode(_cs, OUTPUT);
Expand Down
5 changes: 5 additions & 0 deletions Adafruit_BME280.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ class Adafruit_BME280 {
bool begin(TwoWire *theWire);
bool begin(uint8_t addr);
bool begin(uint8_t addr, TwoWire *theWire);
bool begin(uint8_t addr, int8_t sdapin, int8_t sclpin);
bool begin(uint8_t addr, int8_t sdapin, int8_t sclpin, TwoWire *theWire);
bool init();

void setSampling(sensor_mode mode = MODE_NORMAL,
Expand Down Expand Up @@ -241,6 +243,9 @@ class Adafruit_BME280 {
int8_t _miso; //!< for the SPI interface
int8_t _sck; //!< for the SPI interface

int8_t _sda; //!< for the I2C interface
int8_t _scl; //!< for the I2C interface

bme280_calib_data _bme280_calib; //!< here calibration data is stored

/**************************************************************************/
Expand Down