ina219

dinosalvioni/ina219/ina219

No description
ina219
@/ina219
UPDpulse
ina219
RSHV
RBUV
SHV
SHC
BUV
BUP
DONE
UPD
DONEpulse
BUPnumber
bus power mW
BUVnumber
bus voltage V
SHCnumber
shunt current mA
SHVnumber
shunt voltage mV
RBUVnumber
raw bus voltage mV
RSHVnumber
raw shunt voltage mV
To use the node in your project you should have the dinosalvioni/ina219 library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD require "https://github.com/flav1972/ArduinoINA219"



/**********************************************
* INA219 library example
* 10 May 2012 by johngineer
*
* 9 January 2016 Flavius Bindea: changed default values and begin()
*
* this code is public domain.
**********************************************/





{{#global}}
#include "INA219.h"
#include "Wire.h"
{{/global}}



struct State {
};

        

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
auto state = getState(ctx);



    if (isInputDirty<input_UPD>(ctx)) {

INA219 monitor;
  monitor.begin();
  // begin calls:
  // configure() with default values RANGE_32V, GAIN_8_320MV, ADC_12BIT, ADC_12BIT, CONT_SH_BUS
  // calibrate() with default values D_SHUNT=0.1, D_V_BUS_MAX=32, D_V_SHUNT_MAX=0.2, D_I_MAX_EXPECTED=2
  // in order to work directly with ADAFruit's INA219B breakout

        float RSHV = monitor.shuntVoltageRaw();
        float RBUV = monitor.busVoltageRaw();
        float SHV = (monitor.shuntVoltage() * 1000);
         float SHC = (monitor.shuntCurrent() * 1000);
        float BUV = (monitor.busVoltage());
        float BUP = (monitor.busPower() * 1000);

        //raw shunt voltage V
        emitValue<output_RSHV>(ctx, RSHV);
        //raw bus voltage V
        emitValue<output_RBUV>(ctx, RBUV);
        //shunt voltage mV
        emitValue<output_SHV>(ctx, SHV);
        //shunt current mA
        emitValue<output_SHC>(ctx, SHC);
        //bus voltage V
        emitValue<output_BUV>(ctx, BUV);
        //bus power mW
        emitValue<output_BUP>(ctx, BUP);
    

        

    
    }emitValue<output_DONE>(ctx, 1);
}