Help with multiplexing I2C and SHT85 sensors

Hi, I have been searching all over for a fix to this, and I can't seem to make anything work.

I am trying to make a program with an arduino nano connected over serial, that are supposed to gather data from 8 SHT85 sensors. All of them have the same I2C address, which is the entire reason of the TCA9548A. I am gonna link the code and right now all it does is gather the data from 1 sensor at a time and print it in a serial terminal.

Everything is working fine when only two sensors are connected. However, when I go beyond 3 or 4 sensors, the program just stops working. I have managed to find out that it still receives serial input, but don't send anything back....

I have pretty come to a stop and would love some new ideas to get over this speedbumb.

As it stands right now I have been over several approaches and landed on a switch case setup where only the I2C bus that I need data from in that specific moment is called.

Arduino: regular NANO, can't put in anymore links. modelnumber: A000005

TCA9548A: https://www.ti.com/lit/ds/symlink/tca9548a.pdf?ts=1620217306048&ref_url=https%253A%252F%252Fwww.google.com%252F

Sensor: https://dk.rs-online.com/web/p/temperatursensor-og-fugtighedssensor-ic-er/1826530/

Hope you can help.

Pastebin with the code, since I can't upload files it seems :slight_smile:

How long are all your wires to these sensors? i2c isn't really designed for great lengths. Also, what sort of pull-up resistors do you have on the bus? How are you powering all these sensors? A schematic would be most helpful. [and posting your code to pastbin is not]

Thanks for the reply. I don’t Think I Can link my code, i would love to know, but it says new members aren’t allowed to paste files into the posts.

I am using 0604 10k 1% resistors. And wires are a few cm long, it’s on PCB. I Can link the schematic and PCB layout tomorrow if it’s still needed. Is it because of capacitances created with longer wires?

How many pullup resistors are there ?
The Nano has internal pullup resistors, but those are weak, 30k or 50k or so.
I don't know if the TCA9548A has internal pullup. I can not find something about that in the datasheet.

I think you need 18 pullup resistors for all the I2C buses.

Adafruit says: "These pins do not have any pullups installed, so if you are using a chip or breakout without i2c pullups be sure to add them!".

That means that if a (sub)I2C bus is not selected, those SDA and SCL pins are floating and that sensor gets confused. With pullup resistors that (sub)I2C bus is idle and the sensor is happy.

Two pullup resistors for each (sub)I2C bus, plus two for the I2C bus from the Nano, that makes 18 resistors.

I have two pull ups for each of the sensors. One for each scl and sda. Both on 10k so nothing should be left floating. I’m gonna be linking the sheets tomorrow.

Which SHTSensor library do you use ?
Some sensor libraries are written in a hurry and don't allow multiple sensors.

I am using the arduino-sht.h

This one: arduino-sht/SHTSensor.h at master · Sensirion/arduino-sht · GitHub

That library is not bad, but there is a issue: I2C communication without clock stretching · Issue #10 · Sensirion/arduino-sht · GitHub
The fix is to remove the repeated start, while the sensor is busy. That seems appropriate. Can you find that Wire.endTransmission() and remove the 'false' parameter ?

It has even a example for multiple sensors.

If that fix does not work, can you make a very simple sketch and select just one sensor (not the first or the second that work), and try that single sensor.

It seems the problem wasn't the code at all and I have made a terrible mistake and found a shortcircuit on of the pins, this seems to have fixed the problem.

Thanks for all the replies. :smiley:

Hello i have the same problem with the SHT85 i use juste one sensor directly connected with the arduino nano board, also i have 2 pull up resistor 10 Kohms, the problem is that the code is not good i think.
#include <Wire.h>
#include "SHTSensor.h"
SHTSensor sht;
// To use a specific sensor instead of probing the bus use this command:
// SHTSensor sht(SHTSensor::SHT3X);
void setup() {
// put your setup code here, to run once:
Wire.begin();
Serial.begin(9600);
delay(1000); // let serial console settle
if (sht.init()) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed\n");
}
sht.setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM); // only supported by SHT3x
}
void loop() {
// put your main code here, to run repeatedly:
if (sht.readSample()) {
Serial.print("SHT:\n");
Serial.print(" RH: ");
Serial.print(sht.getHumidity(), 2);
Serial.print("\n");
Serial.print(" T: ");
Serial.print(sht.getTemperature(), 2);
Serial.print("\n");
} else {
Serial.print("Error in readSample()\n");
}
delay(1000);
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.