INA219 input triggering an output issue.

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
icebox05
 
Posts: 27
Joined: Fri Jan 10, 2014 3:28 pm

INA219 input triggering an output issue.

Post by icebox05 »

I have the INA219 sensor and it works great with the getcurrent example.

I'm using it with the Adafruit_NeoPixel strip

The input from the INA219 works well in this code

Code: Select all

 { if (current_mA >.30 ){

  strip.setPixelColor(0, 0, 255, 0);
  strip.setPixelColor(1, 0, 255, 0);
  strip.setPixelColor(2, 0, 255, 0);
  strip.setPixelColor(3, 0, 255, 0);
  strip.setPixelColor(4, 0, 255, 0);
  strip.setPixelColor(5, 0, 255, 0);
  strip.setPixelColor(6, 0, 255, 0);
  strip.setPixelColor(7, 0, 255, 0);
  strip.setBrightness(255);
  strip.show();
 }
  
  else{
  
  strip.setPixelColor(0, 255, 0, 0);
  strip.setPixelColor(1, 255, 0, 0);
  strip.setPixelColor(2, 255, 0, 0);
  strip.setPixelColor(3, 255, 0, 0);
  strip.setPixelColor(4, 255, 0, 0);
  strip.setPixelColor(5, 255, 0, 0);
  strip.setPixelColor(6, 255, 0, 0);
  strip.setPixelColor(7, 255, 0, 0);
  strip.setBrightness(255);
  strip.show();}
 }
The last part is where I'm having issues.
I can't get it to digitalwrite an output when the current reading gets above a certain number.
Here is the code.

Code: Select all

 { if (current_mA >.30 ){
  digitalWrite,(pin11,HIGH);}
  
It complies fine but it seems its not really setting pin11 high when the current gets above .30mA

I'm needing help with this part I'm sure this part is missing something..just not sure what it is.

Thanks,

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: INA219 input triggering an output issue.

Post by Franklin97355 »

Perhaps if we knew which pins the ina219 and neopixels were connected to and what code you are using to read the ina219 it would help.

icebox05
 
Posts: 27
Joined: Fri Jan 10, 2014 3:28 pm

Re: INA219 input triggering an output issue.

Post by icebox05 »

The INA219 is connected to the SDA and SCL pins over I2C.

I'm using the default adafruit library to read the INA219.

The neo pixels are using default pin 3 and they work fine its just getting the arduino to trigger an output from the current_mA read thats the issue.

Basicaly the code goes as follows.

If current_mA is greater than .30mA turn lights green..else turn red
If current_mA is greater than .30mA change pin11 to high..(which is activating a contact closure using reistors and npn transistor 2222)
I have confirmed if I command pin11 on in the code without restrictions it turns the circuit on fine.
Just needing help with turning it on when the current is reading above a certain value.

Thanks

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: INA219 input triggering an output issue.

Post by adafruit_support_bill »

Please post the code you are using.

icebox05
 
Posts: 27
Joined: Fri Jan 10, 2014 3:28 pm

Re: INA219 input triggering an output issue.

Post by icebox05 »

Code: Select all

 
 */
 
#include <Wire.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_INA219.h>
#define PIN 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

Adafruit_INA219 ina219;

// These constants won't change.  They're used to give names
// to the pins used:

const int v = 6;
const int signal = 7;


int pin2 = 2;
int pin10 = 10;
int pin11 = 11;


void setup() {
  pinMode(v, OUTPUT); 
  pinMode(signal, OUTPUT);  
  pinMode(pin2, INPUT);
  pinMode(pin10, OUTPUT);
  pinMode(pin11, OUTPUT);
    strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  
  uint32_t currentFrequency;
    
  Serial.begin(115200);
  Serial.println("Hello!");
  
  Serial.println("Measuring voltage and current with INA219 ...");
  ina219.begin();
}

void loop() {
  
  float shuntvoltage = 0;
  float busvoltage = 0;
  float current_mA = 0;
  float loadvoltage = 0;
  
   shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  loadvoltage = busvoltage + (shuntvoltage / 1000);
  
   digitalWrite(pin10, HIGH); 
 
 { if (current_mA >.30 ){
  digitalWrite,(pin11,HIGH);}
  
        
  
  // read the analog in value:
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");
  Serial.println("");

  delay(2000);  
  
 
    
 { if (current_mA >.30 ){

  strip.setPixelColor(0, 0, 255, 0);
  strip.setPixelColor(1, 0, 255, 0);
  strip.setPixelColor(2, 0, 255, 0);
  strip.setPixelColor(3, 0, 255, 0);
  strip.setPixelColor(4, 0, 255, 0);
  strip.setPixelColor(5, 0, 255, 0);
  strip.setPixelColor(6, 0, 255, 0);
  strip.setPixelColor(7, 0, 255, 0);
  strip.setBrightness(255);
  strip.show();
 }
  
  else{
  
  strip.setPixelColor(0, 255, 0, 0);
  strip.setPixelColor(1, 255, 0, 0);
  strip.setPixelColor(2, 255, 0, 0);
  strip.setPixelColor(3, 255, 0, 0);
  strip.setPixelColor(4, 255, 0, 0);
  strip.setPixelColor(5, 255, 0, 0);
  strip.setPixelColor(6, 255, 0, 0);
  strip.setPixelColor(7, 255, 0, 0);
  strip.setBrightness(255);
  strip.show();}
 }



  
}}

  
One more note..I have tried to move that part of the code before and after the neo pixel part still with no results.

Thanks,

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: INA219 input triggering an output issue.

Post by adafruit_support_bill »

I am a little surprised that the code compiles without errors. You have a comma between "digitalWrite" and the parentheses.

Code: Select all

 digitalWrite,(pin11,HIGH);}
