From 7a19aaf1a77b9bb544c88dfb16697ec740b5378e Mon Sep 17 00:00:00 2001 From: WizardTim <43670403+WizardTim@users.noreply.github.com> Date: Fri, 4 Dec 2020 09:29:27 +1000 Subject: [PATCH 1/3] Add power figures, cleanup output format - Changed naming of 'PSU' and 'Load' voltages to 'VIN+' and 'VIN-' as I initially thought 'PSU' was referring to I2C logic level Vcc. Not sure why previous names were chosen, I can't find any IN219 eval boards that don't used VIN+/VIN-. - Added power figures both from on chip register (lower resolution) as well as one calculated in Python using the full resolution voltage/current values - Align output in columns with correct significant figures --- examples/ina219_simpletest.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/ina219_simpletest.py b/examples/ina219_simpletest.py index 4212449..2a6bfca 100644 --- a/examples/ina219_simpletest.py +++ b/examples/ina219_simpletest.py @@ -31,12 +31,15 @@ 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 + power = ina219.power # power in watts # 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("Voltage (VIN+) : {:6.3f} V".format(bus_voltage + shunt_voltage)) + print("Voltage (VIN-) : {:6.3f} V".format(bus_voltage)) + print("Shunt Voltage : {:8.5f} V".format(shunt_voltage)) + print("Shunt Current : {:7.4f} A".format(current / 1000)) + print("Power Calc. : {:8.5f} W".format(bus_voltage*(current/1000))) + print("Power Register : {:6.3f} W".format(power)) print("") time.sleep(2) From 791d0760b7ddb2c8ab32c385ca74df1eafc1efe3 Mon Sep 17 00:00:00 2001 From: WizardTim <43670403+WizardTim@users.noreply.github.com> Date: Fri, 4 Dec 2020 10:36:30 +1000 Subject: [PATCH 2/3] Use overflow flag in example Would have liked to implement ADC overflow detection but no flag appears to exist for it --- examples/ina219_simpletest.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/ina219_simpletest.py b/examples/ina219_simpletest.py index 2a6bfca..ab7716c 100644 --- a/examples/ina219_simpletest.py +++ b/examples/ina219_simpletest.py @@ -42,4 +42,9 @@ print("Power Register : {:6.3f} W".format(power)) print("") + # Check internal calculations haven't overflowed (doesn't detect ADC overflows) + if ina219.overflow: + print("Internal Math Overflow Detected!") + print("") + time.sleep(2) From 8052acb504de66585070fdaa236dae6fdc372e06 Mon Sep 17 00:00:00 2001 From: WizardTim <43670403+WizardTim@users.noreply.github.com> Date: Fri, 4 Dec 2020 10:56:22 +1000 Subject: [PATCH 3/3] Formatting --- examples/ina219_simpletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ina219_simpletest.py b/examples/ina219_simpletest.py index ab7716c..ae5c0d2 100644 --- a/examples/ina219_simpletest.py +++ b/examples/ina219_simpletest.py @@ -38,7 +38,7 @@ print("Voltage (VIN-) : {:6.3f} V".format(bus_voltage)) print("Shunt Voltage : {:8.5f} V".format(shunt_voltage)) print("Shunt Current : {:7.4f} A".format(current / 1000)) - print("Power Calc. : {:8.5f} W".format(bus_voltage*(current/1000))) + print("Power Calc. : {:8.5f} W".format(bus_voltage * (current / 1000))) print("Power Register : {:6.3f} W".format(power)) print("")