ADS1115 Not working

I’ve struggled every which way with the Adafruit ADS1115. I’ve even tried alternative libraries. I’ve edited the c++ code. Everything! Is anyone getting this thing to work?

Something is seriously messes up with this thing. No error at all is being thrown by XOD with the following code!!! It just stalls when you try to upload…

#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


#include <Wire.h>
#include <Adafruit_ADS1X15.h>


node(

    meta{

        //using Type = Adafruit_ADS1X15*;

       
    }

     Adafruit_ADS1X15  adc = Adafruit_ADS1115(48h);

void evaluate(Context ctx) {

   // if(isSettingUp())
       // return;
    
    if (!isInputDirty<input_UPDATE>(ctx))
        return;

    //Number address = getValue<input_ADDR>(ctx);

    
    if(!adc->begin()){
        raiseError(ctx);
        return;
    }
    
    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){adc.setGain(GAIN_ONE);}             // 1x gain   +/- 4.096V  1 bit = 0.125mV
    else if(gain==2){adc.setGain(GAIN_TWO);}             // 2x gain   +/- 2.048V  1 bit = 0.0625mV
    else if(gain==4){adc.setGain(GAIN_FOUR);}            // 4x gain   +/- 1.024V  1 bit = 0.03125mV
    else if(gain==8){adc.setGain(GAIN_EIGHT);}           // 8x gain   +/- 0.512V  1 bit = 0.015625mV
    else if(gain==16){adc.setGain(GAIN_SIXTEEN);}        // 16x gain  +/- 0.256V  1 bit = 0.0078125mV
    int16_t buffer;
    buffer=adc.readADC_SingleEnded(0); emitValue<output_A0>(ctx, buffer);
    buffer=adc.readADC_SingleEnded(1); emitValue<output_A1>(ctx, buffer);
    buffer=adc.readADC_SingleEnded(2); emitValue<output_A2>(ctx, buffer);
    buffer=adc.readADC_SingleEnded(3); emitValue<output_A3>(ctx, buffer);
    buffer=adc.readADC_Differential_0_1(); emitValue<output_A0_1>(ctx, buffer);
    buffer=adc.readADC_Differential_2_3(); emitValue<output_A2_3>(ctx, buffer);
    emitValue<output_DONE>(ctx, 1);
}

}

It just doesn’t make any sense! Why won’t this code transpile?

#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


#include <Wire.h>
#include <Adafruit_ADS1X15.h>


node(

    meta{

        using Type = Adafruit_ADS1115*;

       
    }

    Adafruit_ADS1115  adc = Adafruit_ADS1115(48h);

void evaluate(Context ctx) {

    if(isSettingUp())
       return;
    
   // if (!isInputDirty<input_UPDATE>(ctx))
       // return;

    //Number address = getValue<input_ADDR>(ctx);

    
    if(!adc.begin()){
        raiseError(ctx);
        return;
    }
    
    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){adc.setGain(GAIN_ONE);}             // 1x gain   +/- 4.096V  1 bit = 0.125mV
    else if(gain==2){adc.setGain(GAIN_TWO);}             // 2x gain   +/- 2.048V  1 bit = 0.0625mV
    else if(gain==4){adc.setGain(GAIN_FOUR);}            // 4x gain   +/- 1.024V  1 bit = 0.03125mV
    else if(gain==8){adc.setGain(GAIN_EIGHT);}           // 8x gain   +/- 0.512V  1 bit = 0.015625mV
    else if(gain==16){adc.setGain(GAIN_SIXTEEN);}        // 16x gain  +/- 0.256V  1 bit = 0.0078125mV
    int16_t buffer;
    buffer=adc.readADC_SingleEnded(0); emitValue<output_A0>(ctx, buffer);
    buffer=adc.readADC_SingleEnded(1); emitValue<output_A1>(ctx, buffer);
    buffer=adc.readADC_SingleEnded(2); emitValue<output_A2>(ctx, buffer);
    buffer=adc.readADC_SingleEnded(3); emitValue<output_A3>(ctx, buffer);
    buffer=adc.readADC_Differential_0_1(); emitValue<output_A0_1>(ctx, buffer);
    buffer=adc.readADC_Differential_2_3(); emitValue<output_A2_3>(ctx, buffer);
    emitValue<output_DONE>(ctx, 1);
}

}



All the libraries are there… It’s all tight… Why won’t somebody help me? I’ve never gotten one piece of help from anyone. Are these questions really that hard?

I don’t have the hardware & never tried the library. From what little I know about include files, yours do appear to be correct. I’d love to help, but I have little to offer. The only two options I can think of:

  1. the xod folder you show above is not the one being used by IDE when you compile
  2. There are Windows permission issues preventing the reading of the header file

Thanks for the reply. If I had a way, then I’d send you a module to try. Although, this issue is before is tries to talk to the device… It’s not even loading the libraries and can’t transpile. Even on the original library file from the creator… not working. But, shouldn’t need a ADS1115… just try to talk to one that isn’t there.

I thought about the permissions issue, and tried running XOD as administrator, and also checking off “read-only” in the C:/AppData. the read-only appears to be for humans accessing through the windows explorer.

I’ve uninstalled XOD and Arduino and reinstalled, and still no luck. Works on Arduino IDE, but not on XOD…

