-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathina219.py
More file actions
executable file
·62 lines (48 loc) · 2.96 KB
/
ina219.py
File metadata and controls
executable file
·62 lines (48 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Sample code and test for adafruit_in219"""
import time
import board
from adafruit_ina219 import ADCResolution, BusVoltageRange, INA219
i2c_bus = board.I2C()
ina1 = INA219(i2c_bus,addr=0x40)
ina2 = INA219(i2c_bus,addr=0x41)
ina3 = INA219(i2c_bus,addr=0x42)
ina4 = INA219(i2c_bus,addr=0x43)
print("ina219 test")
ina1.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S
ina1.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S
ina1.bus_voltage_range = BusVoltageRange.RANGE_16V
ina2.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S
ina2.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S
ina2.bus_voltage_range = BusVoltageRange.RANGE_16V
ina3.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S
ina3.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S
ina3.bus_voltage_range = BusVoltageRange.RANGE_16V
ina4.bus_adc_resolution = ADCResolution.ADCRES_12BIT_32S
ina4.shunt_adc_resolution = ADCResolution.ADCRES_12BIT_32S
ina4.bus_voltage_range = BusVoltageRange.RANGE_16V
# measure and display loop
while True:
bus_voltage1 = ina1.bus_voltage # voltage on V- (load side)
shunt_voltage1 = ina1.shunt_voltage # voltage between V+ and V- across the shunt
power1 = ina1.power
current1 = ina1.current # current in mA
bus_voltage2 = ina2.bus_voltage # voltage on V- (load side)
shunt_voltage2 = ina2.shunt_voltage # voltage between V+ and V- across the shunt
power2 = ina2.power
current2 = ina2.current # current in mA
bus_voltage3 = ina3.bus_voltage # voltage on V- (load side)
shunt_voltage3 = ina3.shunt_voltage # voltage between V+ and V- across the shunt
power3 = ina3.power
current3 = ina3.current # current in mA
bus_voltage4 = ina4.bus_voltage # voltage on V- (load side)
shunt_voltage4 = ina4.shunt_voltage # voltage between V+ and V- across the shunt
power4 = ina4.power
current4 = ina4.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 Shunt Voltage:{:9.6f}V Load Voltage:{:6.3f}V Power:{:9.6f}W Current:{:9.6f}A".format((bus_voltage1 + shunt_voltage1),(shunt_voltage1),(bus_voltage1),(power1),(current1/1000)))
print("PSU Voltage:{:6.3f}V Shunt Voltage:{:9.6f}V Load Voltage:{:6.3f}V Power:{:9.6f}W Current:{:9.6f}A".format((bus_voltage2 + shunt_voltage2),(shunt_voltage2),(bus_voltage2),(power2),(current2/1000)))
print("PSU Voltage:{:6.3f}V Shunt Voltage:{:9.6f}V Load Voltage:{:6.3f}V Power:{:9.6f}W Current:{:9.6f}A".format((bus_voltage3 + shunt_voltage3),(shunt_voltage3),(bus_voltage3),(power3),(current3/1000)))
print("PSU Voltage:{:6.3f}V Shunt Voltage:{:9.6f}V Load Voltage:{:6.3f}V Power:{:9.6f}W Current:{:9.6f}A".format((bus_voltage4 + shunt_voltage4),(shunt_voltage4),(bus_voltage4),(power4),(current3/1000)))
print("")
print("")
time.sleep(1)