diff --git a/libraries/INA219/CHANGELOG.md b/libraries/INA219/CHANGELOG.md index d8c26bd7..75cc74b8 100644 --- a/libraries/INA219/CHANGELOG.md +++ b/libraries/INA219/CHANGELOG.md @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.4.0] - 2024-08-14 +- fix **float getShuntVoltage()** for negative values, kudos to aguilerabr +- add **int getMaxShuntVoltage()**, depends on GAIN (Table 7). +- removed default for **setGain()** as it was not sensors default. +- update readme.md + +---- + ## [0.3.1] - 2024-04-22 - Bump version after Fix #17, Kudos to ChrisRed255 diff --git a/libraries/INA219/INA219.cpp b/libraries/INA219/INA219.cpp index 8bcf0708..d791d003 100644 --- a/libraries/INA219/INA219.cpp +++ b/libraries/INA219/INA219.cpp @@ -1,6 +1,6 @@ // FILE: INA219.h // AUTHOR: Rob Tillaart -// VERSION: 0.3.1 +// VERSION: 0.4.0 // DATE: 2021-05-18 // PURPOSE: Arduino library for INA219 voltage, current and power sensor // URL: https://github.com/RobTillaart/INA219 @@ -74,7 +74,7 @@ uint8_t INA219::getAddress() // float INA219::getShuntVoltage() { - uint16_t value = _readRegister(INA219_SHUNT_VOLTAGE); + int16_t value = _readRegister(INA219_SHUNT_VOLTAGE); return value * 1e-5; // fixed 10 uV } @@ -167,6 +167,7 @@ bool INA219::setGain(uint8_t factor) } uint16_t config = _readRegister(INA219_CONFIGURATION); config &= ~INA219_CONF_PROG_GAIN; + // factor == 1 ==> mask = 00 if (factor == 2) config |= (1 << 11); else if (factor == 4) config |= (2 << 11); else if (factor == 8) config |= (3 << 11); @@ -187,6 +188,13 @@ uint8_t INA219::getGain() } +int INA219::getMaxShuntVoltage() +{ + int gain = getGain(); // 1, 2, 4, 8 + return gain * 40; // 40, 80, 160, 320 +} + + //////////////////////////////////////////////////////// // // BUS diff --git a/libraries/INA219/INA219.h b/libraries/INA219/INA219.h index 772e6f3a..40d919b8 100644 --- a/libraries/INA219/INA219.h +++ b/libraries/INA219/INA219.h @@ -1,7 +1,7 @@ #pragma once // FILE: INA219.h // AUTHOR: Rob Tillaart -// VERSION: 0.3.1 +// VERSION: 0.4.0 // DATE: 2021-05-18 // PURPOSE: Arduino library for INA219 voltage, current and power sensor // URL: https://github.com/RobTillaart/INA219 @@ -13,7 +13,7 @@ #include "Wire.h" -#define INA219_LIB_VERSION (F("0.3.1")) +#define INA219_LIB_VERSION (F("0.4.0")) class INA219 @@ -54,9 +54,14 @@ public: // voltage = 16, 32 (values below 32 are rounded to 16 or 32) bool setBusVoltageRange(uint8_t voltage = 16); uint8_t getBusVoltageRange(); // returns 16 or 32. - // factor = 1, 2, 4, 8 - bool setGain(uint8_t factor = 1); + // factor = 1, 2, 4, 8 (8 = sensor default) + bool setGain(uint8_t factor); // removed default parameter. uint8_t getGain(); + // MaxShuntVoltagedepends on GAIN, + // See Table 7. Shunt Voltage Register Format + // default = 320. + int getMaxShuntVoltage(); + // configuration BUS // use one of the next three diff --git a/libraries/INA219/README.md b/libraries/INA219/README.md index 4cd084ca..bfa8c04b 100644 --- a/libraries/INA219/README.md +++ b/libraries/INA219/README.md @@ -33,6 +33,12 @@ A few important maxima, see datasheet, chapter 7, esp 7.5 +#### 0.4.0 Breaking change + +Version 0.4.0 fixed negative values for **getShuntVoltage()**. +Older versions are obsolete now. + + #### 0.2.0 Breaking change Version 0.2.0 introduced a breaking change. @@ -146,14 +152,16 @@ See section below. Returns false if it could not write settings to device. - **bool setBusVoltageRange(uint8_t voltage = 16)** set to 16 or 32. Values <= 16 map to 16 and values between 16 and 32 map to 32. -Returns false if voltage is above 32.. +Returns false if voltage is above 32. Returns false if it could not write settings to device. - **uint8_t getBusVoltageRange()** returns 16 or 32. (Volts) -- **bool setGain(uint8_t factor = 1)** factor = 1, 2, 4, 8. +- **bool setGain(uint8_t factor)** factor = 1, 2, 4, 8 (default). Determines the shunt voltage range. 40, 80, 160 or 320 mV. Returns false if factor is not a valid value. Returns false if it could not write settings to device. - **uint8_t getGain()** returns set factor. +- **int getMaxShuntVoltage()** returns 40, 80, 160 or 320 (mV). +320 is the sensors default. #### Configuration BUS and SHUNT diff --git a/libraries/INA219/keywords.txt b/libraries/INA219/keywords.txt index 3dda43cc..ac8fafdf 100644 --- a/libraries/INA219/keywords.txt +++ b/libraries/INA219/keywords.txt @@ -32,6 +32,7 @@ setBusVoltageRange KEYWORD2 getBusVoltageRange KEYWORD2 setGain KEYWORD2 getGain KEYWORD2 +getMaxShuntVoltage KEYWORD2 setBusResolution KEYWORD2 setBusSamples KEYWORD2 diff --git a/libraries/INA219/library.json b/libraries/INA219/library.json index f6faccf0..5a50cd08 100644 --- a/libraries/INA219/library.json +++ b/libraries/INA219/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/INA219.git" }, - "version": "0.3.1", + "version": "0.4.0", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/libraries/INA219/library.properties b/libraries/INA219/library.properties index 99a7b640..9f1901f6 100644 --- a/libraries/INA219/library.properties +++ b/libraries/INA219/library.properties @@ -1,5 +1,5 @@ name=INA219 -version=0.3.1 +version=0.4.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for INA219 voltage, current and power sensor.