Skip to content

Commit

Permalink
Merge pull request #14 from jarzebski/dev
Browse files Browse the repository at this point in the history
release 1.1.0
  • Loading branch information
jarzebski authored May 18, 2023
2 parents 93f661a + c4990c2 commit 20e0524
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 707 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
INA226 Arduino Library 1.1.0 / 18.06.2023
======================================================================

* Fixes for calibrate method and setShuntVoltageLimit method
* Add new method readRawShuntCurrent()
* Add new method disableAlerts()
* Change getMaskEnable() to public access
* Remove beginTransmission and endTransmission in readRegister
* Remove delay(1) in wire transmission
* Add PlatformIO and Arduino library informations
* Change to MIT license
* General cleanups

INA226 Arduino Library 1.0.0 / 08.04.2014
======================================================================

Expand Down
695 changes: 21 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
78 changes: 78 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
###########################################
# Syntax Coloring Map For INA226
###########################################

###########################################
# Datatypes (KEYWORD1)
###########################################

INA226 KEYWORD1

###########################################
# Methods and Functions (KEYWORD2)
###########################################
begin KEYWORD2
configure KEYWORD2
calibrate KEYWORD2
getAverages KEYWORD2
getBusConversionTime KEYWORD2
getShuntConversionTime KEYWORD2
enableShuntOverLimitAlert KEYWORD2
enableBusOvertLimitAlert KEYWORD2
enableBusUnderLimitAlert KEYWORD2
enableOverPowerLimitAlert KEYWORD2
enableConversionReadyAlert KEYWORD2
disableAlerts KEYWORD2
setBusVoltageLimit KEYWORD2
setShuntVoltageLimit KEYWORD2
setPowerLimit KEYWORD2
setAlertInvertedPolarity KEYWORD2
setAlertLatch KEYWORD2
isMathOverflow KEYWORD2
isAlert KEYWORD2
readShuntCurrent KEYWORD2
readRawShuntCurrent KEYWORD2
readShuntVoltage KEYWORD2
readBusPower KEYWORD2
readBusVoltage KEYWORD2
getMaxPossibleCurrent KEYWORD2
getMaxCurrent KEYWORD2
getMaxShuntVoltage KEYWORD2
getMaxPower KEYWORD2
getMaskEnable KEYWORD2

