0

TCA9548a + SHT31D connect
Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Please be positive and constructive with your questions and comments.

TCA9548a + SHT31D connect

by Mainzelman on Sun May 02, 2021 12:20 pm

Hello, Beginner help needed.
Raspberry PI 4, 1x TCA9548 + 2x SHT31D, Python3. How can I connect the SHT31 to the TCA9548 ?

i2cdetect -l
i2c-15 i2c i2c-1-mux (chan_id 4) I2C adapter
i2c-13 i2c i2c-1-mux (chan_id 2) I2C adapter
i2c-1 i2c bcm2835 (i2c@7e804000) I2C adapter
i2c-11 i2c i2c-1-mux (chan_id 0) I2C adapter
i2c-18 i2c i2c-1-mux (chan_id 7) I2C adapter
i2c-16 i2c i2c-1-mux (chan_id 5) I2C adapter
i2c-14 i2c i2c-1-mux (chan_id 3) I2C adapter
i2c-12 i2c i2c-1-mux (chan_id 1) I2C adapter
i2c-17 i2c i2c-1-mux (chan_id 6) I2C adapter
#
# Example code
#
#!/usr/bin/python3
import time
import board
import busio
import adafruit_sht31d
import adafruit_tca9548a

i2c=busio.I2C(board.SCL, board.SDA)

tca = adafruit_tca9548a.TCA9548A(i2c)

sht1 = adafruit_sht31d.SHT31D(tca[0])
sht2 = adafruit_sht31d.SHT31D(tca[1])

while 1:
print("Sensor #1: Temp: {}, RH: {}".format(sht1.temperature,sht1.relative_humidity))
print("Sensor #2: Temp: {}, RH: {}".format(sht2.temperature,sht2.relative_humidity))
print("-------------------------")
#
# Error
Traceback (most recent call last):
File "./Test-1.py", line 13, in <module>
sht1 = adafruit_sht31d.SHT31D(tca[0])
File "/usr/local/lib/python3.7/dist-packages/adafruit_sht31d.py", line 182, in __init__
self.i2c_device = I2CDevice(i2c_bus, address)
File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 50, in __init__
self.__probe_for_device()
File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 151, in __probe_for_device
while not self.i2c.try_lock():
#
# Print only TCA state
# Example code
#
#!/usr/bin/python3
import time
import board
import busio
import adafruit_sht31d
import adafruit_tca9548a

i2c=busio.I2C(board.SCL, board.SDA)

tca = adafruit_tca9548a.TCA9548A(i2c)

#sht1 = adafruit_sht31d.SHT31D(tca[0])
#sht2 = adafruit_sht31d.SHT31D(tca[1])

while 1:
# print("Sensor #1: Temp: {}, RH: {}".format(sht1.temperature,sht1.relative_humidity))
# print("Sensor #2: Temp: {}, RH: {}".format(sht2.temperature,sht2.relative_humidity))
print("-------------------------")
print(tca)
print(tca[0])
print(tca[1])
print(tca[2])
print(tca[3])
print(tca[4])
print(tca[5])
print(tca[6])
print(tca[7])
time.sleep(2)
#
# Output
<adafruit_tca9548a.TCA9548A object at 0xb66fdc90>
<adafruit_tca9548a.TCA9548A_Channel object at 0xb662e890>
<adafruit_tca9548a.TCA9548A_Channel object at 0xb6648230>
<adafruit_tca9548a.TCA9548A_Channel object at 0xb66482d0>
<adafruit_tca9548a.TCA9548A_Channel object at 0xb6648310>
<adafruit_tca9548a.TCA9548A_Channel object at 0xb6648350>
<adafruit_tca9548a.TCA9548A_Channel object at 0xb6648390>
<adafruit_tca9548a.TCA9548A_Channel object at 0xb66483d0>
<adafruit_tca9548a.TCA9548A_Channel object at 0xb6648410>
-------------------------
#
many thanks for help or tips

Mainzelman
 
Posts: 4
Joined: Sun May 02, 2021 11:48 am

Re: TCA9548a + SHT31D connect

by mikeysklar on Mon May 03, 2021 4:48 pm

This is not an answer to your question, but if you only hve two SHT-31D devices you can set the address on them using either 0x44 and 0x45. This would allow you to bypass the TCA9548A.

