parent
9753be900d
commit
d27900d91d
@ -1,40 +0,0 @@
|
||||
"""Sample code and test for adafruit_in219"""
|
||||
|
||||
import sys
|
||||
import board
|
||||
import busio
|
||||
from adafruit_extended_bus import ExtendedI2C as I2C
|
||||
from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219
|
||||
|
||||
if __name__ == "__main__":
|
||||
# print 'Length: ', len(sys.argv)
|
||||
|
||||
if (len(sys.argv)) > 1:
|
||||
# print("There are arguments!")
|
||||
# if (('a' == sys.argv[1]) or ('afsk' in sys.argv[1])):
|
||||
bus = int(sys.argv[1], base=10)
|
||||
if (len(sys.argv)) > 2:
|
||||
address = int(sys.argv[2], base=16)
|
||||
else:
|
||||
address = 0x40
|
||||
else:
|
||||
bus = 1
|
||||
address = 0x40
|
||||
|
||||
try:
|
||||
# Create library object using Extended Bus I2C port
|
||||
i2c_bus = I2C(bus) # 1 Device is /dev/i2c-1
|
||||
|
||||
ina219 = INA219(i2c_bus, address)
|
||||
|
||||
# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage
|
||||
ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S
|
||||
ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S
|
||||
# optional : change voltage range to 16V
|
||||
ina219.bus_voltage_range = BusVoltageRange.RANGE_16V
|
||||
|
||||
current = ina219.current # current in mA
|
||||
print("{:9.1f}".format(current))
|
||||
|
||||
except:
|
||||
print("0.0 Error")
|
||||
@ -1,62 +0,0 @@
|
||||
"""Sample code and test for adafruit_in219"""
|
||||
|
||||
import time
|
||||
import board
|
||||
import busio
|
||||
#import smbus
|
||||
#from adafruit_blinka.microcontroller.bcm283x import pin
|
||||
from adafruit_extended_bus import ExtendedI2C as I2C
|
||||
|
||||
from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219
|
||||
|
||||
#i2c_bus2 = smbus.SMBus(3) # 3
|
||||
#b1 = i2c_bus2.read_i2c_block_data(0x45, 0x01, 2)
|
||||
#print (b1)
|
||||
|
||||
#p = busio.I2C(scl, sda)
|
||||
#p = busio.I2C(pin.D1,pin.D0)
|
||||
#p = board.I2C(pin.D1,pin.D0)
|
||||
#p.deinit()
|
||||
|
||||
# Create library object using our Extended Bus I2C port
|
||||
i2c_bus = I2C(11) # 1 Device is /dev/i2c-1
|
||||
|
||||
|
||||
#i2c_bus = board.I2C()
|
||||
#i2c_bus = p
|
||||
|
||||
print(i2c_bus)
|
||||
|
||||
ina219 = INA219(i2c_bus, 0x45)
|
||||
|
||||
print("ina219 test")
|
||||
|
||||
# display some of the advanced field (just to test)
|
||||
print("Config register:")
|
||||
print(" bus_voltage_range: 0x%1X" % ina219.bus_voltage_range)
|
||||
print(" gain: 0x%1X" % ina219.gain)
|
||||
print(" bus_adc_resolution: 0x%1X" % ina219.bus_adc_resolution)
|
||||
print(" shunt_adc_resolution: 0x%1X" % ina219.shunt_adc_resolution)
|
||||
print(" mode: 0x%1X" % ina219.mode)
|
||||
print("")
|
||||
|
||||
# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage
|
||||
ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S
|
||||
ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S
|
||||
# optional : change voltage range to 16V
|
||||
ina219.bus_voltage_range = BusVoltageRange.RANGE_16V
|
||||
|
||||
# measure and display loop
|
||||
while True:
|
||||
bus_voltage = ina219.bus_voltage # voltage on V- (load side)
|
||||
shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt
|
||||
current = ina219.current # current in mA
|
||||
|
||||
# INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage
|
||||
print("PSU Voltage: {:6.3f} V".format(bus_voltage + shunt_voltage))
|
||||
print("Shunt Voltage: {:9.6f} V".format(shunt_voltage))
|
||||
print("Load Voltage: {:6.3f} V".format(bus_voltage))
|
||||
print("Current: {:9.1f} mA".format(current))
|
||||
print("")
|
||||
|
||||
time.sleep(2)
|
||||
@ -1,49 +0,0 @@
|
||||
"""Sample code and test for adafruit_in219"""
|
||||
|
||||
import time
|
||||
import board
|
||||
import smbus
|
||||
from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219
|
||||
|
||||
i2c_bus2 = smbus.SMBus(3)
|
||||
b1 = i2c_bus2.read_i2c_block_data(0x45, 0x01, 2)
|
||||
print (b1)
|
||||
|
||||
|
||||
i2c_bus = board.I2C()
|
||||
|
||||
print(i2c_bus)
|
||||
|
||||
ina219 = INA219(i2c_bus, 0x45)
|
||||
|
||||
print("ina219 test")
|
||||
|
||||
# display some of the advanced field (just to test)
|
||||
print("Config register:")
|
||||
print(" bus_voltage_range: 0x%1X" % ina219.bus_voltage_range)
|
||||
print(" gain: 0x%1X" % ina219.gain)
|
||||
print(" bus_adc_resolution: 0x%1X" % ina219.bus_adc_resolution)
|
||||
print(" shunt_adc_resolution: 0x%1X" % ina219.shunt_adc_resolution)
|
||||
print(" mode: 0x%1X" % ina219.mode)
|
||||
print("")
|
||||
|
||||
# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage
|
||||
ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S
|
||||
ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S
|
||||
# optional : change voltage range to 16V
|
||||
ina219.bus_voltage_range = BusVoltageRange.RANGE_16V
|
||||
|
||||
# measure and display loop
|
||||
while True:
|
||||
bus_voltage = ina219.bus_voltage # voltage on V- (load side)
|
||||
shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt
|
||||
current = ina219.current # current in mA
|
||||
|
||||
# INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage
|
||||
print("PSU Voltage: {:6.3f} V".format(bus_voltage + shunt_voltage))
|
||||
print("Shunt Voltage: {:9.6f} V".format(shunt_voltage))
|
||||
print("Load Voltage: {:6.3f} V".format(bus_voltage))
|
||||
print("Current: {:9.6f} A".format(current / 1000))
|
||||
print("")
|
||||
|
||||
time.sleep(2)
|
||||
@ -1,65 +0,0 @@
|
||||
from time import sleep
|
||||
from ina219 import INA219
|
||||
|
||||
ina1 = INA219(shunt_ohms=0.1,
|
||||
max_expected_amps = 0.6,
|
||||
address=0x40)
|
||||
|
||||
ina1.configure(voltage_range=ina1.RANGE_16V,
|
||||
gain=ina1.GAIN_AUTO,
|
||||
bus_adc=ina1.ADC_128SAMP,
|
||||
shunt_adc=ina1.ADC_128SAMP)
|
||||
|
||||
ina2 = INA219(shunt_ohms=0.1,
|
||||
max_expected_amps = 0.6,
|
||||
address=0x41)
|
||||
|
||||
ina2.configure(voltage_range=ina2.RANGE_16V,
|
||||
gain=ina2.GAIN_AUTO,
|
||||
bus_adc=ina2.ADC_128SAMP,
|
||||
shunt_adc=ina2.ADC_128SAMP)
|
||||
|
||||
ina3 = INA219(shunt_ohms=0.1,
|
||||
max_expected_amps = 0.6,
|
||||
address=0x44)
|
||||
|
||||
ina3.configure(voltage_range=ina3.RANGE_16V,
|
||||
gain=ina3.GAIN_AUTO,
|
||||
bus_adc=ina3.ADC_128SAMP,
|
||||
shunt_adc=ina3.ADC_128SAMP)
|
||||
|
||||
ina4 = INA219(shunt_ohms=0.1,
|
||||
max_expected_amps = 0.6,
|
||||
address=0x45)
|
||||
|
||||
ina4.configure(voltage_range=ina4.RANGE_16V,
|
||||
gain=ina4.GAIN_AUTO,
|
||||
bus_adc=ina4.ADC_128SAMP,
|
||||
shunt_adc=ina4.ADC_128SAMP)
|
||||
|
||||
while 1:
|
||||
v1 = ina1.voltage()
|
||||
i1 = ina1.current()
|
||||
p1 = ina1.power()
|
||||
print('1 {0:0.1f}V {1:0.1f}mA'.format(v1, i1))
|
||||
print('{0:0.1f} Watts\n\n'.format(p1/1000))
|
||||
|
||||
v2 = ina2.voltage()
|
||||
i2 = ina2.current()
|
||||
p2 = ina2.power()
|
||||
print('2 {0:0.1f}V {1:0.1f}mA'.format(v2, i2))
|
||||
print('{0:0.1f} Watts\n\n'.format(p2/1000))
|
||||
|
||||
v3 = ina3.voltage()
|
||||
i3 = ina3.current()
|
||||
p3 = ina3.power()
|
||||
print('3 {0:0.1f}V {1:0.1f}mA'.format(v3, i3))
|
||||
print('{0:0.1f} Watts\n\n'.format(p3/1000))
|
||||
|
||||
v4 = ina4.voltage()
|
||||
i4 = ina4.current()
|
||||
p4 = ina4.power()
|
||||
print('4 {0:0.1f}V {1:0.1f}mA'.format(v4, i4))
|
||||
print('{0:0.1f} Watts\n\n\n'.format(p4/1000))
|
||||
|
||||
sleep(1)
|
||||
@ -1,87 +0,0 @@
|
||||
SHUNT_OHMS = 0.01
|
||||
MAX_EXPECTED_AMPS = 2.5
|
||||
SHUNT_OHMS45 = 0.1
|
||||
MAX_EXPECTED_AMPS45 = 0.6
|
||||
ina40v = 0
|
||||
ina40i = 0
|
||||
ina40p = 0
|
||||
ina41v = 0
|
||||
ina41i = 0
|
||||
ina41p = 0
|
||||
ina44v = 0
|
||||
ina44i = 0
|
||||
ina44p = 0
|
||||
ina45v = 0
|
||||
ina45i = 0
|
||||
ina45p = 0
|
||||
ina4av = 0
|
||||
ina4ai = 0
|
||||
ina4ap = 0
|
||||
|
||||
FAIL = -1
|
||||
|
||||
try:
|
||||
from ina219 import INA219
|
||||
from ina219 import DeviceRangeError
|
||||
INA219DISABLE=-1
|
||||
except:
|
||||
INA219DISABLE=1
|
||||
|
||||
if INA219DISABLE !=1:
|
||||
try:
|
||||
ina40 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x40)
|
||||
ina40.wake();
|
||||
ina40.configure(ina40.RANGE_16V)
|
||||
ina40.busnum = 0;
|
||||
ina40v = ina40.voltage()
|
||||
ina40i = ina40.current()
|
||||
ina40p = ina40.power()
|
||||
ina40.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina41 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x41)
|
||||
ina41.wake();
|
||||
ina41.configure(ina41.RANGE_16V)
|
||||
ina41.busnum = 1;
|
||||
ina41v = ina41.voltage()
|
||||
ina41i = ina41.current()
|
||||
ina41p = ina41.power()
|
||||
ina41.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina44 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x44)
|
||||
ina44.wake();
|
||||
ina44.configure(ina44.RANGE_16V)
|
||||
ina44.busnum = 1;
|
||||
ina44v = ina44.voltage()
|
||||
ina44i = ina44.current()
|
||||
ina44p = ina44.power()
|
||||
ina44.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina45 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x45)
|
||||
ina45.wake();
|
||||
ina45.configure(ina45.RANGE_16V)
|
||||
ina45.busnum = 1;
|
||||
ina45v = ina45.voltage()
|
||||
ina45i = ina45.current()
|
||||
ina45p = ina45.power()
|
||||
ina45.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina4a = INA219(SHUNT_OHMS, MAX_EXPECTED_AMPS, 0x4a)
|
||||
ina4a.wake();
|
||||
ina4a.configure(ina4a.RANGE_16V)
|
||||
ina4a.busnum = 1;
|
||||
ina4av = ina4a.voltage()
|
||||
ina4ai = ina4a.current()
|
||||
ina4ap = ina4a.power()
|
||||
ina4a.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
print ina40v, ina40i, ina40p, ina41v, ina41i, ina41p, ina44v, ina44i, ina44p, ina45v, ina45i, ina45p, ina4av, ina4ai, ina4ap
|
||||
|
||||
@ -1,94 +0,0 @@
|
||||
import time
|
||||
|
||||
SHUNT_OHMS = 0.01
|
||||
MAX_EXPECTED_AMPS = 2.5
|
||||
SHUNT_OHMS45 = 0.1
|
||||
MAX_EXPECTED_AMPS45 = 0.6
|
||||
ina40v = 0
|
||||
ina40i = 0
|
||||
ina40p = 0
|
||||
ina41v = 0
|
||||
ina41i = 0
|
||||
ina41p = 0
|
||||
ina44v = 0
|
||||
ina44i = 0
|
||||
ina44p = 0
|
||||
ina45v = 0
|
||||
ina45i = 0
|
||||
ina45p = 0
|
||||
ina4av = 0
|
||||
ina4ai = 0
|
||||
ina4ap = 0
|
||||
|
||||
FAIL = -1
|
||||
|
||||
try:
|
||||
from ina219 import INA219
|
||||
from ina219 import DeviceRangeError
|
||||
INA219DISABLE=-1
|
||||
except:
|
||||
INA219DISABLE=1
|
||||
|
||||
print "+X v\t+X i\t+X p\t+Y v\t+Y i\t+Y p\t+Z v\t+Z i\t+Z p\tVbatt\tibatt\tpbatt\tV5\ti5\tp5\t+X v\t+X i\t+X p\t"
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
if INA219DISABLE !=1:
|
||||
try:
|
||||
ina40 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x40)
|
||||
ina40.wake();
|
||||
ina40.configure(ina40.RANGE_16V)
|
||||
ina40.busnum = 0;
|
||||
ina40v = ina40.voltage()
|
||||
ina40i = ina40.current()
|
||||
ina40p = ina40.power()
|
||||
ina40.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina41 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x41)
|
||||
ina41.wake();
|
||||
ina41.configure(ina41.RANGE_16V)
|
||||
ina41.busnum = 1;
|
||||
ina41v = ina41.voltage()
|
||||
ina41i = ina41.current()
|
||||
ina41p = ina41.power()
|
||||
ina41.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina44 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x44)
|
||||
ina44.wake();
|
||||
ina44.configure(ina44.RANGE_16V)
|
||||
ina44.busnum = 1;
|
||||
ina44v = ina44.voltage()
|
||||
ina44i = ina44.current()
|
||||
ina44p = ina44.power()
|
||||
|
||||
ina44.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina45 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x45)
|
||||
ina45.wake();
|
||||
ina45.configure(ina45.RANGE_16V)
|
||||
ina45.busnum = 1;
|
||||
ina45v = ina45.voltage()
|
||||
ina45i = ina45.current()
|
||||
ina45p = ina45.power()
|
||||
ina45.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina4a = INA219(SHUNT_OHMS, MAX_EXPECTED_AMPS, 0x4a)
|
||||
ina4a.wake();
|
||||
ina4a.configure(ina4a.RANGE_16V)
|
||||
ina4a.busnum = 1;
|
||||
ina4av = ina4a.voltage()
|
||||
ina4ai = ina4a.current()
|
||||
ina4ap = ina4a.power()
|
||||
ina4a.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
print ina40v, "\t", ina40i,"\t", ina40p,"\t", ina41v,"\t", ina41i,"\t", ina41p,"\t", ina44v,"\t", ina44i,"\t", ina44p,"\t", ina45v,"\t", ina45i,"\t", ina45p,"\t", ina4av,"\t", ina4ai,"\t", ina4ap
|
||||
|
||||
@ -1,139 +0,0 @@
|
||||
SHUNT_OHMS = 0.01
|
||||
MAX_EXPECTED_AMPS = 2.5
|
||||
SHUNT_OHMS45 = 0.1
|
||||
MAX_EXPECTED_AMPS45 = 0.6
|
||||
ina40v = 0
|
||||
ina40i = 0
|
||||
ina40p = 0
|
||||
ina41v = 0
|
||||
ina41i = 0
|
||||
ina41p = 0
|
||||
ina44v = 0
|
||||
ina44i = 0
|
||||
ina44p = 0
|
||||
ina45v = 0
|
||||
ina45i = 0
|
||||
ina45p = 0
|
||||
ina403v = 0
|
||||
ina403i = 0
|
||||
ina403p = 0
|
||||
ina413v = 0
|
||||
ina413i = 0
|
||||
ina413p = 0
|
||||
ina443v = 0
|
||||
ina443i = 0
|
||||
ina443p = 0
|
||||
ina453v = 0
|
||||
ina453i = 0
|
||||
ina453p = 0
|
||||
FAIL = -1
|
||||
|
||||
try:
|
||||
from ina219 import INA219
|
||||
from ina219 import DeviceRangeError
|
||||
INA219DISABLE=-1
|
||||
|
||||
except:
|
||||
INA219DISABLE=1
|
||||
print"python package ina219 import failed! Install by typing: sudo pip install pi-ina219==1.1.0"
|
||||
|
||||
if INA219DISABLE !=1:
|
||||
try:
|
||||
ina40 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x40)
|
||||
ina40.wake();
|
||||
ina40.configure(ina40.RANGE_16V)
|
||||
ina40.busnum = 0;
|
||||
ina40v = ina40.voltage()
|
||||
ina40i = ina40.current()
|
||||
ina40p = ina40.power()
|
||||
ina40.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina41 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x41)
|
||||
ina41.wake();
|
||||
ina41.configure(ina41.RANGE_16V)
|
||||
ina41.busnum = 1;
|
||||
ina41v = ina41.voltage()
|
||||
ina41i = ina41.current()
|
||||
ina41p = ina41.power()
|
||||
ina41.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina44 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x44)
|
||||
ina44.wake();
|
||||
ina44.configure(ina44.RANGE_16V)
|
||||
ina44.busnum = 1;
|
||||
ina44v = ina44.voltage()
|
||||
ina44i = ina44.current()
|
||||
ina44p = ina44.power()
|
||||
ina44.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina45 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x45)
|
||||
ina45.wake();
|
||||
ina45.configure(ina45.RANGE_16V)
|
||||
ina45.busnum = 1;
|
||||
ina45v = ina45.voltage()
|
||||
ina45i = ina45.current()
|
||||
ina45p = ina45.power()
|
||||
ina45.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina403 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x40)
|
||||
ina403.wake();
|
||||
ina403.configure(ina403.RANGE_16V)
|
||||
ina403.busnum = 3;
|
||||
ina403v = ina403.voltage()
|
||||
ina403i = ina403.current()
|
||||
ina403p = ina403.power()
|
||||
ina403.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina413 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x41)
|
||||
ina413.wake();
|
||||
ina413.configure(ina413.RANGE_16V)
|
||||
ina413.busnum = 3;
|
||||
ina413v = ina413.voltage()
|
||||
ina413i = ina413.current()
|
||||
ina413p = ina413.power()
|
||||
ina413.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina443 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x44)
|
||||
ina443.wake();
|
||||
ina443.configure(ina443.RANGE_16V)
|
||||
ina443.busnum = 3;
|
||||
ina443v = ina443.voltage()
|
||||
ina443i = ina443.current()
|
||||
ina443p = ina443.power()
|
||||
ina443.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
try:
|
||||
ina453 = INA219(SHUNT_OHMS45, MAX_EXPECTED_AMPS45, 0x45)
|
||||
ina453.wake();
|
||||
ina453.configure(ina453.RANGE_16V)
|
||||
ina453.busnum = 3;
|
||||
ina453v = ina453.voltage()
|
||||
ina453i = ina453.current()
|
||||
ina453p = ina453.power()
|
||||
ina453.sleep();
|
||||
except:
|
||||
FAIL = 1
|
||||
if INA219DISABLE !=1:
|
||||
print
|
||||
print "+X (0x40) v=",ina40v, "V i=", ina40i, "mA p=", ina40p, "mW "
|
||||
print "+Y (0x41) v=",ina41v, "V i=", ina41i, "mA p=", ina41p, "mW "
|
||||
print "5V Supply (0x44) v=",ina44v, "V i=", ina44i, "mA p=", ina44p, "mW "
|
||||
print "Battery (0x45) v=",ina45v, "V i=", ina45i, "mA p=", ina45p, "mW "
|
||||
print "+Z (0x40 3) v=",ina403v, "V i=", ina403i, "mA p=", ina403p, "mW "
|
||||
print "-X (0x41 3) v=",ina413v, "V i=", ina413i, "mA p=", ina413p, "mW "
|
||||
print "-Y (0x44 3) v=",ina443v, "V i=", ina443i, "mA p=", ina443p, "mW "
|
||||
print "-Z (0x45 3) v=",ina453v, "V i=", ina453i, "mA p=", ina453p, "mW "
|
||||
print
|
||||
@ -1,44 +0,0 @@
|
||||
"""Sample code and test for adafruit_in219"""
|
||||
|
||||
import sys
|
||||
import board
|
||||
import busio
|
||||
from adafruit_extended_bus import ExtendedI2C as I2C
|
||||
from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219
|
||||
|
||||
if __name__ == "__main__":
|
||||
# print 'Length: ', len(sys.argv)
|
||||
|
||||
if (len(sys.argv)) > 1:
|
||||
# print("There are arguments!")
|
||||
# if (('a' == sys.argv[1]) or ('afsk' in sys.argv[1])):
|
||||
bus = int(sys.argv[1], base=10)
|
||||
if (len(sys.argv)) > 2:
|
||||
address = int(sys.argv[2], base=16)
|
||||
else:
|
||||
address = 0x40
|
||||
else:
|
||||
bus = 1
|
||||
address = 0x40
|
||||
|
||||
try:
|
||||
# Create library object using Extended Bus I2C port
|
||||
i2c_bus = I2C(bus) # 1 Device is /dev/i2c-1
|
||||
ina219 = INA219(i2c_bus, address)
|
||||
|
||||
# print("ina219 test")
|
||||
|
||||
# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage
|
||||
ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S
|
||||
ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_1S # 32S
|
||||
# optional : change voltage range to 16V
|
||||
ina219.bus_voltage_range = BusVoltageRange.RANGE_16V
|
||||
|
||||
bus_voltage = ina219.bus_voltage # voltage on V- (load side)
|
||||
shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt
|
||||
# current = ina219.current # current in mA
|
||||
# INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage
|
||||
print("{:6.3f}".format(bus_voltage + shunt_voltage))
|
||||
|
||||
except:
|
||||
print("0.0 Error")
|
||||
Loading…
Reference in new issue