Skip to content
Chris Borrill edited this page May 6, 2023 · 12 revisions

Welcome to the pi_ina219 wiki!

Trouble Shooting

On Raspbian Jessie this error can occur when installing:

setuptools_scm.version.SetuptoolsOutdatedWarning: your setuptools is too old (<12)

This can be fixed with:

sudo pip install -U pip

Compatibility

  • Raspberry Pi 2
  • Raspberry Pi 3
  • Raspberry Pi 4
  • Raspberry Pi Zero
  • LoPy4 - tested by a user, probably will be compatible with all Pycom modules, including WiPy.
  • Beagle Bone Black - tested by a user.

Continuous Integration

See Github Actions: https://github.com/chrisb2/pi_ina219/actions

Code Coverage Report

A code coverage report of the unit tests is automatically generated by Travis CI, see https://codecov.io/gh/chrisb2/pi_ina219

Example of Auto Gain in Operation

The following Python script demonstrates auto gain in operation.

#!/usr/bin/env python

import time
import logging
from ina219 import INA219
from ina219 import DeviceRangeError

SHUNT_OHMS = 0.1


def read():
    ina = INA219(SHUNT_OHMS, log_level=logging.INFO)
    ina.configure()

    while True:
        v = ina.voltage()
        a = 0.0
        w = 0.0
        s = 0.0
        try:
            a = ina.current() / 1000
            w = ina.power() / 1000
            s = ina.shunt_voltage()
        except DeviceRangeError as e:
            print e
            a = 0.0
            w = 0.0
            s = 0.0

        print ("%.2fV, %.3fA, %.3fW, %.3fmV" % (v, a, w, s))
        time.sleep(1)


if __name__ == "__main__":
    read()

As the voltage was increased, the INFO log output, shows the gain starting at 40mV, then increasing to 80mV, 160mV, 320mV and finally exceeding the maximum range of the device. When the voltage is then reduce, valid readings are once again obtained.

