#!/usr/bin/env python # -*- coding: utf-8 -*- # Test program to illustrate INA219 class usage import ina219 if __name__ == "__main__": # Connecting to INA219 in Debug mode chip = ina219.ina219(debug=True) # Perform a soft reset on chip chip.SoftReset() # Retrieve bus voltage chip.GetBusVoltage() # Retrieve shunt voltage chip.GetShuntVoltage() # Calibrate chip with an expected max current of 3.2A # and a shunt resistor or 0.1ohms chip.Calibrate(r_shunt=0.1, i_max=3.2) # Force INA219 to trigger a new measurement # (if configured in triggered mode) chip.TriggerMeasurement() # Retrieve calculated current chip.GetCurrent() # Retrieve calculated power chip.GetPower() # Configure chip using full parameters conf = chip.CONF_BRNG_32V | chip.CONF_PGA_DIV8 | chip.CONF_BADC_12BIT | \ chip.CONF_SADC_12BIT | chip.CONF_MODE_SHUNT_BUS_CONT chip.Configure(config=conf) # Configure chip by changing a single value # -> Set bus voltage range to 16V chip.Configure(single_value=chip.CONF_BRNG_16V, mask=chip.CONF_BRNG_MASK)