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 Jan 12, 2017 · 4 revisions

waitForConversion();

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