Skip to content

Commit 2a646f2

Browse files
committed
0.1.3 INA219
1 parent e30ffcd commit 2a646f2

File tree

16 files changed

+355
-96
lines changed

16 files changed

+355
-96
lines changed

libraries/INA219/.github/workflows/arduino-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
lint:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
9+
- uses: actions/checkout@v3
1010
- uses: arduino/arduino-lint-action@v1
1111
with:
1212
library-manager: update

libraries/INA219/.github/workflows/arduino_test_runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v3
1212
- uses: ruby/setup-ruby@v1
1313
with:
1414
ruby-version: 2.6

libraries/INA219/.github/workflows/jsoncheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414
- name: json-syntax-check
1515
uses: limitusus/json-syntax-check@v1
1616
with:

libraries/INA219/CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,24 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.1.3] - 2023-03-31
10+
- fix setBusADC() range check
11+
- fix setShuntADC() range check
12+
- fix setMode() range check
13+
- add getMathOverflowFlag()
14+
- add getConversionFlag()
15+
- add example to test settings
16+
- add example to test I2C speed
17+
- update readme.md
18+
- update GitHub actions
19+
- update license 2023
20+
- minor edits
21+
22+
923
## [0.1.2] - 2022-11-14
1024
- Add RP2040 support to build-CI.
1125
- Add CHANGELOG.md
1226

13-
1427
## [0.1.1] - 2022-09-06
1528
- refactor and first public release
1629

libraries/INA219/INA219.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// FILE: INA219.h
22
// AUTHOR: Rob Tillaart
3-
// VERSION: 0.1.2
3+
// VERSION: 0.1.3
44
// DATE: 2021-05-18
55
// PURPOSE: Arduino library for INA219 voltage, current and power sensor
66
// URL: https://github.com/RobTillaart/INA219
7-
//
8-
// HISTORY: see changelog.md
97

108

119
#include "INA219.h"
@@ -90,7 +88,7 @@ float INA219::getBusVoltage()
9088
{
9189
uint16_t value = _readRegister(INA219_BUS_VOLTAGE);
9290
uint8_t flags = value & 0x03;
93-
// overflow handling
91+
// math overflow handling
9492
if (flags & 0x01) return -100;
9593
float voltage = (value >> 3) * 4e-3; // fixed 4 mV
9694
return voltage;
@@ -112,6 +110,20 @@ float INA219::getCurrent()
112110
}
113111

114112

113+
bool INA219::getMathOverflowFlag()
114+
{
115+
uint16_t value = _readRegister(INA219_BUS_VOLTAGE);
116+
return ((value & 0x0001) == 0x0001);
117+
}
118+
119+
120+
bool INA219::getConversionFlag()
121+
{
122+
uint16_t value = _readRegister(INA219_BUS_VOLTAGE);
123+
return ((value & 0x0002) == 0x0002);
124+
}
125+
126+
115127
////////////////////////////////////////////////////////
116128
//
117129
// CONFIGURATION
@@ -178,7 +190,7 @@ uint8_t INA219::getGain()
178190

179191
bool INA219::setBusADC(uint8_t mask)
180192
{
181-
if (mask > 0x000F) return false;
193+
if (mask > 0x0F) return false;
182194

183195
// TODO improve this one. datasheet.
184196
// two functions
@@ -204,7 +216,7 @@ uint8_t INA219::getBusADC()
204216

205217
bool INA219::setShuntADC(uint8_t mask)
206218
{
207-
if (mask > 0x000F) return false;
219+
if (mask > 0x0F) return false;
208220

209221
// TODO improve this one. datasheet.
210222
// two functions
@@ -227,7 +239,7 @@ uint8_t INA219::getShuntADC()
227239

228240
bool INA219::setMode(uint8_t mode)
229241
{
230-
if (mode > 8) return false;
242+
if (mode > 7) return false;
231243
uint16_t config = _readRegister(INA219_CONFIGURATION);
232244
config &= ~INA219_CONF_MODE;
233245
config |= mode;
@@ -250,7 +262,7 @@ uint8_t INA219::getMode()
250262
//
251263
bool INA219::setMaxCurrentShunt(float maxCurrent, float shunt)
252264
{
253-
#define printdebug true
265+
// #define printdebug
254266
uint16_t calib = 0;
255267

256268
if (maxCurrent < 0.001) return false;
@@ -288,7 +300,7 @@ bool INA219::setMaxCurrentShunt(float maxCurrent, float shunt)
288300

289301
////////////////////////////////////////////////////////
290302
//
291-
// PRIVATE
303+
// PRIVATE
292304
//
293305

294306
uint16_t INA219::_readRegister(uint8_t reg)
@@ -315,5 +327,5 @@ uint16_t INA219::_writeRegister(uint8_t reg, uint16_t value)
315327
}
316328

317329

318-
// -- END OF FILE --
330+
// -- END OF FILE --
319331

libraries/INA219/INA219.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#pragma once
22
// FILE: INA219.h
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.2
4+
// VERSION: 0.1.3
55
// DATE: 2021-05-18
66
// PURPOSE: Arduino library for INA219 voltage, current and power sensor
77
// URL: https://github.com/RobTillaart/INA219
88
//
9-
// Read the datasheet for the details
9+
// Read the datasheet for the details how to connect!
1010
//
1111

1212

1313
#include "Arduino.h"
1414
#include "Wire.h"
1515

1616

17-
#define INA219_LIB_VERSION (F("0.1.2"))
17+
#define INA219_LIB_VERSION (F("0.1.3"))
1818

1919

2020
class INA219
@@ -30,11 +30,13 @@ class INA219
3030
bool isConnected();
3131

3232

33-
// CORE FUNCTIONS // Register
34-
float getShuntVoltage(); // 01
35-
float getBusVoltage(); // 02
36-
float getPower(); // 03
37-
float getCurrent(); // 04
33+
// CORE FUNCTIONS // Register
34+
float getShuntVoltage(); // 01
35+
float getBusVoltage(); // 02
36+
float getPower(); // 03
37+
float getCurrent(); // 04
38+
bool getMathOverflowFlag(); // 02
39+
bool getConversionFlag(); // 02
3840

3941

4042
// SCALE HELPERS
@@ -71,7 +73,7 @@ class INA219
7173
bool setModeADCOff() { return setMode(4); };
7274
bool setModeShuntContinuous() { return setMode(5); };
7375
bool setModeBusContinuous() { return setMode(6); };
74-
bool setModeShuntBusContinuous() { return setMode(7); }; // default.
76+
bool setModeShuntBusContinuous() { return setMode(7); }; // default.
7577

7678

7779
// CALIBRATION
@@ -109,5 +111,5 @@ class INA219
109111
};
110112

111113

112-
// -- END OF FILE --
114+
// -- END OF FILE --
113115

libraries/INA219/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021-2022 Rob Tillaart
3+
Copyright (c) 2021-2023 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)