add try exception for error

pull/55/head
alanbjohnston 5 years ago committed by GitHub
parent 7c684b461e
commit a54a31cfe7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,9 +21,9 @@ if __name__ == "__main__":
bus = 1 bus = 1
address = 0x40 address = 0x40
try:
# Create library object using Extended Bus I2C port # Create library object using Extended Bus I2C port
i2c_bus = I2C(bus) # 1 Device is /dev/i2c-1 i2c_bus = I2C(bus) # 1 Device is /dev/i2c-1
ina219 = INA219(i2c_bus, address) ina219 = INA219(i2c_bus, address)
# print("ina219 test") # print("ina219 test")
@ -37,12 +37,8 @@ if __name__ == "__main__":
bus_voltage = ina219.bus_voltage # voltage on V- (load side) bus_voltage = ina219.bus_voltage # voltage on V- (load side)
shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt shunt_voltage = ina219.shunt_voltage # voltage between V+ and V- across the shunt
# current = ina219.current # current in mA # current = ina219.current # current in mA
# INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage # INA219 measure bus voltage on the load side. So PSU voltage = bus_voltage + shunt_voltage
print("{:6.3f}".format(bus_voltage + shunt_voltage)) print("{:6.3f}".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) exception:
printf("0 Error\n")

Loading…
Cancel
Save

Powered by TurnKey Linux.