Skip to content

Commit 882f634

Browse files
committed
Allow user to call TwoWire::begin themselves
* That way, they can use non-default pins and have multiple devices on a single TwoWire bus.
1 parent a49542c commit 882f634

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Adafruit_BMP280.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,19 @@ Adafruit_BMP280::Adafruit_BMP280(int8_t cspin, int8_t mosipin, int8_t misopin,
7373
* The I2C address to use (default = 0x77)
7474
* @param chipid
7575
* The expected chip ID (used to validate connection).
76+
* @param beginTwi
77+
* Call begin on the TwoWire object (default = true).
78+
* If false, call TwoWire::begin yourself before calling
79+
* this function.
7680
* @return True if the init was successful, otherwise false.
7781
*/
78-
bool Adafruit_BMP280::begin(uint8_t addr, uint8_t chipid) {
82+
bool Adafruit_BMP280::begin(uint8_t addr, uint8_t chipid, bool beginTwi) {
7983
_i2caddr = addr;
8084

8185
if (_cs == -1) {
8286
// i2c
83-
_wire->begin();
87+
if(beginTwi)
88+
_wire->begin();
8489
} else {
8590
digitalWrite(_cs, HIGH);
8691
pinMode(_cs, OUTPUT);

Adafruit_BMP280.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class Adafruit_BMP280 {
187187
Adafruit_BMP280(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin);
188188
~Adafruit_BMP280(void);
189189

190-
bool begin(uint8_t addr = BMP280_ADDRESS, uint8_t chipid = BMP280_CHIPID);
190+
bool begin(uint8_t addr = BMP280_ADDRESS, uint8_t chipid = BMP280_CHIPID, bool beginTwi = true);
191191
void reset(void);
192192
uint8_t getStatus(void);
193193

0 commit comments

Comments
 (0)