Skip to content

Commit ff35f01

Browse files
committed
0.5.3 INA226
1 parent 24f939f commit ff35f01

File tree

14 files changed

+165
-63
lines changed

14 files changed

+165
-63
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# These are supported funding model platforms
22

33
github: RobTillaart
4+
custom: "https://www.paypal.me/robtillaart"
45

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ on: [push, pull_request]
55
jobs:
66
lint:
77
runs-on: ubuntu-latest
8+
timeout-minutes: 5
89
steps:
9-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v4
1011
- uses: arduino/arduino-lint-action@v1
1112
with:
1213
library-manager: update

libraries/INA226/.github/workflows/arduino_test_runner.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
---
2+
23
name: Arduino CI
34

45
on: [push, pull_request]
56

67
jobs:
78
runTest:
89
runs-on: ubuntu-latest
10+
timeout-minutes: 20
911

1012
steps:
11-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1214
- uses: ruby/setup-ruby@v1
1315
with:
1416
ruby-version: 2.6

libraries/INA226/.github/workflows/jsoncheck.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ on:
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
12+
timeout-minutes: 5
1213
steps:
13-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1415
- name: json-syntax-check
15-
uses: limitusus/json-syntax-check@v1
16+
uses: limitusus/json-syntax-check@v2
1617
with:
1718
pattern: "\\.json$"
1819

libraries/INA226/CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ 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.5.3] - 2024-03-25
10+
- add enum **ina226_average_enum** (Thanks to Henk Holdijk)
11+
- add enum **ina226_timing_enum** for BVCT SVCT conversion timing
12+
- update keywords
13+
- update GitHub actions
14+
- update section **Configuration** in readme.md.
15+
- update unit test
16+
- minor edits
17+
18+
919
## [0.5.2] - 2024-01-06
1020
- Thanks to Henk Holdijk for his improvements.
1121
- fix #35, add **bool isConversionReady()**
@@ -17,7 +27,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1727
- remove not needed include from examples.
1828
- update readme.md
1929

20-
2130
## [0.5.1] - 2023-12-10
2231
- reimplementation of **setMaxCurrentShunt()**,
2332
- thanks to tileiar

libraries/INA226/INA226.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// FILE: INA226.cpp
22
// AUTHOR: Rob Tillaart
3-
// VERSION: 0.5.2
3+
// VERSION: 0.5.3
44
// DATE: 2021-05-18
55
// PURPOSE: Arduino library for INA226 power sensor
66
// URL: https://github.com/RobTillaart/INA226

libraries/INA226/INA226.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22
// FILE: INA226.h
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.5.2
4+
// VERSION: 0.5.3
55
// DATE: 2021-05-18
66
// PURPOSE: Arduino library for INA226 power sensor
77
// URL: https://github.com/RobTillaart/INA226
@@ -13,7 +13,7 @@
1313
#include "Wire.h"
1414

1515

16-
#define INA226_LIB_VERSION "0.5.2"
16+
#define INA226_LIB_VERSION "0.5.3"
1717

1818

1919
// set by setAlertRegister
@@ -46,6 +46,32 @@
4646
#define INA226_MAX_WAIT_MS 600 // millis
4747

4848

