Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

INA219 High Side DC Current Sensor Breakout options please
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

INA219 High Side DC Current Sensor Breakout options please

by joey120373 on Tue Aug 28, 2012 1:20 am

I just got two of these in the mail to play with. I hooked one up and loaded the demo code, after changing the file extension to ".ino" and renaming the library :? :? :?

( why does this have to be done? Wouldn't it save a lot of hassle for new users like myself if the libraries and examples provided would just have the correct file extension and be labeled so that arduino would recognize them? )

In any case, it works great and appears to be quite a useful little board :D :D thanks.

So, I want to use this for a low current measuring device, say 0-40 mA. The web page indicates that setting the internal gain to a 1 ( opposed to the default of 8 ) will give a range of 400mA, that is getting a lot closer, then if I were to replace the .1 ohm resistor with a 1ohm, it should give 12 bit accuracy across a 40mA range, correct?

So I thought I would start by trying to set the internal gain to 1, this is where i am needing help. I read the spec sheet, and I think I understand what bits to change, problem is, as I am quite new to arduino, I dont quite understand how to read the library. I assume that somewhere in the .h or .cpp file there is a data string sent to the IC that sets the gain and voltage bits etc. but where exactly is that and can it be modified?

Just for kicks, I removed the .1ohm resistor and replaced it with a 1% 10 ohm resistor (had a few lying around), then added a few lines of code to divide the current/100 and display that, seems to work ok, but not the most elegant way of doing it. I would prefer to do it by changing the gain and using a 1 ohm sense resistor.

Any help would be greatly appreciated, and thanks for this cool little board!

Joe
joey120373
 
Posts: 7
Joined: Thu Apr 19, 2012 12:57 am

Re: INA219 High Side DC Current Sensor Breakout options please

by adafruit_support_bill on Tue Aug 28, 2012 6:16 am

The gain (and other properties) are set in the control register via the following code (in Adafruit_INA219.cpp).

Code: Select all | TOGGLE FULL SIZE
  // Set Config register to take into account the settings above
  uint16_t config = INA219_CONFIG_BVOLTAGERANGE_32V |
                    INA219_CONFIG_GAIN_8_320MV |
                    INA219_CONFIG_BADCRES_12BIT |
                    INA219_CONFIG_SADCRES_12BIT_1S_532US |
                    INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
  wireWriteRegister(INA219_REG_CONFIG, config);


To change the gain, substitute one of the bitmask gain constants defined in (in Adafruit_INA219.h)

Code: Select all | TOGGLE FULL SIZE
 #define INA219_CONFIG_GAIN_1_40MV (0x0000) // Gain 1, 40mV Range
#define INA219_CONFIG_GAIN_2_80MV (0x0800) // Gain 2, 80mV Range
#define INA219_CONFIG_GAIN_4_160MV (0x1000) // Gain 4, 160mV Range
#define INA219_CONFIG_GAIN_8_320MV (0x1800) // Gain 8, 320mV Range


( why does this have to be done? Wouldn't it save a lot of hassle for new users like myself if the libraries and examples provided would just have the correct file extension and be labeled so that arduino would recognize them? )

Many people are still using pre-1.0 version of the Arduino IDE which expect the .pde extension. 1.0 and later will recognize .pde files (and automatically convert them to .ino) if you open them via the File->Examples menu.

adafruit_support_bill
 
Posts: 77964
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.