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?