1

Hello i am creating a shield for raspberry Pi 3/4 and in need of a lot of analog pins to read 30 sensors. and since the shield can only fit 5 sockets of the connector i am using i need to use 2 ADS1115 on a single shield. This brings me to a total of 12 ADS1115 to read 30 sensors. I chose this chip instead of the others because adafruit already made a library for it which makes coding a bit easier.

Can i connect 12 i2c devices on the default i2c raspberry pins? Is it possible to make the other GPIO pins as i2C?

tlfong01
  • 4,847
  • 3
  • 12
  • 24
Jack
  • 714
  • 3
  • 8
  • 19

4 Answers4

3

You can connect as many devices as you want to an I2C bus as long as you can give each a unique address.

If you can't change the device address you can use an I2C multiplexor to connect up to 8 of the devices to a single I2C bus. You enable the device you want to talk to by sending a control byte to the multiplexor.

The TCA9548A is an example of a multiplexor. You can connect up to 8 TCA9548A to a single bus so can connect up to 64 ADS1115 to the Pi via the standard I2C bus.

I would not design a system based on the opinion that the software for one part may be simpler. You should consider the overall system compexity.

joan
  • 71,852
  • 5
  • 76
  • 108
2

This article explains how to add another 5 I2C buses, using spare GPIO pins, in addition to the default IC2-1 bus. https://www.instructables.com/Raspberry-PI-Multiple-I2c-Devices/#discuss

I was able to add i2c-4 bus in the /boot/config.txt file with:

dtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=1,i2c_gpio_sda=17,i2c_gpio_scl=27

Reboot and then sudo i2cdetect -y 4 correctly show the attached ADS1115 at address 0x.48

By reading the ADS1115 datasheet at https://www.ti.com/product/ADS1115 I found on page 34, figure 42 shows how to wire the Address line to get 4 different address. In simple English, these are the required connections:

  • for addr 0X48, ADDR --> GND
  • for addr 0X49, ADDR --> VDD
  • for addr 0x4A, ADDR --> SDA
  • for addr 0x4B, ADDR --> SCL

There are more notes on page 23, section 9.5.1.1 on address selection.

So by putting 4 ADS1115 on each of 6 I2C bus, you could control 24 ADS1115 and monitor 96 single-ended analog inputs.

I have successfully tested 2 ADS1115 on I2C-1 at the same time as 1 ADS1115 on I2C-4. For my project, 4 ADS1115 on IC2-1 bus will be sufficient.

It doesn’t look like you hardware multiplexor/expanders for lots of ADS1115 fan-out.

For python control of higher numbered I2C buses, the Adafruit support folks told me to use adafruit-extended-bus package.

type: pip3 install adafruit-extended-bus

Code from my test script is:

# demo script showing use of 2 different I2C bus
# I2C-1 has devices 0X48 & 0X4b, I2C-4 has device 0X48

import board, busio, time, traceback import adafruit_ads1x15.ads1115 as ADS from adafruit_ads1x15.analog_in import AnalogIn from adafruit_extended_bus import ExtendedI2C as I2C

Create two I2C bus, default & custom #4 per /boot/config.txt

i2c_1 = busio.I2C(board.SCL, board.SDA) i2c_4 = I2C(4) # custom #4 per /boot/config.txt

Create the ADC objects using two I2C bus

ads10 = ADS.ADS1115(i2c_1, address=0x48) ads13 = ADS.ADS1115(i2c_1, address=0x4b) ads40 = ADS.ADS1115(i2c_4, address=0x48)

Create single-ended inputs on i2c-1 bus

ch1_48_0 = AnalogIn(ads10, ADS.P0) ch1_48_1 = AnalogIn(ads10, ADS.P1) ch1_48_2 = AnalogIn(ads10, ADS.P2) ch1_48_3 = AnalogIn(ads10, ADS.P3)

ch1_4b_0 = AnalogIn(ads13, ADS.P0) ch1_4b_1 = AnalogIn(ads13, ADS.P1) ch1_4b_2 = AnalogIn(ads13, ADS.P2) ch1_4b_3 = AnalogIn(ads13, ADS.P3)

