This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

INA219: Motor gets stop after using INA219 library

Part Number: INA219


Hello Sir,

I am using the INA219 for reading the motor current consumption using Arduino. But as I use the library of INA219 then motor works only for few seconds and then get stopped.

I am using this code-

// defines pins numbers
const int stepPin = 5;
const int dirPin = 2;
const int enPin = 8;
#include <Wire.h>
#include <Adafruit_INA219.h>

Adafruit_INA219 ina219;
void setup(void) {

// Sets the two pins as Outputs

pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);

pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
Serial.begin(115200);
while (!Serial) {
//will pause Zero, Leonardo, etc until serial console opens
delayMicroseconds(1);
}

uint32_t currentFrequency;

//Serial.println("Hello!");

// Initialize the INA219.
// By default the initialization will use the largest range (32V, 2A). However
// you can call a setCalibration function to change this range (see comments).
ina219.begin();
// To use a slightly lower 32V, 1A range (higher precision on amps):
// ina219.setCalibration_32V_1A();
// Or to use a lower 16V, 400mA range (higher precision on volts and amps):
//ina219.setCalibration_16V_400mA();

Serial.println("Measuring voltage and current with INA219 ...");


}
void loop() {

digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < 8000; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(100);
digitalWrite(stepPin,LOW);
delayMicroseconds(60);
}
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power_mW = 0;
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
power_mW = ina219.getPower_mW();
loadvoltage = busvoltage + (shuntvoltage / 1000);

Serial.print("Bus Voltage: "); Serial.print(busvoltage); Serial.println(" V");
Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
Serial.print("");
Serial.println("Load Voltage: "); Serial.print(loadvoltage); Serial.println(" V");
Serial.print("");
Serial.println("Current: "); Serial.print(current_mA); Serial.println(" mA");
Serial.print("Power: "); Serial.print(power_mW); Serial.println(" mW");
Serial.println("");

}

Also, I had tried to use the set_calibration command but doesn't work anything.

Please help me as soon as possible.

Thanks