Adafruit_SHT31.h: with two I2C interfaces

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Tipo1000
 
Posts: 7
Joined: Thu Aug 19, 2021 11:04 am

Adafruit_SHT31.h: with two I2C interfaces

Post by Tipo1000 »

Hi,

I have four pieces of "Adafruit Sensirion SHT31-D" sensors connected to ATSAMD21G18A custom board.
They are connected to two I2C interfaces and with I2C scanner I can see they are connected ok.

The issue is how to get information from all of them using Adafruit_SHT31.h library?
How can I switch back and forth between those two I2C interfaces in Arduino code?

The second I2C interface is configured with "TwoWire myWire(&sercom5, 16, 17);" in sketch declaration part.
With that declaration I can read the sensors in second I2C interface, but then how do I read the sensors in default I2C interface?

And vice versa: without "TwoWire myWire(&sercom5, 16, 17);" I can read only sensors in default I2C interface.

Any help would be great!
TwoWire myWire(&sercom5, 16, 17);

Adafruit_SHT31 sht31_kotelo = Adafruit_SHT31(); // on default I2C
Adafruit_SHT31 sht31_1 = Adafruit_SHT31(); // on default I2C
Adafruit_SHT31 sht31_2 = Adafruit_SHT31(); // on second I2C on SERCOM5
Adafruit_SHT31 sht31_3 = Adafruit_SHT31(); // on second I2C on SERCOM5
if (! sht31_1.begin(0x45)) {
Serial.println("Couldn't find sht31_1.");
} else {
Serial.println("sht31_1 OK.");
Thanks,
Tipo

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit_SHT31.h: with two I2C interfaces

Post by adafruit_support_bill »

You need to pass the alternate i2c bus to the constructor. Otherwise it assumes the default bus.

Code: Select all

TwoWire myWire(&sercom5, 16, 17);

Adafruit_SHT31 sht31_kotelo = Adafruit_SHT31(); // on default I2C
Adafruit_SHT31 sht31_1 = Adafruit_SHT31(); // on default I2C
Adafruit_SHT31 sht31_2 = Adafruit_SHT31(&myWire); // on second I2C on SERCOM5
Adafruit_SHT31 sht31_3 = Adafruit_SHT31(&myWire); // on second I2C on SERCOM5

User avatar
Tipo1000
 
Posts: 7
Joined: Thu Aug 19, 2021 11:04 am

Re: Adafruit_SHT31.h: with two I2C interfaces

Post by Tipo1000 »

Still can't get it to work...

To make sure SERCOM I2C is working I connected SHT31 with address 0x44 to default I2C and SHT31 with address 0x45 to SERCOM I2C. I2C scanner (code attached) output below seems to confirm both I2C’s are working.
I2C Scanner

Scanning myWire (sercom5 I2C)...
I2C device found at address 0x45 !
done

Scanning Wire (default I2C)...
I2C device found at address 0x44 !
done
Having confirmed the above I added other SHT31 sensors' so that both I2C's have 0x44 and 0x45, and then I tried to run a sketch with Adafruit_SHT31.h library (code attached).

Result: It finds only sensors in default I2C. Also, at the same time I checked with scope that there was not traffic in SERCOM I2C. Output is below:
START, delay 3s...
Checking SHT31 sensors...

sht31_0 OK.
sht31_1 OK.
Any help would be great ;)
Attachments
2xI2C Adafruit_lib.zip
(1.35 KiB) Downloaded 6 times

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Adafruit_SHT31.h: with two I2C interfaces

Post by adafruit_support_bill »

Looks like pins 16 and 17 are not available for sercom5 usage on the ATSAMD21:
https://learn.adafruit.com/using-atsamd ... 1599746-28

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”