INA219 test.py

From Federal Burro of Information
Jump to navigationJump to search


#!/usr/bin/env python3
from ina219 import INA219
from ina219 import DeviceRangeError

SHUNT_OHMS = 0.1

def read():
  ina = INA219(SHUNT_OHMS,address=0x41)
  # ina.configure()
  ina.configure(ina.RANGE_16V, ina.GAIN_1_40MV)

  try:
    print("bus voltage {}V, Bus Current {}mA, Power {}mW, shunt v {} mV ".format(ina.voltage(),ina.current(),ina.power(),ina.shunt_voltage()))
    # print("Bus Current: {} mA, Power: {} mW".format(ina.current(),ina.power()))
    # print("Power: {} mW".format(ina.power()))
    print("Shunt voltage: {} mV".format(ina.shunt_voltage()))
  except DeviceRangeError as e:
    # Current out of device range with specified shunt resistor
    print(e)

if __name__ == "__main__":
  read()