ADS1115 gives the same value on every input

Hello. I have an ADS1115 from aliexpress: https://www.aliexpress.com/item/16-Bit-I2C-ADS1115-Module-ADC-4-channel-with-Pro-Gain-Amplifier-RPi-1PCS/32882005440.html

Now i have the prolem that i always have the same value on every input.
What's the problem here? I use this code:

#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads(0x48);
float Voltage = 0.0;
float Voltage2 = 0.0;

void setup(void)
{
  Serial.begin(9600);
  ads.begin();
}

void loop(void)
{
  int16_t adc0, adc1;  // we read from the ADC, we have a sixteen bit integer as a result

  adc0 = ads.readADC_SingleEnded(0);
  adc1 = ads.readADC_SingleEnded(1);
  Voltage = (adc0 * 0.1875) / 1000;
  Voltage2 = (adc1 * 0.1875) / 1000;

  Serial.print("AIN0: ");
  Serial.print(adc0);
  Serial.print("\tVoltage: ");
  Serial.println(Voltage, 7);
  Serial.println();

  Serial.print("AIN1: ");
  Serial.print(adc1);
  Serial.print("\tVoltage: ");
  Serial.println(Voltage2, 7);
  Serial.println();

  delay(100);
}

I connected a Joystick with two axis. One axis to adc0, the other to adc1.

Sample output:

AIN1: 15281	Voltage: 2.8651874

AIN0: 15281	Voltage: 2.8651874

AIN1: 15274	Voltage: 2.8638749

AIN0: 15274	Voltage: 2.8638749

AIN1: 15327	Voltage: 2.8738124

AIN0: 15327	Voltage: 2.8738124

AIN1: 16217	Voltage: 3.0406876

AIN0: 16217	Voltage: 3.0406876

AIN1: 17575	Voltage: 3.2953124

AIN0: 17575	Voltage: 3.2953124

AIN1: 17577	Voltage: 3.2956874

AIN0: 17577	Voltage: 3.2956874

AIN1: 17576	Voltage: 3.2955000

AIN0: 17576	Voltage: 3.2955000

AIN1: 14334	Voltage: 2.6876249

AIN0: 14334	Voltage: 2.6876249

AIN1: 13746	Voltage: 2.5773749

AIN0: 13746	Voltage: 2.5773749

AIN1: 15324	Voltage: 2.8732500

AIN0: 15324	Voltage: 2.8732500

AIN1: 10789	Voltage: 2.0229375

AIN0: 10789	Voltage: 2.0229375

AIN1: 3749	Voltage: 0.7029375

AIN0: 3749	Voltage: 0.7029375

Suigor:
Hello.

Hello there!

I was reading through your code and found something that appeared strange to me. I have never used this device so I can't be sure.

Suigor:
#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads(0x48);

In your library inclusion you have "Adafruit_ADS1015.h", but your class constructor is "Adafruit_ADS1115". Is this intentional?

Thanks for your answer bos1714.

Yes, it's the library for the ads1015 and ads1115 as well. So this is fine. GitHub - adafruit/Adafruit_ADS1X15: Driver for TI's ADS1015: 12-bit Differential or Single-Ended ADC with PGA and Comparator

I use the ESP32, maybe this is important. I saw that the library was not testet for the ESP32.

I noticed something. When i add a delay between the readouts they are different, but they seem to be wrong then:

 adc0 = ads.readADC_SingleEnded(0);
  delay(100);
  adc1 = ads.readADC_SingleEnded(1);

Could there be a problem with the I2C Communication?

I believe the ESP32 is a 3.3V board. What is the operating voltage of the ADS1115?

Input voltage: 2.0-5.5v

Can you post a schematic of your setup?

I made a photo: :slight_smile:
https://photos.app.goo.gl/zaJBh8HNDK1grYk17

The potentiometer of the joystick are connected each to ground and 3.3v, the middle pins from the potentiometer to a0 and a1 of the ADS11115.

The joystick does work when connected to analog inputs of the ESP32 directly, but the inputs of the ESP32 are not linear.

ESP32 doesn't really narrow it down. Is this Heltec WIFI KIT 32 your board?

Yes exactly, i use the heltec board.

Suigor:
I noticed something. When i add a delay between the readouts they are different, but they seem to be wrong then:

 adc0 = ads.readADC_SingleEnded(0);

