Interfacing with ADS1115 based ADC module in C

This post started mostly as asking for help, but I’ve figured most of it out. I’m posting it anyway as it might help others looking to do the same thing, as info appears to be scarce. There are a couple of questions I’ve placed at the end, though.

I’ve got one of these ADS1115 based ADC modules and have connected it to a Raspberry Pi 4 Model B. I’m writing a program in C, so the documentation for Python isn’t helpful. After some poking around I found this thread on the topic. The author of wiringPi gave a quick response without much detail, but it was useful.

I’ve made the following program using ads1115Setup and analogRead, and tested it with a 9V battery and voltage divider in several configurations. The ADC is connected to a 5V pin on the Pi.

#include <stdio.h>
#include <wiringPi.h>
#include <ads1115.h>
#define MY_BASE 2222

int main(int argc, char **argv)
    ads1115Setup(MY_BASE, 0x48);
    int ch0 = analogRead(MY_BASE + 0);
    printf("ch0: %d\n", ch0);

    return 0;

My multi-meter readings vs. the values returned are as follows:

Voltage Reading
0.18 1458
0.32 2612
1.67 13387
2.08 16641
2.75 21953
4.02 32034

As a chart:


Using this data I’ve worked out that the ADC is using the 4.096V Full-Scale Range. This is good enough for my purpose, but can anyone tell me how to make it use the 6.144V FSR?

Also, out of curiosity, why does the pin value 2222 work? It doesn’t seem to match any of the pin values that wiringPi accepts.

1 Like

Hi Tim
I don’t profess know anything about what you are trying to do but I do have an interest in measuring techniques.
You mentioned a voltage divider. What sort of resistance values are you using. You can get to a stage where your DMM with a resistance of 10MΩ has an influence. I once had occasion where measuring (or trying to) the input voltage to a PLC type device (Mitsubishi Alpha series controller) while monitoring the ADC numerical output lowered the ADC reading by 3 or 4 digits. This with a low resolution ADC (0 - 512).

Having said that, what you read as ??V on your meter IS actually what is present on the ADC input WITH THE METER CONNECTED. The problems can arise if the voltage changes (so the ADC number changes) when the meter is removed so there is a difficulty sometimes actually measuring what is happening accurately. Keeping voltage divider resistances as low as practical will minimise this problem I think this is why recommended potentiometer value is max is usually10k. Of course if the measured voltage source resistance is low this problem will not exist. If the source resistance gets too high the 10MΩ of the meter becomes part of the lower leg of a voltage divider and can influence measurement of the true voltage values. This can be demonstrated. Measure a power supply, say 5V. insert a 10MΩ resistor in series with the meter, you will now read 2.5V. This is extreme but does demonstrate how the input resistance of a DMM (or any other meter in fact) can influence the measurement. This does not have to be a huge problem as long as he user is aware if what is happening and can interpret any measurements accordingly.
Cheers Bob

1 Like

Hi Bob,

Thanks - I had not thought about the influence of the multi-meter’s resistance. Luckily I was using quite low values for the resistors in the voltage divider. The one I was measuring across was about 220Ω, adding others to the top to lower the measured voltage. At one point I ran it a few times rapidly and the returned value was ticking down. I guess it was draining the battery?


1 Like

The project itself is an adaptation of the rainwater tank monitoring system in issues 51 and 52 of DIYODE magazine. I need the ADC to measure the voltage over a ~100Ω shunt resistor which is in series with the 4-20 mA current loop pressure sensor. I’m more of a software engineer with a little background knowledge on electronics, so I’m learning a lot as I go.

Hi Tim
The 10MΩ meter is not going to worry that. But it is well worth keeping these affects in mind, particularly if you are ever getting strange unexpected results. The measurement techniques could well be causing them. Not only with DMMs, for instance an oscilloscope probe with an earth clip which is too long often will put ringing or other funny effects on a display which in the real world (without the oscilloscope) are not really there and only serve to worry and confuse the user.

But like I said. It does not have to be a problem as long as the user is aware of what can happen.
Cheers Bob

1 Like