49+
// for setAverage() and getAverage()
50+
enum ina226_average_enum {
51+
INA226_1_SAMPLE = 0,
52+
INA226_4_SAMPLES = 1,
53+
INA226_16_SAMPLES = 2,
54+
INA226_64_SAMPLES = 3,
55+
INA226_128_SAMPLES = 4,
56+
INA226_256_SAMPLES = 5,
57+
INA226_512_SAMPLES = 6,
58+
INA226_1024_SAMPLES = 7
59+
};
60+
61+
62+
// for BVCT and SVCT conversion timing.
63+
enum ina226_timing_enum {
64+
INA226_140_us = 0,
65+
INA226_204_us = 1,
66+
INA226_332_us = 2,
67+
INA226_588_us = 3,
68+
INA226_1100_us = 4,
69+
INA226_2100_us = 5,
70+
INA226_4200_us = 6,
71+
INA226_8300_us = 7
72+
};
73+
74+
4975
class INA226
5076
{
5177
public:
@@ -81,11 +107,11 @@ class INA226
81107

82108
// Configuration
83109
bool reset();
84-
bool setAverage(uint8_t avg = 0);
110+
bool setAverage(uint8_t avg = INA226_1_SAMPLE);
85111
uint8_t getAverage();
86-
bool setBusVoltageConversionTime(uint8_t bvct = 4);
112+
bool setBusVoltageConversionTime(uint8_t bvct = INA226_1100_us);
87113
uint8_t getBusVoltageConversionTime();
88-
bool setShuntVoltageConversionTime(uint8_t svct = 4);
114+
bool setShuntVoltageConversionTime(uint8_t svct = INA226_1100_us);
89115
uint8_t getShuntVoltageConversionTime();
90116

91117

libraries/INA226/README.md

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -161,50 +161,66 @@ Helper functions for the micro scale.
161161

162162
#### Configuration
163163

164-
Note: the conversion time runs in the background and if done value is stored in a register.
165-
The core functions read from the registers, so they are not blocked.
166-
They return the same value if no new data is available / ready.
164+
**Note:**
165+
The internal conversions runs in the background in the device.
166+
If a conversion is finished the measured value is stored in the appropriate register.
167+
The last obtained values can always be read from the registers, so they will not block.
168+
Result can be that you get the very same value if no new data is available yet.
169+
This is especially true if you increase the number of samples.
170+
(See also discussion in INA219 issue 11).
171+
172+
Using more samples reduces the noise level, but one will miss the faster
173+
changes in voltage or current.
174+
Depending on your project needs you can choose one over the other.
175+
176+
As a rule of thumb one could take the time between two I2C reads of
177+
a register as an upper limit.
178+
This would result in a fresh measurement every time one reads the register.
179+
NB it is always possible to average readings fetched from the device
180+
in your own code.
181+
167182

168183
- **bool reset()** software power on reset.
169184
This implies calibration with **setMaxCurrentShunt()** needs to be redone.
170185
Returns true upon success.
171-
- **bool setAverage(uint8_t avg = 0)** see table below.
186+
- **bool setAverage(uint8_t avg = INA226_1_SAMPLE)** see table below.
172187
(0 = default ==> 1 read), returns false if parameter > 7.
173188
- **uint8_t getAverage()** returns the value set. See table below.
174189
Note this is not the count of samples.
175-
- **bool setBusVoltageConversionTime(uint8_t bvct = 4)** see table below.
190+
- **bool setBusVoltageConversionTime(uint8_t bvct = INA226_1100_us)** see table below.
176191
(4 = default ==> 1.1 ms), returns false if parameter > 7.
177192
- **uint8_t getBusVoltageConversionTime()** return the value set.
178193
Note the value returned is not a unit of time.
179-
- **bool setShuntVoltageConversionTime(uint8_t svct = 4)** see table below.
194+
- **bool setShuntVoltageConversionTime(uint8_t svct = INA226_1100_us)** see table below.
180195
(4 = default ==> 1.1 ms), returns false if parameter > 7.
181196
- **uint8_t getShuntVoltageConversionTime()** return the value set.
182197
Note the value returned is not a unit of time.
183198

184199

185-
| Average | # samples | notes |
186-
|:-------:|----------:|--------:|
187-
| 0 | 1 | default |
188-
| 1 | 4 | |
189-
| 2 | 16 | |
190-
| 3 | 64 | |
191-
| 4 | 128 | |
192-
| 5 | 256 | |
193-
| 6 | 512 | |
194-
| 7 | 1024 | |
200+
| enum description | value | # samples | notes |
201+
|:--------------------:|:-----:|----------:|--------:|
202+
| INA226_1_SAMPLE | 0 | 1 | default
203+
| INA226_4_SAMPLES | 1 | 4 |
204+
| INA226_16_SAMPLES | 2 | 16 |
205+
| INA226_64_SAMPLES | 3 | 64 |
206+
| INA226_128_SAMPLES | 4 | 128 |
207+
| INA226_256_SAMPLES | 5 | 256 |
208+
| INA226_512_SAMPLES | 6 | 512 |
209+
| INA226_1024_SAMPLES | 7 | 1024 |
210+
195211

196212

213+
| enum description | BVCT SVCT | time | notes |
214+
|:------------------:|:---------:|----------:|--------:|
215+
| INA226_140_us | 0 | 140 us |
216+
| INA226_204_us | 1 | 204 us |
217+
| INA226_332_us | 2 | 332 us |
218+
| INA226_588_us | 3 | 588 us |
219+
| INA226_1100_us | 4 | 1.1 ms | default
220+
| INA226_2100_us | 5 | 2.1 ms |
221+
| INA226_4200_us | 6 | 4.2 ms |
222+
| INA226_8300_us | 7 | 8.3 ms |
197223

198-
| BVCT SVCT | time | notes |
199-
|:---------:|----------:|--------:|
200-
| 0 | 140 us |
201-
| 1 | 204 us |
202-
| 2 | 332 us |
203-
| 3 | 588 us |
204-
| 4 | 1.1 ms | default |
205-
| 5 | 2.1 ms |
206-
| 6 | 4.2 ms |
207-
| 7 | 8.3 ms |
208224

209225
Note: times are typical, check datasheet for operational range.
210226
(max is ~10% higher)
@@ -249,13 +265,13 @@ See https://github.com/RobTillaart/INA226/pull/29 for details of the discussion.
249265

250266
#### Error codes setMaxCurrentShunt
251267

252-
| descriptive name error | value | meaning |
253-
|:------------------------------|---------:|:----------|
254-
| INA226_ERR_NONE | 0x0000 | OK
255-
| INA226_ERR_SHUNTVOLTAGE_HIGH | 0x8000 | maxCurrent \* shunt > 80 mV
256-
| INA226_ERR_MAXCURRENT_LOW | 0x8001 | maxCurrent < 0.001
257-
| INA226_ERR_SHUNT_LOW | 0x8002 | shunt < 0.001
258-
| INA226_ERR_NORMALIZE_FAILED | 0x8003 | not possible to normalize.
268+
| descriptive name error | value | meaning |
269+
|:-------------------------------|---------:|:----------|
270+
| INA226_ERR_NONE | 0x0000 | OK
271+
| INA226_ERR_SHUNTVOLTAGE_HIGH | 0x8000 | maxCurrent \* shunt > 80 mV
272+
| INA226_ERR_MAXCURRENT_LOW | 0x8001 | maxCurrent < 0.001
273+
| INA226_ERR_SHUNT_LOW | 0x8002 | shunt < 0.001
274+
| INA226_ERR_NORMALIZE_FAILED | 0x8003 | not possible to normalize.
259275

260276

261277
#### Operating mode
@@ -293,23 +309,23 @@ Returns true if write to register successful.
293309
- **uint16_t getAlertLimit()** returns the limit set by **setAlertLimit()**.
294310

295311

296-
| description alert register | value | a.k.a. |
297-
|:---------------------------|-------:| -------:|
298-
| INA226_SHUNT_OVER_VOLTAGE | 0x8000 | SOL |
299-
| INA226_SHUNT_UNDER_VOLTAGE | 0x4000 | SUL |
300-
| INA226_BUS_OVER_VOLTAGE | 0x2000 | BOL |
301-
| INA226_BUS_UNDER_VOLTAGE | 0x1000 | BUL |
302-
| INA226_POWER_OVER_LIMIT | 0x0800 | POL |
303-
| INA226_CONVERSION_READY | 0x0400 | |
312+
| description alert register | value | a.k.a. |
313+
|:-----------------------------|---------:| -------:|
314+
| INA226_SHUNT_OVER_VOLTAGE | 0x8000 | SOL |
315+
| INA226_SHUNT_UNDER_VOLTAGE | 0x4000 | SUL |
316+
| INA226_BUS_OVER_VOLTAGE | 0x2000 | BOL |
317+
| INA226_BUS_UNDER_VOLTAGE | 0x1000 | BUL |
318+
| INA226_POWER_OVER_LIMIT | 0x0800 | POL |
319+
| INA226_CONVERSION_READY | 0x0400 | |
304320

305321

306-
| description alert flags | value |
307-
|:-------------------------------|-------:|
308-
| INA226_ALERT_FUNCTION_FLAG | 0x0010 |
309-
| INA226_CONVERSION_READY_FLAG | 0x0008 |
310-
| INA226_MATH_OVERFLOW_FLAG | 0x0004 |
311-
| INA226_ALERT_POLARITY_FLAG | 0x0002 |
312-
| INA226_ALERT_LATCH_ENABLE_FLAG | 0x0001 |
322+
| description alert flags | value |
323+
|:---------------------------------|---------:|
324+
| INA226_ALERT_FUNCTION_FLAG | 0x0010 |
325+
| INA226_CONVERSION_READY_FLAG | 0x0008 |
326+
| INA226_MATH_OVERFLOW_FLAG | 0x0004 |
327+
| INA226_ALERT_POLARITY_FLAG | 0x0002 |
328+
| INA226_ALERT_LATCH_ENABLE_FLAG | 0x0001 |
313329

314330

315331
The alert line falls when alert is reached.

libraries/INA226/examples/INA226_demo_alert/INA226_demo_alert.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// URL: https://github.com/RobTillaart/INA226
66

77

8-
// EXPERIMENTAL CODE - NOT TESTED.
8+
// EXPERIMENTAL CODE - NOT TESTED.
99

1010

1111
#include "INA226.h"

libraries/INA226/examples/INA226_set_average/INA226_set_average.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void setup()
2929
Serial.println("could not connect. Fix and Reboot");
3030
}
3131
INA.setMaxCurrentShunt(1, 0.002);
32-
INA.setAverage(7); // <<<<<<<<<<<<<<<
32+
INA.setAverage(INA226_1024_SAMPLES); // <<<<<<<<<<<<<<<
3333
}
3434

3535

0 commit comments

Comments
 (0)