Create single-ended inputs on i2c-4 bus

ch4_48_0 = AnalogIn(ads40, ADS.P0) ch4_48_1 = AnalogIn(ads40, ADS.P1) ch4_48_2 = AnalogIn(ads40, ADS.P2) ch4_48_3 = AnalogIn(ads40, ADS.P3)

And it works, I can now read data from I2C-1 & I2C-4 devices.

MatsK
  • 2,882
  • 3
  • 17
  • 22
1

Answer

A year ago, I spent 200+ hours messing around with Rpi3B+ stretch 100kHz I2C bus and devices. My humble dream was to connect 64+ devices, mcp23017, ads1115 etc, on a bus.

To add as many devices as possible, I struggled with I2C mux/demux, extender/expander, and also multiple I2C buses per Rpi3B+. Sadly, there are too many things that I didn't know that I didn't know, and my long, sad story short is a broken dream.

One bottleneck I always remember is that I2C has a capacitance limit of 400pF, a block I was not knowledgeable to jump over.

My conclusion is that putting more than 6 devices on a 30+ cm long, low speed I2C bus, even using CAT5/UTP wiring, is practically unstable/unreliable.

(Yes, I know, many "experts" claim that it is "doable".)

Recently I happily updated myself to Rpi4B and I have successfully tested 3 stable low speed I2C buses. So my humble dream now is 24+ mcp23017/ads1115 etc each Rpi4B.

/ to continue, ...

References

(1) how to communicate with navio2, raspberry pi 3 to ard-ltc1867 using i2c protocol to read analog data

(2) Seeed ADC (ADS1115) with Raspberry Pi 3 B+to read voltage values using python3

(3) How to connect two BME280 sensors via I2C to a Raspberry Pi 3B+ (Read my comments)

(4) P82B715 I2C-bus extender datasheet - NXP

(5) P82B715 I2C-bus Extender Learning Notes - tlfong01 2008

www.raspberrypi.org/forums search "P82B715" + "tlfong01" = 19 matches

(5.1) https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=77158&p=1352373&hilit=P82B715#p1351758

(5.2) https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=77158&p=1352373&hilit=P82B715#p1351929

(5.3) https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=77158&p=1352373&hilit=P82B715#p1352201

(5.4) https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=77158&p=1352373&hilit=P82B715#p1352292

(5.5) https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=77158&p=1352373&hilit=P82B715#p1352373

(6) Purple PCB Fabrication etc

(6.1) Oshpark and Elecrow PCB Fabrication Service

(6.2) https://oshpark.com/

(6.3) https://oshpark.com/#aboutus

(6.4) https://pcbshopper.com/osh-park-reviews/

(6.5) https://www.wellpcb.com/purple-pcb.html

(6.6) https://www.youtube.com/watch?v=HH3hoeFjS8w

(6.7) https://www.elecrow.com/pcb-manufacturing.html

(7) GY/CJMCU Purple/Blue ADS1115 I2C ADC Module - US$1.6

(7.1) https://www.aliexpress.com/w/wholesale-ads1115.html?switch_new_app=y

(7.2) https://fr.aliexpress.com/item/32590193920.html

(7.3) https://fr.aliexpress.com/item/32637401475.html

(7.4) https://fr.aliexpress.com/item/32462143150.html

Appendices

Appendix A - PCBs stacked on to proto boards

pcb stack

Appendix B - Proto boards stacked on to towers

proto board stack example

/ to continue, ...

tlfong01
  • 4,847
  • 3
  • 12
  • 24
1

The ADS1115 can be configured to 4 different addresses. For this you need to connect the ADDR pin to GND, VDD, SDA or SCL, respectivelly (the Adafruit PCB has it wired to GND via a Pull-Down, so this should work as well - I only tried wiring it to VDD, which did work).

The Pi4 has up to 4 I2C busses, at least according to the specificiation. I haven't seen any software supporting busses 2-4 yet, though.

PMF
  • 906
  • 7
  • 14