diff --git a/Beastdevices_INA3221.cpp b/Beastdevices_INA3221.cpp index 04f6d2f..544ef3e 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); //custom i2c pins + } else { + return _i2c->begin(); + } } void Beastdevices_INA3221::setShuntRes(uint32_t res_ch1, uint32_t res_ch2, uint32_t res_ch3) { @@ -509,7 +514,7 @@ float Beastdevices_INA3221::getVoltage(ina3221_ch_t channel) { break; } - _read(reg, &val_raw); + _read(reg, &val_raw); voltage_V = val_raw / 1000.0; diff --git a/Beastdevices_INA3221.h b/Beastdevices_INA3221.h index 4293d56..e2f3939 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); // 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