ADR - This is the I2C address selection pin. This pin has a 10K pull down resistor to make the default I2C address 0x44. You can tie this pin to Vin to make the address 0x45


https://learn.adafruit.com/adafruit-sht ... ut/pinouts

mikeysklar
 
Posts: 4526
Joined: Mon Aug 01, 2016 8:10 pm

Re: TCA9548a + SHT31D connect

by Mainzelman on Tue May 04, 2021 2:12 am

Thank you for the hint - but i would like to use more then 2 sensors. I only use 2 Sensors in the example.

Mainzelman
 
Posts: 4
Joined: Sun May 02, 2021 11:48 am

Re: TCA9548a + SHT31D connect

by mikeysklar on Tue May 04, 2021 11:41 am

Your code example looks fine that is failing out on the i2c try_lock. I'm wondering if a small addition of multiple tries would make a difference?

Code: Select all | TOGGLE FULL SIZE
>>> while not <chrome_find class="find_in_page">i2c.try</chrome_find>_lock():
...     pass
...
>>>


https://learn.adafruit.com/circuitpytho ... -2837704-1

Can you also post your wiring. Maybe there is something there out of place?

mikeysklar
 
Posts: 4526
Joined: Mon Aug 01, 2016 8:10 pm

Re: TCA9548a + SHT31D connect

by Mainzelman on Tue May 04, 2021 12:33 pm

many thanks for the answer. Please find attached one Picture with Cable settings.
To me it looks like SHT31 lib is not communicating with TCA9548a lib.
Please note - i use Kernel drivers:
/boot/config.txt
# ap - Kernel driver
dtoverlay=i2c-mux,pca9548
#
when i test with i2cdetect -y <N> everyone has address UU.
#
pi@raspberrypi:~ $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: UU -- -- -- -- -- -- --
pi@raspberrypi:~ $ i2cdetect -y 11
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: UU -- -- -- -- -- -- --
#
Is that correct ?
Attachments
sCable_TCA9548a.jpg
sCable_TCA9548a.jpg (629.64 KiB) Viewed 69 times

Mainzelman
 
Posts: 4
Joined: Sun May 02, 2021 11:48 am

Re: TCA9548a + SHT31D connect

by mikeysklar on Thu May 06, 2021 11:39 am

I think the UU is a function of I2S being enabled (the sound interface - do not confuse with I2C). That should go away if you disable i2s (/boot/config.txt).

Is the kernel driver required pca9865? That does not seem necessary.

I've seen one forum user successfully report getting things going on their Pi with the TCA9865A + SHT31D combo.

viewtopic.php?f=24&t=172376

I think you are running identical code so I suspect the issue is more with the a driver conflict (i2s or PCA) and possibly wiring. Although your wiring looks reasonable from the parts I can see.

Code: Select all | TOGGLE FULL SIZE
import time
import adafruit_sht31d
import adafruit_tca9548a
from busio import I2C
from board import SCL,SDA

i2c=I2C(SCL,SDA)
tca = adafruit_tca9548a.TCA9548A(i2c)

sht1 = adafruit_sht31d.SHT31D(tca[0])
sht2 = adafruit_sht31d.SHT31D(tca[1])

while 1:
print("Sensor #1: Temp: {}, RH: {}".format(sht1.temperature,sht1.relative_humidity))
print("Sensor #2: Temp: {}, RH: {}".format(sht2.temperature,sht2.relative_humidity))
print("-------------------------")
time.sleep(1)

mikeysklar
 
Posts: 4526
Joined: Mon Aug 01, 2016 8:10 pm

Re: TCA9548a + SHT31D connect

by Mainzelman on Mon May 10, 2021 6:01 am

First of all, I would like to say thank you very much for your support. I reset and rebuilt my project. It works now ! (without the kernel modules)
-> to my shame i have to say - i had connected the power supply to the sensors on the wrong side of the breadboard ;-(( (beginners mistake)
Thanks again.

Mainzelman
 
Posts: 4
Joined: Sun May 02, 2021 11:48 am

Re: TCA9548a + SHT31D connect

by mikeysklar on Mon May 10, 2021 4:14 pm

Cool. Glad that worked out. Thank you for getting back to us with your findings.

mikeysklar
 
Posts: 4526
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.