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

waitForConversion()

Arnd edited this page Jun 22, 2018 · 4 revisions

waitForConversion([deviceNumber]);

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

wait for conversion to complete as specified below for the device given in "deviceNumber"; setting all devices if the "deviceNumber" parameter is omitted.

The last measurement for bus voltage, shunt voltage, computed amps and computed watts is always available, the new value is being computed by the INA226 in the background, either continuously or triggered by an explicit call. The INA226 sets a flag when the currently running conversion has completed, and this function will not return until the computation has completed. It also resets the flag so that it can be set by the next conversion.


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
  INA226.setBusConversion(7);   // set bus conversion time 8.2446ms
  INA226.setShuntConversion(7); // set shunt conversion time 8.2446ms
  INA226.setAveraging(1024);    // set to 1024 samples
} // of setup
void loop() {
  waitForConversion(); // conversion takes 1024*8.2446ms = 8.44 seconds
  uint16_t BusMicroAmps = INA226.getBusMicroAmps();
  Serial.print("Bus amperage is ");
  Serial.print((float)BusMicroAmps/1000,3);
  Serial.print(" mVolts\n");
} // of main loop