Page 1 of 1

How to Use More than one ADS1115

Posted: Tue Oct 01, 2019 1:27 pm
by TerryC65

We've been using Adafruit ADS1115 A/D Converters in our project to measure various voltages from sensors with great success. So far, each Pi in the system has been able to cater for all the sensor values at that location using a single converter. Here is a code fragment that we used:

Code: Select all

import board
import busio
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn

# Create the I2C bus
i2c = busio.I2C(board.SCL, board.SDA)

# Create the ADC object using the I2C bus
    ads = ADS.ADS1115(i2c)
except OSError:
    print(" OSError. No ADS Device.")
except ValueError:
    print(" ValueError. No I2C Device.  Exiting...")

# Create four single-ended inputs on channels 0 to 3
    chan0 = AnalogIn(ads, ADS.P0)
    chan1 = AnalogIn(ads, ADS.P1)
    chan2 = AnalogIn(ads, ADS.P2)
    chan3 = AnalogIn(ads, ADS.P3)
except OSError:
    print(" OSError. A/D Channel(s) missing.")
We have one last requirement; we have three sensors at a single location, each needing four channels of measurement. I've sussed out how to set up the addressing, so we can physically install three A/D Converters, each connected to the Pi via the I2C Bus. The first of these has the default address of 0x48 (configured in the Adafruit CircuitPython Module) and the other two are 0x49 and 0x4B respectively. So far so good.

I've looked at the code in the Adafruit Git Repository ( ... it_ads1x15), but cannot see how to pass the required address. I realise that it isn't the Adafruit device that needs the address; it's the I2C bus, so I had a look at it from that point of view. The problem is that I'm not 100% happy with the code side of things, so I'm uncertain as to the best approach.

I believe that I will have to create three objects (ads1, ads2, ads3), but how do I pass the addresses to ads2 and ads3?

Re: How to Use More than one ADS1115

Posted: Tue Oct 01, 2019 1:50 pm
by DirkS
From the code you link to:

Code: Select all

class ADS1x15(object):
    """Base functionality for ADS1x15 analog to digital converters."""

    def __init__(self, i2c, gain=1, data_rate=None, mode=Mode.SINGLE,
You can see the 'address' parameter is set to the base address.
You need to overrule it:

Code: Select all

ads2 = ADS.ADS1115(i2c, address=0x49)

Re: How to Use More than one ADS1115

Posted: Tue Oct 01, 2019 2:01 pm
by TerryC65
Many thanks. I was wondering if I could do that, but my lack of coding experience meant that I was looking too deep at the problem.