Skip to content

Commit

Permalink
add getBusVoltage_uV() (#24)
Browse files Browse the repository at this point in the history
- added **getBusVoltage_uV()** for completeness
- INA226_test_I2C.ino to prep performance tests
- fix changelog.md
- fix keywords.txt
- update readme.md
- update GitHub actions
- update license 2023
- minor edits
  • Loading branch information
RobTillaart authored Apr 4, 2023
1 parent be51eab commit 460cbd7
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 75 deletions.
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
# Change Log I2CKeyPad8x8
# Change Log INA226

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.4.2] - 2023-04-03

- added **getBusVoltage_uV()** for completeness
- INA226_test_I2C.ino to prep performance tests
- fix changelog.md
- fix keywords.txt
- update readme.md
- update GitHub actions
- update license 2023
- minor edits


## [0.4.1] - 2022-11-12
- Add RP2040 support to build-CI.
- Add CHANGELOG.md - replaces release notes to be consistent over libraries.
- Add CHANGELOG.md, replaces release_notes to be consistent over my libraries.
- minor edit unit test


## [0.4.0] - 2022-08-26
- fix #16 - change error to warning for max current
setMaxCurrentShunt now returns an int indicating OK == 0
Expand Down
14 changes: 6 additions & 8 deletions INA226.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// FILE: INA226.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.4.1
// VERSION: 0.4.2
// DATE: 2021-05-18
// PURPOSE: Arduino library for INA226 power sensor
// URL: https://github.com/RobTillaart/INA226
//
// HISTORY: see changelog.md


#include "INA226.h"
Expand Down Expand Up @@ -99,7 +97,7 @@ float INA226::getBusVoltage()
float INA226::getPower()
{
uint16_t val = _readRegister(INA226_POWER);
return val * 25 * _current_LSB; // fixed 25 Watt
return val * 25 * _current_LSB; // fixed 25 Watt
}


Expand Down Expand Up @@ -196,7 +194,7 @@ int INA226::setMaxCurrentShunt(float maxCurrent, float shunt, bool normalize)

// fix #16 - datasheet 6.5 Electrical Characteristics
// rounded value to 80 mV
float shuntVoltage = abs(maxCurrent * shunt);
float shuntVoltage = abs(maxCurrent * shunt);
if (shuntVoltage > 0.080) return INA226_ERR_SHUNTVOLTAGE_HIGH;
if (maxCurrent < 0.001) return INA226_ERR_MAXCURRENT_LOW;
if (shunt < 0.001) return INA226_ERR_SHUNT_LOW;
Expand Down Expand Up @@ -298,7 +296,7 @@ uint8_t INA226::getMode()

////////////////////////////////////////////////////////
//
// alert
// alert
//
void INA226::setAlertRegister(uint16_t mask)
{
Expand Down Expand Up @@ -326,7 +324,7 @@ uint16_t INA226::getAlertLimit()

////////////////////////////////////////////////////////
//
// meta information
// meta information
//
uint16_t INA226::getManufacturerID()
{
Expand Down Expand Up @@ -367,5 +365,5 @@ uint16_t INA226::_writeRegister(uint8_t reg, uint16_t value)
}


// -- END OF FILE --
// -- END OF FILE --

26 changes: 14 additions & 12 deletions INA226.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
// FILE: INA226.h
// AUTHOR: Rob Tillaart
// VERSION: 0.4.1
// VERSION: 0.4.2
// DATE: 2021-05-18
// PURPOSE: Arduino library for INA226 power sensor
// URL: https://github.com/RobTillaart/INA226
Expand All @@ -14,7 +14,7 @@
#include "Wire.h"


#define INA226_LIB_VERSION (F("0.4.1"))
#define INA226_LIB_VERSION (F("0.4.2"))


// set by setAlertRegister
Expand Down Expand Up @@ -55,17 +55,19 @@ class INA226


// Core functions
float getBusVoltage();
float getShuntVoltage();
float getCurrent();
float getPower();
float getBusVoltage(); // Volt
float getShuntVoltage(); // Volt
float getCurrent(); // Ampere
float getPower(); // Watt


// Scale helpers
// Scale helpers milli range
float getBusVoltage_mV() { return getBusVoltage() * 1e3; };
float getShuntVoltage_mV() { return getShuntVoltage() * 1e3; };
float getCurrent_mA() { return getCurrent() * 1e3; };
float getPower_mW() { return getPower() * 1e3; };
// Scale helpers micro range
float getBusVoltage_uV() { return getBusVoltage() * 1e6; };
float getShuntVoltage_uV() { return getShuntVoltage() * 1e6; };
float getCurrent_uA() { return getCurrent() * 1e6; };
float getPower_uW() { return getPower() * 1e6; };
Expand All @@ -86,7 +88,7 @@ class INA226
// shunt * maxCurrent < 81 mV
// maxCurrent >= 0.001
// shunt >= 0.001
int setMaxCurrentShunt(float macCurrent = 20.0,
int setMaxCurrentShunt(float macCurrent = 20.0,
float shunt = 0.002,
bool normalize = true);
bool isCalibrated() { return _current_LSB != 0.0; };
Expand All @@ -108,7 +110,7 @@ class INA226
bool setModeShuntBusTrigger() { return setMode(3); };
bool setModeShuntContinuous() { return setMode(5); };
bool setModeBusContinuous() { return setMode(6); };
bool setModeShuntBusContinuous() { return setMode(7); }; // default.
bool setModeShuntBusContinuous() { return setMode(7); }; // default.


// Alert
Expand All @@ -124,8 +126,8 @@ class INA226


// Meta information
uint16_t getManufacturerID(); // should return 0x5449
uint16_t getDieID(); // should return 0x2260
uint16_t getManufacturerID(); // should return 0x5449
uint16_t getDieID(); // should return 0x2260


// DEBUG
Expand All @@ -146,5 +148,5 @@ class INA226
};


// -- END OF FILE --
// -- END OF FILE --

Loading

0 comments on commit 460cbd7

Please sign in to comment.