Close

Automatic Gain and Current Overflow Detection

A project log for Raspberry Pi INA219 voltage/current sensor library

Python library for Raspberry Pi which provides an easy to use interface for the INA219 voltage and current sensor from Texas Instruments.

chrisChris 03/02/2017 at 07:430 Comments

Version 1.1.0 of the INA219 library is now available with three major enhancements:

At its simplest the following code is all thats required to get readings for the full supported current/power range of the device. See the README for further details.

#!/usr/bin/env python
from ina219 import INA219
from ina219 import DeviceRangeError
SHUNT_OHMS = 0.1


def read():
   ina = INA219(SHUNT_OHMS)
   ina.configure()
   print "Bus Voltage: %.3f V" % ina.voltage()
   try:
       print "Bus Current: %.3f mA" % ina.current()
       print "Power: %.3f mW" % ina.power()
       print "Shunt voltage: %.3f mV" % ina.shunt_voltage()
   except DeviceRangeError as e:
       # Current out of device range with specified shunt resister
       print e


if __name__ == "__main__":
   read()

Discussions