This driver is a clone of an early version of the Adafruit CircuitPython driver, when these were still readable and simple.
The only thing changed was the way of reading and writing to the I2C device.
ina = INA219(i2c, *, address=0x40)
Create an instance of the ina219 object.
Args:
* i2c: The I2C object used for communication.
* address: The I2C address. The default value is 0x40.
The INA219 device will be initialized with the range of 1A/32V.
Return the current though the shunt at the configured range.
Return the voltage between the shunt's V- connection and GND.
Return the voltage between the shunt's V+ and V- connections.
Set the measurement range to 32V and 2A.
Set the measurement range to 32V and 1A.
Set the measurement range to 16V and 400mA.
from machine import I2C
from ina219 import INA219
import time
# Depending on the port, the Pins for SDA and SCL must be specified.
# See the MicroPython documentation for your port.
# I2C requires pull-up resistors at SDA and SCL.
i2c = I2C(1)
ina = INA219(i2c)
set_calibration_32V_1A()
while True:
current = ina.current
voltage = ina.bus_voltage
print("{} mA {} V".format(current, voltage))
time.sleep(1)