Datasheet
You can also download the adafruit_ina219.mpy from its releases page on Github.
Before continuing make sure your board's lib folder or root filesystem has
the adafruit_ina219.mpy, and adafruit_bus_device files and folders copied over.
Next connect to the board's serial REPL so you are at the CircuitPython >>> prompt.
Usage
To demonstrate the usage of the sensor we'll initialize it and read the current and more from the board's Python REPL.
Run the following code to import the necessary modules and initialize the I2C connection with the sensor:
Remember if you're using a board that doesn't support hardware I2C (like the ESP8266) you need to use
the bitbangio module instead:
Now you're ready to read values from the sensor using any of these functions:
get_shunt_voltage_mV() - The shunt voltage in millivolts.
get_bus_voltage_V() - The bus voltage in volts.
get_current_mA() - The current in milliamps.
That's all there is to using the INA219 with CircuitPython!
Here's a full example to print the voltage and current every second. Save this as main.py on your board's filesystem
and check the output from the serial REPL. Also remember if you're using the ESP8266 you need to change the
initialization to use the bitbangio module!
import board
import busio
import adafruit_ina219
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_ina219.INA219(i2c)
import board
import bitbangio
import adafruit_ina219
i2c = bitbangio.I2C(board.SCL, board.SDA)
sensor = adafruit_ina219.INA219(i2c)
print('Shunt voltage: {} mV'.format(sensor.get_shunt_voltage_mV()))
print('Bus voltage: {} V'.format(sensor.get_bus_voltage_V()))
print('Current: {} mA'.format(sensor.get_current_mA()))
© Adafruit Industries https://learn.adafruit.com/adafruit-ina219-current-sensor-breakout Page 16 of 19