简体   繁体   中英

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

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.

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, ie instead of ads = ADS.ADS1115(i2c) use

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

For the second put there 0x49 .

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM