0

I am using the ADS1015, which is a 12-bit ADC from adafruit. I have it hooked up to a Logic Level Converter using I2C to communicate to the Pi. I have two sensors hooked up to the I2C device, so I need to change the address of the ADS1015 to read from both sensors because they currently have the same address (0x48). I am using the Adafruit ads1x15 python library right now, and I am wondering if there is an easy way to change the I2C address of the ADS1015 in my code.

Here's my code so far:

from smbus import SMBus
import board
import busio
import time

import adafruit_ads1x15.ads1015 as ADS from adafruit_ads1x15.analog_in import AnalogIn from adafruit_ads1x15.ads1015 import Mode

i2cbus_1 = SMBus(1) i2cbus_2 = busio.I2C(board.SCL, board.SDA)

ads = ADS.ADS1015(i2cbus_2) chan = AnalogIn(ads, ADS.P0)

user134624
  • 17
  • 2
  • 1
    See https://circuitpython.readthedocs.io/projects/ads1x15/en/latest/api.html#ads1015. add the address parameter when creating the ADS1015 instance – Dirk Jun 10 '21 at 15:25

2 Answers2

0

Answer

Errata and Apology

Many thanks for @Gil pointing out my silly mistake for saying the following:

An easy way to set the ADS1015/ADS1115 devices is to hardware pull up/down the four Address pins A0, A1, A2, A3.

Actually A0~A3 are analog input lines AIN0~AIN3. (See @Gil comment below.)


ads1115 address pins


See the Q&As in the reference list for more details.


References

(1) Rpi Thonny Python cannot ADS1015/ADS1115 Problem - RpiSE 2019apr16 Viewed 1k times

(2) How can Rpi3/4 interface multiple ADS1015/ADS1115 ADCs? - RpiSE 2019oct12


Appendices

Appendix A - I2cdetect -y 1 two ADS1115s

ads1115 detect


Appendix B - Demo Python Program to red ADS1115 registers


$ ads1015_test16_2019apr1601 tlfong01 2019apr16hkt1506
$ Rpi3B+ stretch linux 4.14.34-v7+ arm python 3.5.3

import smbus

i2cCh0 = smbus.SMBus(1)

def readRegOneByte(i2cCh, devAddr, regAddr): readByte = i2cCh.read_byte_data(devAddr, regAddr) return readByte

def testReadRegWhoAmI(): print('\n*** Begin test \n') devAddr = 0x48 regAddr = 0x71 readByte = readRegOneByte(i2cCh0, 0x48, 0x71) print(' devAddr =', hex(devAddr)) print(' regAddr =', hex(regAddr)) print(' regContent =', hex(readByte)) print('\n End test ') return

$ Main

testReadRegWhoAmI()

$ End


tlfong01
  • 4,665
  • 3
  • 10
  • 24
  • 1
    If you look at the data sheet it is a 4-channel, delta-sigma ADC with PGA, oscillator, VREF, comparator and I2C. The A0- to A3 are Not address lines but analog inputs. There is one address select pin ADDR, pin 1 of the IC, and It may be a jumper/trace option on the board. This would allow two of them. on the same bus. They also make multiplexers for I1C devices. I do not have a board handy to check this. – Gil Mar 03 '23 at 18:21
  • @Gil: Many thanks for pointing out my silly mistakes. You are absolutely right in saying that The *A0~A3 are actually AIN0~AIN3 analog input lines*. Let me write an Errata now. – tlfong01 Mar 05 '23 at 08:19
  • 1
    Not a problem, I had to double check to be sure, I appreciated the link to the data sheet, it helped a lot. – Gil Mar 05 '23 at 22:40
0

I think the ADS1015 has 4 channels, all which can be read using the same address, you only need to change the I2C address if you have more ADS1015 chips or have a clash of addresses with other devices.

From the chip documentation:

  1. Write to Config register: – First byte: 0b10010000 (first 7-bit I2C address followed by a low R/W bit)
    – Second byte: 0b00000001 (points to Config register)
    – Third byte: 0b10000100 (MSB of the Config register to be written)
    – Fourth byte: 0b10000011 (LSB of the Config register to be written)
  2. Write to Address Pointer register:
    – First byte: 0b10010000 (first 7-bit I2C address followed by a low R/W bit)
    – Second byte: 0b00000000 (points to Conversion register)
  3. Read Conversion register:
    – First byte: 0b10010001 (first 7-bit I2C address followed by a high R/W bit)
    – Second byte: the ADS101x response with the MSB of the Conversion register
    – Third byte: the ADS101x response with the LSB of the Conversion register

Which basically means, select the config register(1 above) and change which ADC inputs are to be read from, followed by selecting the conversion register(2 above). The chip then replies to the read command(3 above) with the last conversion sent in two bytes.

If you are going to read from a single channel as compared to ground then the conversion register as the third byte (in 1 above) should have the bit pattern 0b1xxx0100 where xxx is the MUX field:
000 : AINP = AIN0 and AINN = AIN1 (default)
001 : AINP = AIN0 and AINN = AIN3
010 : AINP = AIN1 and AINN = AIN3
011 : AINP = AIN2 and AINN = AIN3
100 : AINP = AIN0 and AINN = GND
101 : AINP = AIN1 and AINN = GND
110 : AINP = AIN2 and AINN = GND
111 : AINP = AIN3 and AINN = GND

Therefore to read from...
channel 0, replace xxx with 100, ie 0b11000100 or 0xC4
channel 1, replace xxx with 101, ie 0b11010100 or 0xD4
channel 2, replace xxx with 110, ie 0b11100100 or 0xE4
channel 3, replace xxx with 111, ie 0b11110100 or 0xF4

The other bit patterns are for comparisons between two analogue inputs.

In this example 0b11000100 we want read from channel 1 hence the pattern 100 in bits 4:6, bits 1:3 or 010 selects the gain amplification (PGA field) of +- 2.048V, whilst the most significant bit, bit 7 sets to start a single conversion. Bit 0, the MODE field, being clear means set Continuous-conversion mode.

The first byte in each case in the above example is the I2C address 0x48 shifted left by 1 bit and either 0 or 1 added as the least significant bit, 0 for write, 1 for read.

Documentation: https://www.ti.com/product/ADS1015

Bill
  • 1
  • 2