INA219 DC current monitor not working

I am trying to create a mesh system of Xenons measuring current and reporting back to an Argon for data collection, but something isn’t working. I am trying to use and Adafruit INA219 DC Current Monitor, and I’m fairly certain I’ve wired everything to the correct ports, but when I run the get-current.ino code in the ina219 library examples my Xenon freezes at the INA219.begin() line.

Has anyone run into this issue before, and more importantly does anyone know how to remedy it? Thank you in advance for your help.

1 Like

@4Science, can you share a picture of your hookup? Are you using an INA219 feather wing?

@peekay123 a picture would not be the easiest to get, but I can list out the connections. I am not using a feather wing, just the breakout board (This one).

My connections are as follows:
INA219 | Xenon
Vcc -> 3V
GND -> GND
SCL -> D1(SCL)
SDA -> D0(SDA)

Vin- -> potentiometer pin 2
Vin+ -> VUSB (to get Voltage)

Pins 1 and 3 of the potentiometer are connected to ground, 1 to ground it and 3 to complete the circuit.

Which address is your board set to?
You should maybe run an I2C scanner sketch to find out whether the sensor is found at all and at what address.

@ScruffR My board is set to the default 0x40 address. I tried to run an I2C Scanner but it freezes after the Wire.endTransmission Line (see Below). I use the LED to tell where the code freezes. This is my first time using I2C and I can’t seem to figure out why it’s not working.

void loop()
{digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,LOW);
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {Serial.println("hey");
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    digitalWrite(LED,HIGH);
    error = Wire.endTransmission();
    delay(500);
    digitalWrite(LED,LOW);//Never Reaches Here
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
 
  delay(5000);           // wait 5 seconds for next scan
}

Are you calling Wire.begin() in setup()?
What device OS version are you running on your Xenon?
And from past troubleshooting experience: Have you soldered the pins on your sensor board?

I am calling Wire.Begin()
My Xenon is running 1.1.1
I have soldered the pins on, although I did them on the other side of the board than on the website, although that shouldn’t have an effect.

@4Science, assuming your soldering is good, it will not make a difference. Can you post your entire code, not just loop()?

One thing to remember is that the INA219 is a HIGH SIDE current sensor. That means you are measuring current THROUGH the load using the current sensing resistor on the breakout. Your potentiometer needs to act as a variable resistor (thus varying current) from Vin+ to Vin-. That means connecting one side of the pot to Vin+ (also VUSB) with the centre wiper connecting to Vin-. As you have it, you have configured the pot as a voltage divider feeding Vin- with a voltage, which is incorrect.

As for the I2C scanner, I suggest you remove the potentiometer and leave Vin-/Vin+ open. I would still prefer a picture as often we find what is described versus what is actually done don’t match.

3 Likes

@peekay123 Removing the potentiometer made the I2C scanner work fine, so I think that hopefully rewiring the current monitor as you described will fix the current monitoring sketch. I am leaving for 4th of July weekend right now, but I will update if that was the issue on Monday, Thank you for your help. Attached below is my I2C scanner. I don’t think anything is wrong with it, but if someone in the future finds this thread and wants a I2C Scanner here it is.

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
const int LED=D7;
#include <Wire.h>
 
 
void setup()
{
    pinMode(LED,OUTPUT);
  Wire.begin();
  delay(500);
  Serial.begin(115200);
  digitalWrite(LED,HIGH);
  while (!Serial);             // Leonardo: wait for serial monitor
  delay(500);
  digitalWrite(LED,LOW);
  Serial.println("\nI2C Scanner");
}
 
 
void loop()
{digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,LOW);
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {//Serial.println("hey");
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    //digitalWrite(LED,HIGH);
    error = Wire.endTransmission();
    //delay(500);
    //digitalWrite(LED,LOW);//Never Reaches Here
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
 
  delay(5000);           // wait 5 seconds for next scan
}
1 Like

@peekay123 Hey, thanks for your help. As it turned out, the Xenon I was using was defective with it’s ports or something. I switched out Xenons and wired the sensor correctly and everything worked fine. One thing that I needed to fix was I needed the GND on the sensor to be wired to the same GND as the potentiometer. I didn’t realize this until some testing.

1 Like