@m5stack @sysdl132 I don't get it working. I have connected the PaHUB to my M5Stack and two ENV sensors to the PaHUB.
When I run the PaHUB demo, it shows the addresses 0x5C, 0x70, 0x75 and 0x76 for channel 0 and 1, and 0x5C, 0x70, 0x75 for the remaining channels.
I my own program, I added the class TCA9548A and DHT22 (I renamed TCA9548A to PaHUB).
My setup function looks like this:
#define PaHub_I2C_ADDRESS 0x70
#define ENV_I2C_ADDRESS 0x76
PaHUB pahub;
void setup() {
ez.begin();
Wire.begin();
pahub.address(PaHub_I2C_ADDRESS);
}
I defined a struct for my sensors:
struct Sensor {
uint8_t channel;
DHT12 device;
char* name;
};
and an array of the struct which is initialized that way:
struct Sensor sensors[] = {
{0, DHT12(CELSIUS, ENV_I2C_ADDRESS), "Left"},
{1, DHT12(CELSIUS, ENV_I2C_ADDRESS), "Hotspot"},
{2, DHT12(CELSIUS, ENV_I2C_ADDRESS), "Right"},
{3, DHT12(CELSIUS, ENV_I2C_ADDRESS), "Left"},
{4, DHT12(CELSIUS, ENV_I2C_ADDRESS), "Hotspot"},
{5, DHT12(CELSIUS, ENV_I2C_ADDRESS), "Right"}
};
This is how I'm reading the sensors:
struct SensorValues readSensor(int channel) {
struct SensorValues sensorValues;
struct Sensor sensor = sensors[channel];
uint8_t returnCode = pahub.selectChannel(sensor.channel);
Serial.println(" ---------- readSensor() ----------");
Serial.print("pahub.selectChannel(");
Serial.print(sensor.channel);
Serial.print(") = ");
Serial.println(returnCode);
if (returnCode == 0) {
sensorValues.temperature = sensor.device.readTemperature();
sensorValues.humidity = sensor.device.readHumidity();
}
Serial.println(" ---------- readSensor() ----------");
return sensorValues;
}
Unfortunately I'm receiving always 0 for both the temperature and the humidity.
Could anybody please give me a hint what I'm doing wrong?
Thanks & Best regards
Thomas