I’m attempting to use 12 SHTC3 sensors in one project. I’m doing an iterative process and am able to use one SHTC3 sensor connected directly to the Red Board. When I try to access the SHTC sensor through a MUX board based on a combination of the example SHTC3 code and MUX code (below), I get the following output:
Qwiic Mux Shield Read Example
Enabled: 0
Beginning sensor. Result = Unknown return code
Disabled: 0
Mux Shield online
Enabled: 0
0 RH = 14.12%, T = -4.53 deg F
Disabled: 0
Enabled: 0
0 RH = 14.12%, T = -4.53 deg F
Disabled: 0
I have the Enabled and Disabled lines just to verify that I got through the enableMUXPort and disableMUXPort functions without error.
Here is my current setup:
Boards:
Red Board - https://www.sparkfun.com/products/15123
MUX - https://www.sparkfun.com/products/16784
SHTC3 - https://www.sparkfun.com/products/16467
Code:
#include <Wire.h>
#include "SparkFun_SHTC3.h" // Click here to get the library: http://librarymanager/All#SparkFun_SHTC3
SHTC3 mySHTC3; // Declare an instance of the SHTC3 class
#define NUMBER_OF_SENSORS 1
#define MUX_ADDR 0x70 //7-bit unshifted default I2C Address
void setup()
{
Serial.begin(115200);
while(Serial == false){}; // Wait for the serial connection to start up
Serial.println("Qwiic Mux Shield Read Example");
Wire.begin();
//Initialize all the sensors
for (byte x = 0 ; x < NUMBER_OF_SENSORS ; x++)
{
enableMuxPort(x); //Tell mux to connect to port X
delay(250);
//mySHTC3.begin();
Serial.print("Beginning sensor. Result = "); // Most SHTC3 functions return a variable of the type "SHTC3_Status_TypeDef" to indicate the status of their execution
errorDecoder(mySHTC3.begin());
Serial.println("");
disableMuxPort(x);
}
Serial.println("Mux Shield online");
}
void loop()
{
for (byte x = 0 ; x < NUMBER_OF_SENSORS ; x++)
{
enableMuxPort(x); //Tell mux to connect to this port, and this port only
SHTC3_Status_TypeDef result = mySHTC3.update(); // Call "update()" to command a measurement, wait for measurement to complete, and update the RH and T members of the object
printInfo(x); // This function is used to print a nice little line of info to the serial port
disableMuxPort(x); //Tell mux to disconnect from this port
delay(250); //Wait for next reading
}
}
///////////////////////
// Utility Functions //
///////////////////////
void printInfo(int num)
{
if(mySHTC3.lastStatus == SHTC3_Status_Nominal) // You can also assess the status of the last command by checking the ".lastStatus" member of the object
{
Serial.print(num);
Serial.print(" RH = ");
Serial.print(mySHTC3.toPercent()); // "toPercent" returns the percent humidity as a floating point number
Serial.print("%, T = ");
Serial.print(mySHTC3.toDegF()); // "toDegF" and "toDegC" return the temperature as a flaoting point number in deg F and deg C respectively
Serial.println(" deg F");
}
else
{
Serial.print("Update failed, error: ");
errorDecoder(mySHTC3.lastStatus);
Serial.println();
}
}
void errorDecoder(SHTC3_Status_TypeDef message) // The errorDecoder function prints "SHTC3_Status_TypeDef" resultsin a human-friendly way
{
switch(message)
{
case SHTC3_Status_Nominal : Serial.print("Nominal"); break;
case SHTC3_Status_Error : Serial.print("Error"); break;
case SHTC3_Status_CRC_Fail : Serial.print("CRC Fail"); break;
default : Serial.print("Unknown return code"); break;
}
}
//Enables a specific port number
void enableMuxPort(byte portNumber)
{
if (portNumber > 7) portNumber = 7;
Wire.beginTransmission(MUX_ADDR);
//Read the current mux settings
Wire.requestFrom(MUX_ADDR, 1);
if (!Wire.available()) return; //Error
byte settings = Wire.read();
//Set the wanted bit to enable the port
settings |= (1 << portNumber);
Wire.write(settings);
Wire.endTransmission();
Serial.print("Enabled: ");
Serial.println(portNumber);
}
//Disables a specific port number
void disableMuxPort(byte portNumber)
{
if (portNumber > 7) portNumber = 7;
Wire.beginTransmission(MUX_ADDR);
//Read the current mux settings
Wire.requestFrom(MUX_ADDR, 1);
if (!Wire.available()) return; //Error
byte settings = Wire.read();
//Clear the wanted bit to disable the port
settings &= ~(1 << portNumber);
Wire.write(settings);
Wire.endTransmission();
Serial.print("Disabled: ");
Serial.println(portNumber);
}
Is there something unique about the SHTC3 implementation that is different from the MMA8452Q (from the MUX example code) that requires a significantly different method of getting data? Any help would be appreciated.