Your Location is: Home > Raspberry-pi2

How to pass I2C addresses to Adafruit CircuitPython code? (Running ADS1115)

From: Bern View: 4844 Iotatron 

Question

I'm trying to run two Adafruit ADS1115s off of one Raspberry Pi, using two I2C addresses (0x48, 0x49). The address for each device can be set by tying the ADDR pin high (0x49) or leaving it floating (default, 0x48). I've confirmed that each board works when the address is set to 0x48, and running "i2cdetect 1" confirms that both boards are connected at the correct addresses.

I can successfully run this sample code

My question is this: How do I get the code to read from I2C address 0x49 instead of 0x48? I can't find documentation anywhere. Please advise.

Best answer

Since there is a Python library the rules of Python language are applied, in particular OOP with class inheritance. That said, The class ADS1115 is inherited from ADS1x15, which in its turn has __init__() method (in OOP constructor) defined as follows:

def __init__(self, address=ADS1x15_DEFAULT_ADDRESS, i2c=None, **kwargs):

which means that it knows about at least two positional arguments with names address and i2c with default values ADS1x15_DEFAULT_ADDRESS and None respectively. So, you need in your code redefine them, i.e. instead of ads = ADS.ADS1115(i2c) use

ads = ADS.ADS1115(address=0x48, i2c=i2c)

For the second put there 0x49.

Another answer

Aha!
ads1 = ADS.ADS1115(i2c, address=0x49)

Source: https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15/issues/20