Other hardware that “talks back” I’ve interfaced with are SDCard (read/write), I2C rtc. As well as other I2C hardware, like LCD screen. So, the I2C is working, fine. It’s something going on with the libraries? Like you said, somehow it’s reading the wrong library. Unless somehow there’s a new version of the ADS1115 that can’t use the old ADS1x15 library? Adafruit did say they are going to focus on CircuitPython, and move away from Arduino.

Where else would XOD be looking for the libraries, if they are already in the xod/ardulib folder?

Like I said, I don’t have much experience with this, but I THINK your xod\__ardulib__ folder is setup correctly. The other issue might be that there is another xod\__ardulib__ folder that xod is actually using.

Compiler is complaining it can’t find the .h file, so it is not just a compatibility issue for version of library (it would be able to find the file, but would find the wrong definitions within the file).

Sorry I’m not being much help, but I don’t really know this part of XOD well enough to waste my time trying to reproduce your problem and/or figuring it out. I understand your frustration. I and others are very willing to help with issues, but most of us are working at a pretty high level and are just helping with coding issues & seldom run into low-level issues like this. I was not able to get any help when I was trying to create a library for accessing serial servos either. I eventually gave up when I couldn’t even get vendor-supplied application to manage the servos from my new laptop :-(.

Hi @xodballxod,

Try:
https://xod.io/libs/wayland/ads1115/

There are four example patches to help you test your device.

1 Like

The main issue with your code is this line, where you use a parenthesis instead of a brace - this really upsets the compiler.

node(

I would modify your code as follows:


#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


#include <Wire.h>
#include <Adafruit_ADS1X15.h>


node{

    meta{

        using Type = Adafruit_ADS1115*;

    }

    Adafruit_ADS1115  adc = Adafruit_ADS1115();

void evaluate(Context ctx) {

    if(isSettingUp()) {
        if(!adc.begin()){
            raiseError(ctx);
            return;
        }
    }

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

}

}

Notice that I’ve separated the code that should run once during setup from the code that should run every time UPDATE receives a pulse.

1 Like

Your guidance totally did the trick. Now, I understand libraries much better! Thanks! Also, I see you made a library, recently. Thanks for that! I’m looking forward to seeing how it turns out!
Interesting, the old ADS1x15 Library by hussainfawzi still throws an error! So, weird.
I was going to put in a switch statement to output the actual voltage instead of the bits, but for now, here’s the updated code that is working well to report the bits, based on the solution you provided.

adafruit-ads1115.xodball (6.4 KB)

#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


#include <Wire.h>
#include <Adafruit_ADS1X15.h>


node{

    meta{

        using Type = Adafruit_ADS1115*;


    }

    Adafruit_ADS1115  adc = Adafruit_ADS1115();

void evaluate(Context ctx) {

if(isSettingUp()) {
        Number address = getValue<input_ADDR>(ctx);
        if(!adc.begin(address)){
            raiseError(ctx);
            return;
        }
    }
    
   if (!isInputDirty<input_UPDATE>(ctx))
       return;



    
    auto gain = getValue<input_GAIN>(ctx);
    if(gain==0.66){adc.setGain(GAIN_TWOTHIRDS);}    // 2/3x gain +/- 6.144V  1 bit = 0.1875mV
    else if(gain==1){adc.setGain(GAIN_ONE);}             // 1x gain   +/- 4.096V  1 bit = 0.125mV
    else if(gain==2){adc.setGain(GAIN_TWO);}             // 2x gain   +/- 2.048V  1 bit = 0.0625mV
    else if(gain==4){adc.setGain(GAIN_FOUR);}            // 4x gain   +/- 1.024V  1 bit = 0.03125mV
    else if(gain==8){adc.setGain(GAIN_EIGHT);}           // 8x gain   +/- 0.512V  1 bit = 0.015625mV
    else if(gain==16){adc.setGain(GAIN_SIXTEEN);}        // 16x gain  +/- 0.256V  1 bit = 0.0078125mV

    
    
    int16_t buffer;
    buffer=adc.readADC_SingleEnded(0); emitValue<output_A0>(ctx, buffer);
    buffer=adc.readADC_SingleEnded(1); emitValue<output_A1>(ctx, buffer);
    buffer=adc.readADC_SingleEnded(2); emitValue<output_A2>(ctx, buffer);
    buffer=adc.readADC_SingleEnded(3); emitValue<output_A3>(ctx, buffer);
    buffer=adc.readADC_Differential_0_1(); emitValue<output_A0_1>(ctx, buffer);
    buffer=adc.readADC_Differential_2_3(); emitValue<output_A2_3>(ctx, buffer);
    emitValue<output_DONE>(ctx, 1);
}

}

Your library is really nice!!! I feel like your new library would make an excellent source for demonstrating the building and use of libraries, as an update to what is on the XOD website, currently - or as an “advanced tutorial”. The library is so beautifully put together, it really clears a lot of stuff up for me regarding XOD C++ nodes. THANK YOU!!!

You’re welcome. Thanks for the feedback. I’ve actually already created a tutorial on wrapping Arduino libraries:

Many thanks to @san43 for transforming my rough draft into a professionally formatted document.

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.