delay(100);
 adc1 = ads.readADC_SingleEnded(1);




Could there be a problem with the I2C Communication?

I have a feeling that this might be your answer. The Adafruit_ADS1x15 library uses a hard coded delay() between requesting a conversion and reading the answer back. For the ADS1015 that is a 1ms delay, and for the ADS1115 it is a 8ms delay. If my sums are right, then the conversion at the default sample rate on the 1015 takes 0.625ms to complete, and on the 1115 it takes 7.81ms - presumably the I2C overhead and whatnot gets added to these. So that's a bit less overhead on the 1115 available.

If the conversion is read before it completes then you end up getting the previous value, not the requested one. Which might explain the identical readings.

Try editing your library Adafruit_ADS1015.h and increase ADS1115_CONVERSIONDELAY to 9ms (or a bit more if necessary to be sure).
Make sure that the library recompiles after the change - maybe quit the IDE and restart it.

If the results then differ, we can then look into why you think they are not correct.

Suigor:
The potentiometer of the joystick are connected each to ground and 3.3v, the middle pins from the potentiometer to a0 and a1 of the ADS11115.

The joystick does work when connected to analog inputs of the ESP32 directly, but the inputs of the ESP32 are not linear.

Not correct, since that ADS1115 has several full-scale voltages, and none of them is 3.3volt.
The ADS1115 is not designed for ratiometric sensors, like pots.
Zero-point will drift if you use this A/D.
I think the best you can do is power the pots from a 2.048volt voltage reference, and use a PGA gain of 2.

ESP A/Ds have the same problem. Made for absolute (voltage) sensors, not for ratiometric sensors.
There should however not be a problem with linearity, assuming you use the right attenuation setting.
Leo..

arduarn:
Try editing your library Adafruit_ADS1015.h and increase ADS1115_CONVERSIONDELAY to 9ms (or a bit more if necessary to be sure).
Make sure that the library recompiles after the change - maybe quit the IDE and restart it.

Thank you. I set it to 10 ms and now it works fine!

arduarn:
I have a feeling that this might be your answer. The Adafruit_ADS1x15 library uses a hard coded delay() between requesting a conversion and reading the answer back. For the ADS1015 that is a 1ms delay, and for the ADS1115 it is a 8ms delay. If my sums are right, then the conversion at the default sample rate on the 1015 takes 0.625ms to complete, and on the 1115 it takes 7.81ms - presumably the I2C overhead and whatnot gets added to these. So that's a bit less overhead on the 1115 available.

If the conversion is read before it completes then you end up getting the previous value, not the requested one. Which might explain the identical readings.

Try editing your library Adafruit_ADS1015.h and increase ADS1115_CONVERSIONDELAY to 9ms (or a bit more if necessary to be sure).
Make sure that the library recompiles after the change - maybe quit the IDE and restart it.

If the results then differ, we can then look into why you think they are not correct.

Thanks Man !!!!!!

@OP

Check if you need to include the following/similar line in the setup() function of your ESP32-Master's sketch.

Wire.begin(4, 5); //GPIO-4 = SSDA, GPIO-5 = SCL

arduarn:
If the conversion is read before it completes then you end up getting the previous value, not the requested one. Which might explain the identical readings.

Try editing your library Adafruit_ADS1015.h and increase ADS1115_CONVERSIONDELAY to 9ms (or a bit more if necessary to be sure).
Make sure that the library recompiles after the change - maybe quit the IDE and restart it.

If the results then differ, we can then look into why you think they are not correct.

I cannot just read this, and don't say even "Thank you!" I struggled for a day or so trying to figure out why the ADS1115 was giving me the same reading for every input pin, just like Suigor posted. Anyway, after changing the conversion dalay to 9 for the ADS1015(12 bit), bingo! All 4 inputs work the way I expected: each input providing a different reading. Once again, thank you, arduarn!

NOTE: I notice that if I feed 1.5V to any input pin, I get a little higher than that, for example feeding 3.2V, I get 3.4+ volts, well this is not good, this will trow off the results. I solved this by multiplying the result by a factor of 0.936.

I am interfacing this ADC with the MKR1000, the MKR1000's analog inputs drift too much as we know, this ADC provides a very stable input, basically it does not drift at all.
I am reading three analog sensors for my Personal Weather Station: the vane or wind direction, the UV index sensor, and the solar radiation sensor.

These are my two cents.