Multiple SHT20 sensors with multiplexer TCA9548a

Hi!

I am trying to use a TCA9548a multiplex to connect one LCD i2C with 2 SHT20 humity sensors (they have the same i2c address).

I don't know what I am doing wrong, I just followed a lot of code I found here on the forum and other tutorials on google, but I am only able to see only one SHT20 measure and LCD just stop to work when I connect this to TCA9548a.

I checked the wiring, and everything seems to be fine. LCD is connected on channel 1, and sht30 is connected in channel 2 and 3 respectively. My code:

#include "Wire.h"
#include <LiquidCrystal_I2C.h>
#include "DFRobot_SHT20.h"

void tcaselect(uint8_t i) {
  if (i > 7) return;
  Wire.beginTransmission(0x70);
  Wire.write(1 << i);
  Wire.endTransmission();  
}

LiquidCrystal_I2C lcd(0x27, 16, 2);
DFRobot_SHT20 sht20External;
DFRobot_SHT20 sht20Internal;

void setup() {
  // Begin serial
  Serial.begin(115200);
  while (!Serial); // Waiting for Serial Monitor

  // Begin wire
  Wire.begin(); // Wire communication begin

  // Begin LCD
  tcaselect(1);
  lcd.begin(16, 2);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Started!");
  
  // Begin sensors
  tcaselect(2);
  delay(200);
  sht20External.initSHT20();
  sht20External.checkSHT20();
  
  tcaselect(3);
  delay(200);
  sht20Internal.initSHT20();
  sht20Internal.checkSHT20();
}

void loop() {
  tcaselect(1);
  lcd.clear();

  tcaselect(2);
  float externalHumidity = sht20External.readHumidity();
  float externalTemperature = sht20External.readTemperature();
  tcaselect(3);
  float internalHumidity = sht20Internal.readHumidity();
  float internalTemperature = sht20Internal.readTemperature();

  Serial.print("H:");
  Serial.println(externalHumidity);
  Serial.print("T:");
  Serial.println(externalTemperature);
  Serial.print("H2:");
  Serial.println(internalHumidity);
  Serial.print("T2:");
  Serial.println(internalTemperature);
  
  tcaselect(1);
  lcd.setCursor(0, 0);
  lcd.print("H:");

  lcd.setCursor(2, 0);
  lcd.print(String(internalHumidity));

  lcd.setCursor(0, 1);
  lcd.print("T:");

  lcd.setCursor(2, 1);
  lcd.print(String(internalTemperature));
  delay(1000);
}

Any ideas?

I've not used this part but the Adafruit example has this line (missing on your code)

#define TCAADDR 0x70

I don`t think so... I have this address on this line directly:

Wire.beginTransmission(0x70)

This approach has the same effect as

#define TCAADDR 0x70
Wire.beginTransmission(TCAADDR)
1 Like

Can you post a wiring diagram showing how everything is hooked up?

Do the LCD and SHT20 have pullup resistors for the I2C lines?

If you hook up the LCD alone, through the TCA9548a, will it work without the SHT20s connected?

There is no need to connect the LCD to a channel on the multiplexer, it can be connected directly to the Arduino SCL/SDA pins.

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