mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.4.0 INA219
This commit is contained in:
parent
a10164e153
commit
018ec25de3
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -32,6 +32,7 @@ setBusVoltageRange KEYWORD2
|
||||
getBusVoltageRange KEYWORD2
|
||||
setGain KEYWORD2
|
||||
getGain KEYWORD2
|
||||
getMaxShuntVoltage KEYWORD2
|
||||
|
||||
setBusResolution KEYWORD2
|
||||
setBusSamples KEYWORD2
|
||||
|
@ -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": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=INA219
|
||||
version=0.3.1
|
||||
version=0.4.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for INA219 voltage, current and power sensor.
|
||||
|
Loading…
Reference in New Issue
Block a user