Skip to content

Commit

Permalink
fixed wire issues and some other smal things
Browse files Browse the repository at this point in the history
version++
  • Loading branch information
peterus committed Apr 27, 2020
1 parent 8168458 commit d776259
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=INA226Lib
version=1.1.1
version=1.1.2
author=Peter Buchegger <[email protected]>, Korneliusz Jarzebski <[email protected]>
maintainer=Peter Buchegger <[email protected]>
sentence=Enables reading from INA226 current sensors to measure current and power.
Expand Down
12 changes: 8 additions & 4 deletions src/INA226.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*
INA226.cpp - Class file for the INA226 Bi-directional Current/Power Monitor Arduino Library.
Version: 1.0.0
(c) 2014 Korneliusz Jarzebski
(c) 2014 Korneliusz Jarzebski, modified 2020 by Peter Buchegger
www.jarzebski.pl
This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -49,7 +48,7 @@ bool INA226::configure(ina226_averages_t avg, ina226_busConvTime_t busConvTime,
return true;
}

bool INA226::calibrate(float rShuntValue, float iMaxExpected)
bool INA226::calibrate(float rShuntValue, float iMaxCurrentExcepted)
{
uint16_t calibrationValue;
rShunt = rShuntValue;
Expand All @@ -58,7 +57,7 @@ bool INA226::calibrate(float rShuntValue, float iMaxExpected)

iMaxPossible = vShuntMax / rShunt;

minimumLSB = iMaxExpected / 32767;
minimumLSB = iMaxCurrentExcepted / 32767;

currentLSB = (uint32_t)(minimumLSB * 100000000);
currentLSB /= 100000000;
Expand Down Expand Up @@ -285,7 +284,10 @@ int16_t INA226::readRegister16(uint8_t reg)
{
int16_t value;

Wire.beginTransmission(inaAddress);
Wire.write(reg);
Wire.endTransmission();

Wire.requestFrom(inaAddress, 2);
uint8_t vha = Wire.read();
uint8_t vla = Wire.read();
Expand All @@ -300,7 +302,9 @@ void INA226::writeRegister16(uint8_t reg, uint16_t val)
vla = (uint8_t)val;
val >>= 8;

Wire.beginTransmission(inaAddress);
Wire.write(reg);
Wire.write((uint8_t)val);
Wire.write(vla);
Wire.endTransmission();
}
7 changes: 3 additions & 4 deletions src/INA226.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*
INA226.h - Header file for the Bi-directional Current/Power Monitor Arduino Library.
Version: 1.0.0
(c) 2014 Korneliusz Jarzebski
(c) 2014 Korneliusz Jarzebski, modified 2020 by Peter Buchegger
www.jarzebski.pl
This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -104,7 +103,7 @@ class INA226

bool begin(uint8_t address = INA226_ADDRESS);
bool configure(ina226_averages_t avg = INA226_AVERAGES_1, ina226_busConvTime_t busConvTime = INA226_BUS_CONV_TIME_1100US, ina226_shuntConvTime_t shuntConvTime = INA226_SHUNT_CONV_TIME_1100US, ina226_mode_t mode = INA226_MODE_SHUNT_BUS_CONT);
bool calibrate(float rShuntValue = 0.1, float iMaxExcepted = 2);
bool calibrate(float rShuntValue = 0.1, float iMaxCurrentExcepted = 2);

ina226_averages_t getAverages(void);
ina226_busConvTime_t getBusConversionTime(void);
Expand Down Expand Up @@ -138,7 +137,7 @@ class INA226
float getMaxShuntVoltage(void);
float getMaxPower(void);

private:
private:

int8_t inaAddress;
float currentLSB, powerLSB;
Expand Down

0 comments on commit d776259

Please sign in to comment.