pull/126/head
alanbjohnston 5 years ago committed by GitHub
parent d0bef1aa2a
commit 526439b813
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,32 +30,32 @@ if __name__ == "__main__":
# config # config
for x in buses: # for x in buses:
try: # try:
i2c_bus = I2C(x) # Device is /dev/i2c-x # i2c_bus = I2C(x) # Device is /dev/i2c-x
for y in addresses: # for y in addresses:
# print(x,y) # print(x,y)
try: # try:
# Create library object using Extended Bus I2C port # Create library object using Extended Bus I2C port
# print("bus: ", x, " addr: ", y) # print("bus: ", x, " addr: ", y)
if x == 0 and y == 0x45: # if x == 0 and y == 0x45:
# print("Reading INA219 in MoPower Board") # print("Reading INA219 in MoPower Board")
i2c_bus = I2C(1) # i2c_bus = I2C(1)
ina219 = INA219(i2c_bus, 0x4a) # ina219 = INA219(i2c_bus, 0x4a)
else: # else:
ina219 = INA219(i2c_bus, y) # ina219 = INA219(i2c_bus, y)
# print("ina219 test") # print("ina219 test")
# print("Configuring") # print("Configuring")
# optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage # optional : change configuration to use 32 samples averaging for both bus voltage and shunt voltage
ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S # ina219.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S
ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S # ina219.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S
# optional : change voltage range to 16V # optional : change voltage range to 16V
ina219.bus_voltage_range = BusVoltageRange.RANGE_16V # ina219.bus_voltage_range = BusVoltageRange.RANGE_16V
except: # except:
print("Python Error 2", file=sys.stderr, flush=True) # print("Python Error 2", file=sys.stderr, flush=True)
except: # except:
print("Python Error 1", file=sys.stderr, flush=True) # print("Python Error 1", file=sys.stderr, flush=True)
# No try checking yet # No try checking yet
# if buses[0] == 0 and addresses[0] == 0x45: # if buses[0] == 0 and addresses[0] == 0x45:
@ -65,23 +65,35 @@ if __name__ == "__main__":
try: try:
i2c_one = I2C(buses[0]) i2c_one = I2C(buses[0])
try: try:
i2c_one = INA219(i2c_one, addresses[0]) ina219_one = INA219(i2c_one, addresses[0])
i2c_one.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S ina219_one.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S
i2c_one.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S ina219_one.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S
i2c_one.bus_voltage_range = BusVoltageRange.RANGE_16V ina219_one.bus_voltage_range = BusVoltageRange.RANGE_16V
oneZero = 1 one = 1
except: except:
print("Python Error 3", file=sys.stderr, flush=True) print("Python Error 3", file=sys.stderr, flush=True)
try: try:
ina219_two = INA219(i2c_one, addresses[1]) ina219_two = INA219(i2c_one, addresses[1])
ina219_two.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S
ina219_two.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S
ina219_two.bus_voltage_range = BusVoltageRange.RANGE_16V
two = 1
except: except:
print("Python Error 3", file=sys.stderr, flush=True) print("Python Error 3", file=sys.stderr, flush=True)
try: try:
ina219_three = INA219(i2c_one, addresses[2]) ina219_three = INA219(i2c_one, addresses[2])
ina219_three.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S
ina219_three.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S
ina219_three.bus_voltage_range = BusVoltageRange.RANGE_16V
three = 1
except: except:
print("Python Error 3", file=sys.stderr, flush=True) print("Python Error 3", file=sys.stderr, flush=True)
try: try:
ina219_four= INA219(i2c_one, addresses[3]) ina219_four= INA219(i2c_one, addresses[3])
ina219_four.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S
ina219_four.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S # 1S
ina219_four.bus_voltage_range = BusVoltageRange.RANGE_16V
four = 1
except: except:
print("Python Error 3", file=sys.stderr, flush=True) print("Python Error 3", file=sys.stderr, flush=True)
except: except:
@ -109,7 +121,7 @@ if __name__ == "__main__":
print("Python Error 5", file=sys.stderr, flush=True) print("Python Error 5", file=sys.stderr, flush=True)
while (True): while (True):
if (zeroOne == 1): if (oneZero == 1):
print("{:6.3f} ".format(ina219_one.bus_voltage), "{:6.3f} ".format(ina219_one.current) , end = '') print("{:6.3f} ".format(ina219_one.bus_voltage), "{:6.3f} ".format(ina219_one.current) , end = '')
else: else:
print("{:6.3f} ".format(0), "{:6.3f} ".format(0), end = '') print("{:6.3f} ".format(0), "{:6.3f} ".format(0), end = '')

Loading…
Cancel
Save

Powered by TurnKey Linux.