diff --git a/Beastdevices_INA3221.cpp b/Beastdevices_INA3221.cpp index 04f6d2f..418d29b 100644 --- a/Beastdevices_INA3221.cpp +++ b/Beastdevices_INA3221.cpp @@ -49,9 +49,10 @@ void Beastdevices_INA3221::_write(ina3221_reg_t reg, uint16_t *val) { _i2c->endTransmission(); } -void Beastdevices_INA3221::begin(TwoWire *theWire) { +bool Beastdevices_INA3221::begin(TwoWire *theWire, int sdaPin, int sclPin) { _i2c = theWire; - + + // Initialize shunt resistors with default values _shuntRes[0] = 10; _shuntRes[1] = 10; _shuntRes[2] = 10; @@ -60,7 +61,11 @@ void Beastdevices_INA3221::begin(TwoWire *theWire) { _filterRes[1] = 0; _filterRes[2] = 0; - _i2c->begin(); + if (sdaPin != -1 && sclPin != -1) { + return _i2c->begin(sdaPin, sclPin); + } else { + return _i2c->begin(); + } } void Beastdevices_INA3221::setShuntRes(uint32_t res_ch1, uint32_t res_ch2, uint32_t res_ch3) { diff --git a/Beastdevices_INA3221.h b/Beastdevices_INA3221.h index 4293d56..fad950c 100644 --- a/Beastdevices_INA3221.h +++ b/Beastdevices_INA3221.h @@ -156,7 +156,7 @@ class Beastdevices_INA3221 { Beastdevices_INA3221(ina3221_addr_t addr) : _i2c_addr(addr) {}; // Initializes INA3221 - void begin(TwoWire *theWire = &Wire); + bool begin(TwoWire *theWire, int sdaPin = -1, int sclPin = -1); //Update "begin" for custom i2c GPIO numbers // Sets shunt resistor value in mOhm void setShuntRes(uint32_t res_ch1, uint32_t res_ch2, uint32_t res_ch3); @@ -308,4 +308,4 @@ class Beastdevices_INA3221 { float getVoltage(ina3221_ch_t channel); }; -#endif \ No newline at end of file +#endif