This is a modified library for the INA219 that can handle a 0.01 ohm resistor instead of a 0.1 Ohm resistor. This allows it to read up to 32A instead of 3.2A.

Dependents:   Hybrid_Supercapacitor_Car_Battery_Monitoring

Fork of INA219 by Components

Revision:
1:8ccc8e47e3d5
Parent:
0:eee9c8ba72ff
--- a/INA219.cpp	Thu Aug 28 10:32:20 2014 +0000
+++ b/INA219.cpp	Tue Dec 26 21:28:13 2017 +0000
@@ -51,7 +51,7 @@
 void INA219::calibrate_16v_400mA()
 {
     // ASSUMING A 0.1 OHM RESISTOR!
-    write_register_u16(INA219_REG_CALIBRATION, 8192);
+    write_register_u16(INA219_REG_CALIBRATION, 7600);
 
     // Write to config register
 
@@ -67,13 +67,13 @@
         resolution_mask = INA219_CONFIG_BADCRES_9BIT | INA219_CONFIG_SADCRES_9BIT_1S_84US;
 
     write_register_u16(INA219_REG_CONFIG, INA219_CONFIG_BVOLTAGERANGE_16V |
-                    INA219_CONFIG_GAIN_1_40MV |
+                    INA219_CONFIG_GAIN_8_320MV |
                     resolution_mask |
                     INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS);
                     
     // Set current divider
-    current_divider = 20;
-    power_divider = 1;
+    current_divider = 2;
+    power_divider = 10;
 }
 
 int16_t INA219::read_current_raw()
@@ -85,4 +85,24 @@
 {
     float raw_current = read_current_raw();
     return raw_current / current_divider;
+}
+int16_t INA219::read_bus_voltage_raw()
+{
+    return ((int16_t)read_register_u16(INA219_REG_BUSVOLTAGE)>>3)*4;
+}
+ 
+float INA219::read_bus_voltage()
+{
+    float raw_voltage = read_bus_voltage_raw();
+    return raw_voltage*0.001;
+}
+int16_t INA219::read_power_raw()
+{
+    return ((int16_t)read_register_u16(INA219_REG_POWER)>>3)*4;
+}
+ 
+float INA219::read_power_mW()
+{
+    float raw_mW = read_power_raw();
+    return raw_mW*2.000;
 }
\ No newline at end of file