###########################################
# Constants (LITERAL1)
###########################################
INA226_AVERAGES_1 LITERAL1
INA226_AVERAGES_4 LITERAL1
INA226_AVERAGES_16 LITERAL1
INA226_AVERAGES_64 LITERAL1
INA226_AVERAGES_128 LITERAL1
INA226_AVERAGES_256 LITERAL1
INA226_AVERAGES_512 LITERAL1
INA226_AVERAGES_1024 LITERAL1
INA226_BUS_CONV_TIME_140US LITERAL1
INA226_BUS_CONV_TIME_204US LITERAL1
INA226_BUS_CONV_TIME_332US LITERAL1
INA226_BUS_CONV_TIME_588US LITERAL1
INA226_BUS_CONV_TIME_1100US LITERAL1
INA226_BUS_CONV_TIME_2116US LITERAL1
INA226_BUS_CONV_TIME_4156US LITERAL1
INA226_BUS_CONV_TIME_8244US LITERAL1
INA226_SHUNT_CONV_TIME_140US LITERAL1
INA226_SHUNT_CONV_TIME_204US LITERAL1
INA226_SHUNT_CONV_TIME_332US LITERAL1
INA226_SHUNT_CONV_TIME_588US LITERAL1
INA226_SHUNT_CONV_TIME_1100US LITERAL1
INA226_SHUNT_CONV_TIME_2116US LITERAL1
INA226_SHUNT_CONV_TIME_4156US LITERAL1
INA226_SHUNT_CONV_TIME_8244US LITERAL1
INA226_MODE_POWER_DOWN LITERAL1
INA226_MODE_SHUNT_TRIG LITERAL1
INA226_MODE_BUS_TRIG LITERAL1
INA226_MODE_SHUNT_BUS_TRIG LITERAL1
INA226_MODE_ADC_OFF LITERAL1
INA226_MODE_SHUNT_CONT LITERAL1
INA226_MODE_BUS_CONT LITERAL1
INA226_MODE_SHUNT_BUS_CONT LITERAL1
16 changes: 16 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Arduino-INA226",
"keywords": "INA226, sensor, power monitoe, power, i2c, wire",
"description": "INA226 Bi-directional Current/Power Monitor Arduino Library",
"repository": {
"type": "git",
"url": "https://github.com/jarzebski/Arduino-INA226"
},
"authors": {
"name": "Korneliusz Jarzębski",
"url": "https://www.jarzebski.pl"
},
"version": "1.1.0",
"frameworks": "arduino",
"platforms": "*"
}
11 changes: 11 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name=INA226 Arduino Library
version=1.1.0
author=Korneliusz Jarzębski
maintainer=Korneliusz Jarzębski
sentence=INA226 Bi-directional Current/Power Monitor Arduino Library
paragraph=
category=Sensors
url=https://github.com/jarzebski/Arduino-INA226
architectures=*
includes=INA226.h
depends=
49 changes: 30 additions & 19 deletions INA226.cpp → src/INA226.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
/*
INA226.cpp - Class file for the INA226 Bi-directional Current/Power Monitor Arduino Library.
Version: 1.0.0
(c) 2014 Korneliusz Jarzebski
www.jarzebski.pl
The MIT License
This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.
Copyright (c) 2014-2023 Korneliusz Jarzębski
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#if ARDUINO >= 100
Expand Down Expand Up @@ -122,6 +128,11 @@ float INA226::readShuntCurrent(void)
return (readRegister16(INA226_REG_CURRENT) * currentLSB);
}

int16_t INA226::readRawShuntCurrent(void)
{
return readRegister16(INA226_REG_CURRENT);
}

float INA226::readShuntVoltage(void)
{
float voltage;
Expand Down Expand Up @@ -223,6 +234,11 @@ void INA226::enableConversionReadyAlert(void)
writeRegister16(INA226_REG_MASKENABLE, INA226_BIT_CNVR);
}

void INA226::disableAlerts(void)
{
writeRegister16(INA226_REG_MASKENABLE, 0);
}

void INA226::setBusVoltageLimit(float voltage)
{
uint16_t value = voltage / 0.00125;
Expand Down Expand Up @@ -293,19 +309,14 @@ int16_t INA226::readRegister16(uint8_t reg)
#endif
Wire.endTransmission();

delay(1);

Wire.beginTransmission(inaAddress);
Wire.requestFrom(inaAddress, 2);
while(!Wire.available()) {};
#if ARDUINO >= 100
uint8_t vha = Wire.read();
uint8_t vla = Wire.read();
#else
uint8_t vha = Wire.receive();
uint8_t vla = Wire.receive();
#endif;
Wire.endTransmission();
#endif

value = vha << 8 | vla;

Expand Down
38 changes: 24 additions & 14 deletions INA226.h → src/INA226.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
/*
INA226.h - Header file for the Bi-directional Current/Power Monitor Arduino Library.
Version: 1.0.0
(c) 2014 Korneliusz Jarzebski
www.jarzebski.pl
The MIT License
This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.
Copyright (c) 2014-2023 Korneliusz Jarzębski
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef INA226_h
Expand Down Expand Up @@ -118,6 +124,8 @@ class INA226
void enableOverPowerLimitAlert(void);
void enableConversionReadyAlert(void);

void disableAlerts(void);

void setBusVoltageLimit(float voltage);
void setShuntVoltageLimit(float voltage);
void setPowerLimit(float watts);
Expand All @@ -132,20 +140,22 @@ class INA226
float readShuntVoltage(void);
float readBusPower(void);
float readBusVoltage(void);
int16_t readRawShuntCurrent(void);

float getMaxPossibleCurrent(void);
float getMaxCurrent(void);
float getMaxShuntVoltage(void);
float getMaxPower(void);

uint16_t getMaskEnable(void);

private:

int8_t inaAddress;
float currentLSB, powerLSB;
float vShuntMax, vBusMax, rShunt;

void setMaskEnable(uint16_t mask);
uint16_t getMaskEnable(void);

void writeRegister16(uint8_t reg, uint16_t val);
int16_t readRegister16(uint8_t reg);
Expand Down

0 comments on commit 20e0524

Please sign in to comment.