Skip to content
This repository has been archived by the owner on Jun 22, 2018. It is now read-only.

setMode()

Arnd edited this page Jun 22, 2018 · 4 revisions

setMode(ModeValue[,deviceNumber]);

‼️ This library is now deprecated and has been replaced by the INA library. All existing INA226 functionality and functions have been implemented ‼️

The device specified in the optional parameter "deviceNumber" is set to the specified mode; if the parameter is not specifed then all INA226 device located are set to the specified mode.

The INA226 has various operating modes. The two main modes are "continuous" (the default) and "triggered". In continuous mode the devices performs measurements in the background and then places the results in the appropriate registers, then goes off and repeats the process. This means that new values are continually written to the registers without user interaction. The triggered mode will only perform measurements when explicitly triggered by the user. Both of these modes have sub-modes which let conversions be limited to either the shunt measurements or the bus measurements or to both. The list of possible modes is as follows:

Mode Value
(Binary)
Mode Description Program Constant
000 Power Down mode with minimal energy consumption. No measurements are taken until the device is powered up with either a reset or explicitly writing a different mode to the configuration register INA_MODE_POWER_DOWN
001 Triggered Shunt mode. When triggered, perform a single shunt voltage conversion only INA_MODE_TRIGGERED_SHUNT
010 Triggered Bus mode. When triggered, perform a single bus voltage conversion only INA_MODE_TRIGGERED_BUS
011 Trigger mode. When triggered, perform a single shunt and bus voltage conversion INA_MODE_TRIGGERED_BOTH
000 Power Down mode with minimal energy consumption. No measurements are taken until the device is powered up with either a reset or explicitly writing a different mode to the configuration register INA_MODE_POWER_DOWN
101 Continuous shunt mode. Automatically perform shunt voltage measurements INA_MODE_CONTINUOUS_SHUNT
110 Continuous bus mode. Automatically perform bus voltage measurements INA_MODE_CONTINUOUS_BUS
111 Continuous mode (default startup value). Automatically perform bus and shunt measurements INA_MODE_CONTINUOUS_BOTH

Example:

INA226_Class INA226(); // Instantiate the class
void setup() {
  INA226.begin(50,100000); // 5V bus with maximum current of 500mA
                           // A 0.1 Ohm shunt resistor generates 50mV max
  INA226.setMode(INA_MODE_CONTINUOUS_BUS); // only compute bus values for all devices
} // of setup

void loop() { uint16_t BusMillivolts = INA226.getBusMillivolts(); Serial.print("Bus voltage is "); Serial.print((float)BusMillivolts/1000,3); Serial.print(" Volts\n"); delay(5000); // wait 5 seconds before next measurement
} // of main loop