I'm not sure what the compiler does with that. You also don't have any code to set the pin low. I think you need something like:

Code: Select all

   if (current_mA > 0.30 )
   {
      digitalWrite(pin11,HIGH);
   }
   else
   {
      digitalWrite(pin11,LOW);
   }

icebox05
 
Posts: 27
Joined: Fri Jan 10, 2014 3:28 pm

Re: INA219 input triggering an output issue.

Post by icebox05 »

The comma was the issue now it turns on but wont turn off.

I used your example but now it seems its still not looking at the current_mA

I logged through serial around -.10-.00mA without the load

not sure whats going on now...I also increased the current_mA > number to 1.00mA and then to 10mA and then 100mA and still the output doesn't turn off.

ideas?

This is how I changed the code

Code: Select all

#include <Wire.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_INA219.h>
#define PIN 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

Adafruit_INA219 ina219;

// These constants won't change.  They're used to give names
// to the pins used:

const int v = 6;
const int signal = 7;


int pin2 = 2;
int pin10 = 10;
int pin11 = 11;


void setup() {
  pinMode(v, OUTPUT); 
  pinMode(signal, OUTPUT);  
  pinMode(pin2, INPUT);
  pinMode(pin10, OUTPUT);
  pinMode(pin11, OUTPUT);
    strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  
  uint32_t currentFrequency;
    
  Serial.begin(115200);
  Serial.println("Hello!");
  
  Serial.println("Measuring voltage and current with INA219 ...");
  ina219.begin();
}

void loop() {
  
  float shuntvoltage = 0;
  float busvoltage = 0;
  float current_mA = 0;
  float loadvoltage = 0;
  
   shuntvoltage = ina219.getShuntVoltage_mV();
  busvoltage = ina219.getBusVoltage_V();
  current_mA = ina219.getCurrent_mA();
  loadvoltage = busvoltage + (shuntvoltage / 1000);
  
   digitalWrite(pin10, HIGH); 
 
  if (current_mA > 100.0 )
   {
      digitalWrite(pin11,HIGH);
   }
   else
   {
      digitalWrite(pin11,LOW);
   }
  
        
  
  // read the analog in value:
  Serial.print("Bus Voltage:   "); Serial.print(busvoltage); Serial.println(" V");
  Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
  Serial.print("Load Voltage:  "); Serial.print(loadvoltage); Serial.println(" V");
  Serial.print("Current:       "); Serial.print(current_mA); Serial.println(" mA");
  Serial.println("");

  delay(2000);  
  
 
    
 { if (current_mA >.30 ){

  strip.setPixelColor(0, 0, 255, 0);
  strip.setPixelColor(1, 0, 255, 0);
  strip.setPixelColor(2, 0, 255, 0);
  strip.setPixelColor(3, 0, 255, 0);
  strip.setPixelColor(4, 0, 255, 0);
  strip.setPixelColor(5, 0, 255, 0);
  strip.setPixelColor(6, 0, 255, 0);
  strip.setPixelColor(7, 0, 255, 0);
  strip.setBrightness(255);
  strip.show();
 }
  
  else{
  
  strip.setPixelColor(0, 255, 0, 0);
  strip.setPixelColor(1, 255, 0, 0);
  strip.setPixelColor(2, 255, 0, 0);
  strip.setPixelColor(3, 255, 0, 0);
  strip.setPixelColor(4, 255, 0, 0);
  strip.setPixelColor(5, 255, 0, 0);
  strip.setPixelColor(6, 255, 0, 0);
  strip.setPixelColor(7, 255, 0, 0);
  strip.setBrightness(255);
  strip.show();}
 }



  
}
Thanks,

icebox05
 
Posts: 27
Joined: Fri Jan 10, 2014 3:28 pm

Re: INA219 input triggering an output issue.

Post by icebox05 »

Disreguard my last post.

It works great! I had the NPN backwords.

Thanks for the great support. I'm sure I'll have more questions as the project progresses.

Thanks Bill and the Adafruit support Team!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”