Skip to content

Commit cac3882

Browse files
committed
TI INA219 Library First Commit
1 parent 3021f08 commit cac3882

File tree

8 files changed

+869
-1
lines changed

8 files changed

+869
-1
lines changed

README.md

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,113 @@
11
# Root4root_INA219
2-
Library for Texas Instruments INA219 IC
2+
3+
##### Library for Texas Instruments INA219 IC - Bidirectional Current/Power Monitor
4+
---
5+
6+
### Quick Example:
7+
```cpp
8+
#include <Arduino.h>
9+
#include "Root4root_INA219.h"
10+
11+
Root4root_INA219 ina219; //0x40 address
12+
13+
void setup() {
14+
Serial.begin(9600);
15+
ina219.begin();
16+
}
17+
18+
void loop() {
19+
float busvoltage = 0;
20+
float current_mA = 0;
21+
22+
busvoltage = ina219.getBusVoltage_V();
23+
current_mA = ina219.getCurrent_mA();
24+
25+
Serial.println(busvoltage);
26+
Serial.println(current_mA);
27+
28+
delay(1000);
29+
}
30+
31+
```
32+
33+
### Advanced Usage:
34+
```cpp
35+
#include <Arduino.h>
36+
#include "Root4root_INA219.h"
37+
38+
Root4root_INA219 ina219(0x40);
39+
40+
void setup() {
41+
42+
//Max expected current 20A with 10 milliOhms shunt,
43+
//calculates calibration register value. 2000, 100 by default.
44+
ina219.begin(20000, 10);
45+
46+
//Change configuration register to fit your requirements.
47+
//Check Readme for more options, or read .h file
48+
ina219.changeConfig(INA219_CONFIG_SHUNT_ADC_RESOLUTION_12BIT_8S_4260US |
49+
INA219_CONFIG_BUS_VOLTAGE_RANGE_16V,
50+
INA219_CONFIG_SHUNT_ADC_RESOLUTION_MASK |
51+
INA219_CONFIG_BUS_VOLTAGE_RANGE_MASK);
52+
//Same as above:
53+
//ina219.changeConfig(0x0058, 0x2078);
54+
55+
56+
Serial.begin(9600);
57+
}
58+
59+
void loop() {
60+
Serial.println(ina219.getBusVoltage_V());
61+
Serial.println(ina219.getCurrent_mA());
62+
Serial.println("--------------------");
63+
64+
//ina219.getBusVoltage_mV();
65+
//ina219.getPower_mW();
66+
//ina219.getShuntVoltage_mV();
67+
68+
delay(1000);
69+
}
70+
71+
```
72+
73+
### Available Methods:
74+
```cpp
75+
//Constructor
76+
Root4root_INA219(uint8_t addr = INA219_ADDRESS, TwoWire *theWire = &Wire);
77+
78+
//DEFAULT_MAX_EXPECTED_CURRENT 2000 mA
79+
//DEFAULT_SHUNT_RESISTOR 100 mOhm
80+
void begin(uint16_t expected = DEFAULT_MAX_EXPECTED_CURRENT, uint8_t rshunt = DEFAULT_SHUNT_RESISTOR);
81+
82+
void setCalibration(uint16_t expected, uint8_t rshunt);
83+
84+
void changeConfig(uint16_t value, uint16_t mask); //See header file to findout config and masks constants.
85+
86+
uint16_t getBusVoltage_mV();
87+
float getBusVoltage_V();
88+
89+
float getShuntVoltage_mV();
90+
int16_t getShuntVoltage_raw(); //raw, shunt voltage register value
91+
92+
float getCurrent_mA();
93+
int16_t getCurrent_raw(); //raw, current register value (not in Amps)
94+
95+
float getPower_mW();
96+
int16_t getPower_raw(); //raw, power register value (not in Watts)
97+
98+
void powerSave(bool on);
99+
100+
void reset();
101+
102+
void trigger(); //For trigged measure mode
103+
104+
//!! Following methods are mainly used for testing purpouses:
105+
void readRegister(uint8_t reg, uint16_t *value);
106+
void writeRegister(uint8_t reg, uint16_t value);
107+
```
108+
109+
### License:
110+
MIT
111+
### Author:
112+
Paul aka root4root \<root4root at gmail dot com><br/>
113+
**Any comments/suggestions are welcomed.**

0 commit comments

Comments
 (0)