chrisb2 / pi_ina219

This Python library supports the INA219 voltage, current and power monitor from Texas Instruments with a Raspberry Pi using the I2C bus. The intent of the library is to make it easy to use the quite complex functionality of this sensor.
MIT License
114 stars 34 forks source link

Allow gain to auto-scale if a current overflow occurs #3

Closed chrisb2 closed 7 years ago

chrisb2 commented 7 years ago

The idea is to make it even easier to use this library by automatically increasing the gain if a current overflow is detected at the current gain. Current overflow would only occur when the gain reaches the maximum value support by the INA219.

Auto-scaling of gain would be the default configuration, so to measure voltage upto 26V and current upto 3.2A (with std 0.1 Ohm shunt) only code similar to the following would required:

SHUNT_OHMS = 0.1
ina = INA219(SHUNT_OHMS)
ina.configure()

try:
    print "Bus Voltage: %.3f V" % ina.voltage()
    print "Bus Current: %.3f mA" % ina.current()
except CurrentOverflowException"
    print "Current greater than device capability"