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,665
  • 3
  • 10
  • 24
Jack
  • 686
  • 3
  • 7
  • 19
  • basing on your response and joan, i would assume it not possible to change the pins of i2c. – Jack Oct 12 '19 at 22:06
  • I appologize i ment add another i2c bus, i am actually aware there thara 2 i2c buses but, unfortunately i would still be lacking – Jack Oct 12 '19 at 22:17
  • yes, i am currently looking for a 4channel alternative to the one joan gave, i already found one but it does not contain a reset function, is this feature necessary even ? – Jack Oct 12 '19 at 22:33
  • did you ever experience your i2c slave device freezes ? – Jack Oct 12 '19 at 22:49

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,024
  • 5
  • 73
  • 106
  • With 4 possible addresses 256 should be possible, I guess. – Tomas By Oct 12 '19 at 22:12
  • you are actually right on your last statement. How would you approach the board design, because i was planning on a stackable shield,with the difference is just a jumper resistor connecting to the appropriate address. I was thinking on a single board 1 TCA9548A and 2 ADS1115. and since you can use 8 TCA i can have a total of 1 ADS which meets my needs, but is this setup the most efficient? – Jack Oct 12 '19 at 22:13
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,791
  • 3
  • 16
  • 20
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,665
  • 3
  • 10
  • 24
  • There will be no problem about cable length since i am planning on stacking shields, using my custom pcb. But i am now where at your stage yet that needs 64 devices. I have read somewhere there are i2c extenders, if you have not checked that out yet – Jack Oct 14 '19 at 15:21
  • @Jack, Ah, stacking shields is a vary complex task. My first impression is that you are over ambitious. Of course you can convenience me to change my mind, perhaps telling me a bit of your stacking shields experience. Yes, I have tried the I2C extenders, perhaps I can show you tomorrow. Cheers. – tlfong01 Oct 14 '19 at 15:29
  • I dont know about in your place, but where i am currently living there is a place where i can let them make my pcb for about a dollar a piece. and since i design my schematics on cads anyway designing the pcb is just a little bit more effort. Though this my first time doing Raspberry pi shields, i had good results with my shield making on arduinos. I will of course start with one shield, and move on from there – Jack Oct 15 '19 at 16:41
  • @Jack, I updated my answer with references (Ref 5) on I2C bus extender (P82B715). My experience is that even if you use short wiring, bus extenders (on top of TSX01n level shifter/buffer) are still useful (to overcome the 400pF capacitance limit). More references to come. Comments welcome. – tlfong01 Oct 16 '19 at 07:03
  • @Jack, I don't design PCBs myself. I am sort of "system integrator", gluing PCBs together on a proto board, and then stack up protoboards to make a "tower". Perhaps I can show you my towers of proto board stack later. Using ADS1115 for example, I usually shop around AliExpress, and order from TaoBao which is much cheaper, because they directly ship from my neighbouring city ShanZhen. I usually buy from a couple of TaoBao's reputable shops selling CJMCU/GY brand "purple" PCBs. See my references 6, 7. – tlfong01 Oct 16 '19 at 07:45
  • @Jack, One big difference between you and my project is that I am chasing moving targets, from Arduino Decimilla/Mega to Rpi 1/2/3/4, MCP3008 to ... ADS1115, the list is long. I still have not the feeling that I am ready to design PCB, because the PCB would be ridiculously big (A1 size). – tlfong01 Oct 16 '19 at 08:16
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
  • 886
  • 7
  • 13