Skip to content

Commit ee35938

Browse files
committed
Update sample to use new properties and clean-up printed output (align values)
1 parent 33e0755 commit ee35938

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

examples/ina219_simpletest.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,22 @@
99

1010
ina219 = adafruit_ina219.INA219(i2c_bus)
1111

12+
# change configuration to use 32 samples averaging for both bus voltage and shunt voltage
13+
ina219.bus_adc_res = 0x0D # BADCRES_12BIT_32S_17MS
14+
ina219.shunt_adc_res = 0x0D # SADCRES_12BIT_32S_17MS
15+
ina219.bus_voltage_range = 0 # BVOLTAGERANGE_16V
16+
1217
print("ina219 test")
1318

1419
while True:
15-
print("Bus Voltage: {} V".format(ina219.bus_voltage))
16-
print("Shunt Voltage: {} mV".format(ina219.shunt_voltage / 1000))
17-
print("Load Voltage: {} V".format(ina219.bus_voltage + ina219.shunt_voltage))
18-
print("Current: {} mA".format(ina219.current))
20+
bus_voltage = ina219.bus_voltage
21+
shunt_voltage = ina219.shunt_voltage
22+
current = ina219.current
23+
24+
print("PSU Voltage: {:6.3f} V".format(bus_voltage + shunt_voltage))
25+
print("Shunt Voltage: {:9.6f} V".format(shunt_voltage))
26+
print("Load Voltage: {:6.3f} V".format(bus_voltage))
27+
print("Current: {:9.6f} A".format(current/1000))
1928
print("")
2029

2130
time.sleep(2)

0 commit comments

Comments
 (0)