Skip to content

begin()

Arnd edited this page May 3, 2020 · 7 revisions

begin(MaxBusAmps, ShuntResistance [,deviceNumber]);

The Initial call to the begin() function is done with just the first two parameters. All INAxxx devices found are initialized with the values passed in as MaxBusAmps and ShuntResistance, see the table below for details. Subsequent calls to the begin() method with different values for different deviceNumbers will override the values. The deviceNumber begins with 0. Since the INA2xx devices only measure the bus voltage and the shunt voltage and don't measure power directly, if these two parameters are not set correctly the computed Amps and Watts will be incorrect but the voltages will be correctly returned. The INA2xx uses the industry standard I2C protocol for communications. Each I²C device has a unique address and this is selectable on the INA2xx by setting certain pins high, low or shorting them with other pins. The appropriate datasheet for the device will show which values are possible, for example the INA226 datasheet describes the possible address settings on page 18. The INA library will search the I²C bus for all matching devices. The maximum number of devices that the library supports is limited by microprocessor EEPROM memory, as the configuration details are stored in this non-volatile memory in order to reduce the program and library footprints.

Parameter Units Description
Max Bus Amperage Amps This value is determined using Ohm's law from maximum voltage and resistance of the shunt. Typically the value is given on the shunt, e.g. "Maximum 75mOhm at 10A". Correct setting of this value is important to correctly scale the readings. The range is from 1A to 1022A; this is used to compute the internal gain of the INA device to achieve an optimal accuracy.
Resistance microOhms The resistance of the shunt is the key factor in determining the amps and watts measured by the INA2xx devices. Since the library does not use floating point and many shunts for high-power applications have a resistance below an ohm the value of the resistance in ohm needs to be multiplied by 1000 to convert from Ohms to milliohms and once more by 1000 to convert to microOhms.

Range Limitation: Since the calibration register is a 16-bit one, it is possible to overflow when the MaxBusAmps are set to a value lower than (0.00512/ShuntR(Ω))

For example, a 200Amp / 50mV shunt which has a resistance of .25 mOhm and which is initialized as "begin(200,250);" and a .1 Ohm resistor on a 10Amp circuit is initialized with "begin(10,100000);"


Example:

INA_Class INA(); // Instantiate the class
void setup() {
  INA.begin(1,100000);  // 1A max current and a 0.1 Ohm shunt resistor 
                        // Note that a power resistor should be used 
                        // to dissipate sufficient generated heat, 
                        // Watts = Amps² x Resistance (0.1W in this case)
} // of Setup

void loop() {
   /* ... */
} // of main loop

Esplora 2866 and Esplora 32

Due to the way that I2C can be declared using these devices and that different pins from the standard SDA and SCL can be used, the library does not issue a "Wire.begin()" for them, but it is expected that the developer issues this call prior to calling the begin() method.

Clone this wiki locally