I have it up and running on an arduino UNO board, and so far it is working great.
However, I am a bit new to all of this and I need some advice for modifying the code to get more resolution at lower currents. According to the web page:
A precision amplifier measures the voltage across the 0.1 ohm, 1% sense resistor. Since the amplifier maximum input difference is ±320mV this means it can measure up to ±3.2 Amps. With the internal 12 bit ADC, the resolution at ±3.2A range is 0.8mA. With the internal gain set at the minimum of div8, the max current is ±400mA and the resolution is 0.1mA. Advanced hackers can remove the 0.1 ohm current sense resistor and replace it with their own to change the range (say a 0.01 ohm to measure up 32 Amps with a resolution of 8mA)
I am assuming that the example code I am using sets the chip up to read a span of ±320mV, and thus report a ±3.2A range, I would like to know how to send the commands to reset the internal gain to minimum (1) so that I can get a ±400mA range instead.
I have looked though the .h and .cpp files, and they seem to be well commented, but it is a little over my head, as i am fairly new to the arduino.
The example sketch simply initiates the chip with the "ina219.begin();" in setup, then starts communication with the chip and reading values. I am assuming that the library actually sets the gain and voltage range via this command.
The Adafruit library seems to be not suited for the lowest current range.
The "ina219_currentDivider_mA" variable is an integer, which should be set to 25/8 for the lowest range (I think). So you might have to write your own interface.
The "ina219.begin()" is the "Adafruit_INA219::begin()" in the "Adafruit_INA219.cpp" file.
It calls a function "ina219SetCalibration_32V_2A()".
That function sets the config register in the INA219.
There is also a function "ina219SetCalibration_32V_1A" which you could use, instead of the '2A' version.
The '1A' version can be altered, but a mistake is easy to make.
In "Adafruit_INA219.h", the define "INA219_CONFIG_GAIN_1_40MV" will set the highest precision.
You could do this:
Make the "ina219_currentDivider_mA" a float in "Adafruit_INA219.h".
Rename "ina219SetCalibration_32V_1A" to "my_ina219SetCalibration"
Call that function from "Adafruit_INA219::begin".
Replace in "my_ina219SetCalibration" the define "INA219_CONFIG_GAIN_8_320MV" by "INA219_CONFIG_GAIN_1_40MV"
Adjust the values for "ina219_currentDivider_mA" and "ina219_powerDivider_mW" by dividing them by 8 in that function.
So it is not easy to do.
You could check the forums at Adafruit.
Or use a different library. I like this one : http://www.johngineer.com/blog/?p=1178
In his README file, John De Cristofaro writes this: "Something to keep in mind however, is that this change in gain DOES NOT affect the resolution of the ADC, which is fixed at 1uV."
So after all, I would suggest to use the Adafruit "1A" function as it is.