DF Robot ADS1115 issues

Hello everyone, I write you here because I am having some small issues with an ADS1115 converter I am using to measure some linear potentiometers. I am quite a newbie so everything I learned until now was by myself, please be indulgent if I ever did a rookie mistake.

The converter I use is then the ADS1115 provided by DFRobot, it's for a work project and was already there before I came to this job. Our aim is to measure the signal out of linear potentiometers used in race cars at a high rate and look at their trace in the Arduino IDE plotter for eventual noise.

I have been trying this first with a Raspberry Pi we had at our workshop and did a small Python program which was working pretty well, except the fact that it was way too slow. I could only log at 10 Hz, when we are looking for minimum 50Hz and ideally around 100. I though it was due to the fact that Python might be a slow language, I don't really know, so having an Arduino at home I decided to use instead. However, with the library provided by DFRobot, I got exactly the same results. Having nothing to loose, I switched to the Adafruit library, and now I finally got what I wanted ! That's to say around 90 Hz, I'm absolutely happy with that.

But, as there is obviously a but...the values are not correct anymore. I expect to read values between 0 and 5V, and now I start at around 20,000 mV with the potentiometer fully closed, and I go down to 14-15,000 mV only when it is fully opened. So it looks like I have an offset for some reason, maybe like the gain is not properly set anymore. I can still look at the trace, but like this it's difficult to say if any noise I would see is bad or not because of the wrong scale. Does somebody now how to fix that maybe ?

I tried to give as many details as possible, but should you need any other information, just let me know. Thanks in advance !

Please post the code, using code tags, and a complete wiring diagram (hand drawn is fine).

Posting instructions are found in the "How to get the best out of this forum" post, linked at the head of very forum category.

I believe the library default sampling rate is 10 Hz, but there are other problems.

Thanks for your answer, this is my code with the Adafruit library (that's to say with a proper logging rate but wrong values displayed) :

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

Adafruit_ADS1115 ads1115;

void setup(void)
{
  Serial.begin(9600);
  ads1115.begin();
  ads1115.setGain(GAIN_TWOTHIRDS);
}

void loop(void)
{
  int16_t adc0;
  adc0 = ads1115.readADC_SingleEnded(0);
  Serial.println(adc0);
  delay(1);
}

Here is my wiring diagram, I respected exactly what DF Robot is telling :

Let me know if you need something else and thanks again !

It doesn't show what is connected to the ADC.

Serial.begin(9600);
The above Baud rate is 1000 characters transmitted per second, or at most around 100 values/second. Set the Baud rate to 115200 or higher, and remove the delay(1)

Add this line after .setGain:

  ads1115.setDataRate(RATE_ADS1115_250SPS);

Here are the possible data rates (from the library code):

#define RATE_ADS1115_8SPS (0x0000)   ///< 8 samples per second
#define RATE_ADS1115_16SPS (0x0020)  ///< 16 samples per second
#define RATE_ADS1115_32SPS (0x0040)  ///< 32 samples per second
#define RATE_ADS1115_64SPS (0x0060)  ///< 64 samples per second
#define RATE_ADS1115_128SPS (0x0080) ///< 128 samples per second (default)
#define RATE_ADS1115_250SPS (0x00A0) ///< 250 samples per second
#define RATE_ADS1115_475SPS (0x00C0) ///< 475 samples per second
#define RATE_ADS1115_860SPS (0x00E0) ///< 860 samples per second

How are you measuring the potentiometers? How are they connected to the ADC?

Also note that the Adafruit library contains a delay that limits the sample rate to 125Hz max.

The ADS1115 is an absolute A/D, meaning it's perfect for measuring voltages,
but a poor choice for measuring ratiometric sources like potentiometers.

Why don't you just measure the pots with the (ratiometric) A/D of the Uno.
Much faster too (100us per pot).
Leo..

Good morning everyone, thanks for your answers and sorry for the delay

It doesn't show what is connected to the ADC.

Sorry, for that, here a picture of how the potentiometer is connected to the ADC (5V to the red, GND to the black and the signal to the blue pins of the A0 line)

I tried with the changes you advised by the way but I do not see any difference, I still get values that are not likely...

I just would like to measure the signal going out of the potentiometer, so nothing else than its voltage. But I had never heard about this other solution as I am discovering all of that like I said in my first post. I can obviously try it and check what it gives, so do you maybe have some explanations about how to do that with the "A/D of the Uno", and if there is already a library I could use somewhere ? Thanks !

That's not an easy task with an ADS1115, because returned voltage depends on pot position and pot supply. If 5volt supply varies 1%, so will your output voltage. You can use the ADS1115, as long as you also have a very stable pot supply, and/or measure pot supply with a second channel of the ADS1115. Powering the pot from the more stable 3.3volt pin of the Uno would be an improvement.

What are your requirements regarding resolution and stability, and what is the value is that pot.

Using the A/D of the Uno is easy. Just connect the pot to 5volt/ground, and the wiper to A0.
int potValue = analogRead(A0);
The Uno R3 only has a 10-bit A/D (1024 values), but it's A/D is supply voltage independent.
The ADS1115 is 15-bit single-ended.
Question is if the resolution of the pot itself requires more than 10-bit.
Leo..

Are they between 26667 and 0?
If yes, then they are correct.
They are the raw ADC output

Hi everyone, thank you for your replies. I was unfortunately abroad for a while and couldn't check this before. I have retried all the solutions and here is a little summary of them :

  • Method 1 : without ADS1115 converter (connected to 5V/ground/A0)
    --> values between 1024 and 0 (I guess because of 10 bits resolution)
    --> around 2.000 values per second with 115.200 bauds (a lot more than I actually need)

  • Method 2 : with ADS1115 converter and Adafruit library :
    --> values between 27070 and 0 on the serial monitor
    --> around 90 values per second (perfect)

  • Method 3 : with ADS1115 converter and DFRobot library :
    --> values between 5076 and 0 (perfect, just like on the car)
    --> around 10 values per second (too slow)

What I then would like to achieve is getting the same values as I would read on the car (that's to say what I read with the DFRobot library) with the speed from the Adafruit library. What are your advices for that, if it's possible ? Thanks a lot again !

Based on Arduino ADC 0 - 1024 corresponds to 0 - 5Volts. Looks OK.

Based on Adafruit ADS1115 27070 - 0. At 2/3 gain the FSR is 6.144V. (27070/32768) * 6.144 ~= 0-5V. Also looks OK.

Based on DFRobot assuming you are still using 2/3 gain (5076/32768)*6.144V = 0.95V.

"Just like on car" does not tell us anything. Changing libraries should not change the reading from the ADS1115.

Something else is going on here.

One approach would be to use the Adafruit library and apply a scale factor of 5076.0/27070.0 to the data.

So upon examining the DFRobot code it is returning a Voltage value in mV hence 5076 or approximately 5V as well.

You can use the Adafruit library which returns the 15bit value and convert the 15bit ADC reading to mV to get presumably "whats on the car". Or you can modify the DFRobot code to reduce the 100ms conversion delay it is adding.

Examine the .cpp and .h files for the library of choice to get a clear picture of what each is doing.