I am trying to use the Adafruit PCA9546A with two Adafruit SHT41 Temperature/Humidity sensors. I am using a ARDUINO PRO MICRO.
The following code compiles and runs but the temperature and humidity are not displayed. The code seems to hang up when sht4_1.getEvent(&humidity1,&temp1) is called(line 48. I think the problem is that the Adafruit_SHT4x.h library does not allow for the calling for tempetature and humidity separately but I am nor really sure.
Any help getting it to work will be appreciated.
// 1/9?2024 TEST SKETCH FOR SHT41 MULTIPLEXER
#include <Wire.h> //used for i2c bus, external EEPROM,ADAFRUIT SHT31-D
#include "Adafruit_SHT4x.h" //added for I2C multipleser ADAFRUIT PART #5664
#define TCAADDR 0x70 //added for I2C multipleser ADAFRUIT PART #5664
Adafruit_SHT4x sht4_1 = Adafruit_SHT4x(); //added for I2C multipleser ADAFRUIT PART #5664 in channel 0
Adafruit_SHT4x sht4_2 = Adafruit_SHT4x(); //added for I2C multipleser ADAFRUIT PART #5664 in channel 1
void setup()
{
Serial.begin(9600);
delay(10000);
Serial.println("SHT41_multiplexer_for_POND");
Wire.begin();
Serial.println("HERE IN SETUP");
// initalize sensors
tcaselect(0);
sht4_1.begin(0x44);
//if (!sht4_1.begin(0x44))
//{
// Serial.println("Could not find Sht4_1");
//}
tcaselect(1);
sht4_2.begin(0x44);
//if (!sht4_2.begin(0x44))
//{
// Serial.println("Could not find Sht4_2");
//}
Serial.println("STARTING_2");
}
void loop()
{
sensors_event_t humidity1, temp1; //added for I2C multipleser ADAFRUIT PART #5664
sensors_event_t humidity2, temp2; //added for I2C multipleser ADAFRUIT PART #5664
tcaselect(0);
Serial.println("HERE AT SENTENCE_2");
delay(10);
sht4_1.getEvent(&humidity1, &temp1);// added for I2C multipleser ADAFRUIT PART #5664, populate temp and humidity objects with fresh data
Serial.println("HERE AT SENTENCE_2-2");
tcaselect(1);
Serial.println("HERE AT SENTENCE_2-3");
sht4_2.getEvent(&humidity2, &temp2);// added for I2C multipleser ADAFRUIT PART #5664, populate temp and humidity objects with fresh data
Serial.print("temp_f1 = ");Serial.println(temp1.temperature);
Serial.print("humidity1 = ");Serial.println(humidity1.relative_humidity);
Serial.print("temp_f2 = ");Serial.println(temp2.temperature);
Serial.print("humidity2 = ");Serial.println(humidity2.relative_humidity);
}
void tcaselect(uint8_t i)
{
Serial.println("HERE AT tcaselect");
if(i>4) return;
Wire.beginTransmission(TCAADDR);
Serial.println("HERE AT tcaselect #2");
Wire.write(1<<i);
Serial.println("HERE AT tcaselect #3");
Wire.endTransmission();
Serial.println("HERE AT tcaselect #4");
//return;
}
2 posts - 2 participants