ntc10-device

lutkola/ntc10/ntc10-device

No description
ntc10-device
@/ntc10-device
PORTport
UPDpulse
ntc10-device
VAL
DONE
PORT
UPD
DONEpulse
VALnumber
To use the node in your project you should have the lutkola/ntc10 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 evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_UPD
#pragma XOD error_raise enable

#define referenceResistance 10000
#define nominalResistance 10000
#define nominalTemperature 298.15
#define bValue 3950
#define adcres 1023


struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
   
    if (!isInputDirty<input_UPD>(ctx))
        return;

    const uint8_t port = getValue<input_PORT>(ctx);
    
    if (!isValidAnalogPort(port)) {
        raiseError(ctx);
        return;
    }
      

    ::pinMode(port, INPUT);

    double avgR = 0;

    for(int i = 0; i < 10; i++){
       avgR += analogRead(port);
       delay(100);
    }

    avgR /= 10;

    //avgR = 476;

    avgR = referenceResistance / (adcres / avgR - 1); 
    
    double inverseKelvin = 1.0 / nominalTemperature + log(avgR / nominalResistance) / bValue;
    double Celsius = 1.0/inverseKelvin - 273.15;


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