Version 1.1.0 of the INA219 library is now available with three major enhancements:
- Support for automatic gain adjustment, this makes getting valid readings over the full current/power range of the device very easy. Automatic gain is the default mode.
- The calibration calculation has been altered so that current overflow conditions are always detected so its no longer possible to obtain invalid current, power or shunt voltage readings.
- This version (v1.1.0) of the library is available in the PyPI Python Package Index (https://pypi.python.org/pypi/pi-ina219), which allows a more standard installation process.
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
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.