Skip to content
Open
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
13 changes: 9 additions & 4 deletions Beastdevices_INA3221.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions Beastdevices_INA3221.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -308,4 +308,4 @@ class Beastdevices_INA3221 {
float getVoltage(ina3221_ch_t channel);
};

#endif
#endif