ads1115-16bit-adc

hussainfawzi/ads1115-16bit-adc/ads1115-16bit-adc

No description
ads1115-16bit-adc
@/ads1115-16bit-adc
ADDRbyte
Device adress on I2C bus.
GAINnumber
Set the PGA gain
UPDATEpulse
Feed a pulse signal to conduct analog reading.
ads1115-16bit-adc
A0
A1
A2
A3
A0-1
A2-3
DONE
ADDR
GAIN
UPDATE
DONEpulse
Spits a pulse when done reading.
A2-3number
Spits the latest value of channel A2 - A3 (differential reading).
A0-1number
Spits the latest value of channel A0 - A1 (differential reading).
A3number
Spits the latest value of channel A3
A2number
Spits the latest value of channel A2
A1number
Spits the latest value of channel A1
A0number
Spits the latest value of channel A0
To use the node in your project you should have the hussainfawzi/ads1115-16bit-adc 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/adafruit/Adafruit_ADS1X15"

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_UPDATE
#pragma XOD error_raise enable

{{#global}}
#include <Wire.h>
#include <Adafruit_ADS1015.h>
{{/global}}

struct State {
};

{{ GENERATED_CODE }}

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

    Number address = getValue<input_ADDR>(ctx);
    Adafruit_ADS1115 ads(address);
    ads.begin();
    auto gain = getValue<input_GAIN>(ctx);
    if(gain==0.66){ads.setGain(GAIN_TWOTHIRDS);}    // 2/3x gain +/- 6.144V  1 bit = 0.1875mV
    else if(gain==1){ads.setGain(GAIN_ONE);}             // 1x gain   +/- 4.096V  1 bit = 0.125mV
    else if(gain==2){ads.setGain(GAIN_TWO);}             // 2x gain   +/- 2.048V  1 bit = 0.0625mV
    else if(gain==4){ads.setGain(GAIN_FOUR);}            // 4x gain   +/- 1.024V  1 bit = 0.03125mV
    else if(gain==8){ads.setGain(GAIN_EIGHT);}           // 8x gain   +/- 0.512V  1 bit = 0.015625mV
    else if(gain==16){ads.setGain(GAIN_SIXTEEN);}        // 16x gain  +/- 0.256V  1 bit = 0.0078125mV
    int16_t buffer;
    buffer=ads.readADC_SingleEnded(0); emitValue<output_A0>(ctx, buffer);
    buffer=ads.readADC_SingleEnded(1); emitValue<output_A1>(ctx, buffer);
    buffer=ads.readADC_SingleEnded(2); emitValue<output_A2>(ctx, buffer);
    buffer=ads.readADC_SingleEnded(3); emitValue<output_A3>(ctx, buffer);
    buffer=ads.readADC_Differential_0_1(); emitValue<output_A0_1>(ctx, buffer);
    buffer=ads.readADC_Differential_2_3(); emitValue<output_A2_3>(ctx, buffer);
    emitValue<output_DONE>(ctx, 1);
};