# Test program to illustrate uINA219 class usage import uina219 import machine # Example using an ESP8266 (ESP-01) i2c = machine.I2C(freq=400000, scl=machine.Pin(0),sda=machine.Pin(2)) # Connecting to INA219 chip = uina219.uina219(i2c) # 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)