2017-03-04 19:40:36,512 - INFO - INA219 gain set to 0.04V
2017-03-04 19:40:36,515 - INFO - INA219 calibrate called with: bus max volts: 32V, max shunt volts: 0.04V
2017-03-04 19:40:36,518 - INFO - INA219 max possible current: 0.400A
2017-03-04 19:40:36,520 - INFO - INA219 current LSB: 1.220e-05 A/bit
2017-03-04 19:40:36,523 - INFO - INA219 power LSB: 2.439e-04 W/bit
2017-03-04 19:40:36,526 - INFO - INA219 max current before overflow: 0.3996A
2017-03-04 19:40:36,528 - INFO - INA219 max shunt voltage before overflow: 39.9598mV
2017-03-04 19:40:36,531 - INFO - INA219 calibration: 0x8333 (33587)
0.00V, 0.027A, 0.000W, 2.700mV
0.00V, 0.027A, 0.000W, 2.710mV
0.00V, 0.028A, 0.000W, 2.800mV
0.00V, 0.032A, 0.000W, 3.210mV
0.00V, 0.034A, 0.000W, 3.460mV
0.01V, 0.040A, 0.000W, 3.980mV
0.11V, 0.239A, 0.026W, 24.290mV
0.18V, 0.384A, 0.071W, 38.380mV
2017-03-04 19:40:47,699 - INFO - INA219 Current overflow detected - attempting to increase gain
2017-03-04 19:40:47,705 - INFO - INA219 gain is currently: 0.04V
2017-03-04 19:40:47,708 - INFO - INA219 calibrate called with: bus max volts: 32V, max shunt volts: 0.08V
2017-03-04 19:40:47,712 - INFO - INA219 max possible current: 0.800A
2017-03-04 19:40:47,715 - INFO - INA219 current LSB: 2.439e-05 A/bit
2017-03-04 19:40:47,719 - INFO - INA219 power LSB: 4.878e-04 W/bit
2017-03-04 19:40:47,721 - INFO - INA219 max current before overflow: 0.7992A
2017-03-04 19:40:47,724 - INFO - INA219 max shunt voltage before overflow: 79.9195mV
2017-03-04 19:40:47,727 - INFO - INA219 calibration: 0x4199 (16793)
2017-03-04 19:40:47,735 - INFO - INA219 gain set to: 0.08V
0.21V, 0.439A, 0.095W, 44.030mV
0.23V, 0.459A, 0.109W, 45.940mV
0.29V, 0.560A, 0.166W, 56.350mV
2017-03-04 19:40:50,790 - INFO - INA219 Current overflow detected - attempting to increase gain
2017-03-04 19:40:50,795 - INFO - INA219 gain is currently: 0.08V
2017-03-04 19:40:50,799 - INFO - INA219 calibrate called with: bus max volts: 32V, max shunt volts: 0.16V
2017-03-04 19:40:50,803 - INFO - INA219 max possible current: 1.600A
2017-03-04 19:40:50,806 - INFO - INA219 current LSB: 4.878e-05 A/bit
2017-03-04 19:40:50,810 - INFO - INA219 power LSB: 9.756e-04 W/bit
2017-03-04 19:40:50,814 - INFO - INA219 max current before overflow: 1.5984A
2017-03-04 19:40:50,817 - INFO - INA219 max shunt voltage before overflow: 159.8390mV
2017-03-04 19:40:50,821 - INFO - INA219 calibration: 0x20cc (8396)
2017-03-04 19:40:50,830 - INFO - INA219 gain set to: 0.16V
0.50V, 0.864A, 0.448W, 86.790mV
0.64V, 0.934A, 0.594W, 93.390mV
0.76V, 1.014A, 0.776W, 101.430mV
0.93V, 1.052A, 0.977W, 105.270mV
0.99V, 1.074A, 1.061W, 107.390mV
1.16V, 1.176A, 1.370W, 117.800mV
1.45V, 1.257A, 1.825W, 125.740mV
1.66V, 1.351A, 2.249W, 135.260mV
1.87V, 1.382A, 2.576W, 138.210mV
2.08V, 1.443A, 3.002W, 144.350mV
2.45V, 1.565A, 3.833W, 156.650mV
2017-03-04 19:41:07,085 - INFO - INA219 Current overflow detected - attempting to increase gain
2017-03-04 19:41:07,090 - INFO - INA219 gain is currently: 0.16V
2017-03-04 19:41:07,094 - INFO - INA219 calibrate called with: bus max volts: 32V, max shunt volts: 0.32V
2017-03-04 19:41:07,098 - INFO - INA219 max possible current: 3.200A
2017-03-04 19:41:07,101 - INFO - INA219 current LSB: 9.756e-05 A/bit
2017-03-04 19:41:07,105 - INFO - INA219 power LSB: 1.951e-03 W/bit
2017-03-04 19:41:07,109 - INFO - INA219 max current before overflow: 3.1968A
2017-03-04 19:41:07,113 - INFO - INA219 max shunt voltage before overflow: 319.6780mV
2017-03-04 19:41:07,117 - INFO - INA219 calibration: 0x1066 (4198)
2017-03-04 19:41:07,126 - INFO - INA219 gain set to: 0.32V
2.70V, 1.625A, 4.398W, 162.430mV
3.07V, 1.713A, 5.253W, 171.410mV
3.66V, 1.892A, 6.944W, 189.360mV
4.20V, 2.018A, 8.494W, 201.850mV
4.64V, 2.105A, 9.754W, 210.580mV
5.28V, 2.266A, 11.977W, 226.570mV
5.83V, 2.374A, 13.846W, 237.460mV
6.32V, 2.480A, 15.688W, 248.150mV
6.92V, 2.604A, 18.053W, 260.710mV
7.76V, 2.761A, 21.442W, 276.190mV
8.21V, 2.844A, 23.360W, 284.530mV
8.92V, 2.971A, 26.519W, 297.240mV
9.15V, 3.009A, 27.532W, 300.980mV
10.02V, 3.159A, 31.666W, 316.070mV
10.27V, 3.197A, 32.835W, 319.540mV
2017-03-04 19:41:32,538 - INFO - INA219 Current overflow detected - attempting to increase gain
2017-03-04 19:41:32,542 - INFO - INA219 gain is currently: 0.32V
2017-03-04 19:41:32,544 - INFO - INA219 Device limit reach, gain cannot be increased
Current out of range (overflow), for gain 0.32V, device limit reached
10.28V, 0.000A, 0.000W, 0.000mV
2017-03-04 19:41:33,556 - INFO - INA219 Current overflow detected - attempting to increase gain
2017-03-04 19:41:33,560 - INFO - INA219 gain is currently: 0.32V
2017-03-04 19:41:33,563 - INFO - INA219 Device limit reach, gain cannot be increased
Current out of range (overflow), for gain 0.32V, device limit reached
10.30V, 0.000A, 0.000W, 0.000mV
9.12V, 2.979A, 27.167W, 297.880mV
8.56V, 2.892A, 24.751W, 289.190mV
8.20V, 2.819A, 23.100W, 281.850mV
8.04V, 2.797A, 22.503W, 279.720mV
8.04V, 2.798A, 22.523W, 279.850mV
7.70V, 2.727A, 20.991W, 272.620mV
7.52V, 2.697A, 20.285W, 269.750mV
7.47V, 2.690A, 20.100W, 269.010mV
7.47V, 2.690A, 20.105W, 269.120mV
Clone this wiki locally