I am very new to Arduino and need a bit of help as I am out of my depth.
Using an UNO, I am trying to read 16 identical Adafruit AHT20 sensors using two SparkFun Qwiic Mux Breakouts (TCA9548A) and get temp and humidity readings from each. I have added the required solder to one of the boards so that the addresses of the Mux boards should be 0x70 and 0x71
I am able to get 8 sensors working well off one Mux board buy using library examples but when I try and add the second board, the data behaves erratically, eg jumping around a bit and dropping down to 0 when the humidity gets high.
The mux boards are in a bus from the UNO, with a sensor attached to each available port.
The code I am trying to use is below. Apologies for untidiness.
#include <Wire.h>
#include <SparkFun_I2C_Mux_Arduino_Library.h>
QWIICMUX myMux;
#define NUMBER_OF_SENSORS_BOARD_1 8
#define NUMBER_OF_SENSORS_BOARD_2 8
#include <Adafruit_AHTX0.h>
Adafruit_AHTX0 aht;
unsigned long myTime;
void setup() {
Serial.begin(115200);
Serial.println("Multiple Muxes with Many Sensors");
Wire.begin();
//Initialise mux boards
if (myMux.begin(0x70) == false)
{
Serial.println("Mux 0x70 not detected. Freezing...");
while (1)
;
}
Serial.println("Mux 0x70 detected");
bool initSuccess = true;
for (byte x = 0; x < NUMBER_OF_SENSORS_BOARD_1; x++)
{
myMux.setPort(x);
if (! aht.begin()) {
Serial.print("Sensor ");
Serial.print(x);
Serial.println(" on board 1 did not begin! Check wiring");
initSuccess = false;
}
else
{
//Configure each sensor
Serial.print("Sensor ");
Serial.print(x);
Serial.println(" on 0x70 found!");
}
}
if (initSuccess == false)
{
Serial.print("Freezing...");
while (1)
;
}
Serial.println("Mux Shield 0x70 online");
//Initialise mux boards
if (myMux.begin(0x71) == false)
{
Serial.println("Mux 0x71 not detected. Freezing...");
while (1)
;
}
Serial.println("Mux 0x71 detected");
for (byte x = 0; x < NUMBER_OF_SENSORS_BOARD_2; x++)
{
myMux.setPort(x);
if (! aht.begin()) {
Serial.print("Sensor ");
Serial.print(x);
Serial.println(" on board 2 did not begin! Check wiring");
initSuccess = false;
}
else
{
//Configure each sensor
Serial.print("Sensor ");
Serial.print(x);
Serial.println(" on 0x71 found!");
}
}
if (initSuccess == false)
{
Serial.print("Freezing...");
while (1)
;
}
Serial.println("Mux Shield 0x71 online");
}
void loop() {
myTime = millis();
Serial.print(myTime);
myMux.begin(0x70);
for (byte x = 0; x < NUMBER_OF_SENSORS_BOARD_1; x++){
myMux.setPort(x);
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);
Serial.print(",");
Serial.print(temp.temperature);
Serial.print(",");
Serial.print(humidity.relative_humidity);
delay(50);
}
myMux.begin(0x71);
for (byte x = 0; x < NUMBER_OF_SENSORS_BOARD_2; x++){
myMux.setPort(x);
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);
Serial.print(",");
Serial.print(temp.temperature);
Serial.print(",");
Serial.print(humidity.relative_humidity);
delay(50);
}
Serial.println();
delay(480);
}
any help would be appreciated.
Thanks