Hi, I am working with an Argon and sensors MLX90393 and a multiplexer I2C tca9845. In particular, I have the following function to call the mux's channels:
void tcaselect(uint8_t i)
{
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
in the setup i set the sensors' features:
void setup()
{
Serial.begin(9600);
Wire.begin();
pinMode(ligth,OUTPUT);
/*-------------SENSOR 0----------------------*/
tcaselect(0);
if (! sensor0.begin_I2C(0x0C)) { // hardware I2C mode, can pass in address & alt Wire
Serial.println ("No sensor 0 found ... check your wiring?");
}
else{
Serial.println(" S0 ok");
}
sensor0.setGain(MLX90393_GAIN_5X);
sensor0.setResolution(MLX90393_X, MLX90393_RES_17);
sensor0.setResolution(MLX90393_Y, MLX90393_RES_17);
sensor0.setResolution(MLX90393_Z, MLX90393_RES_16);
// Set oversampling
sensor0.setOversampling(MLX90393_OSR_3);
// Set digital filtering
sensor0.setFilter(MLX90393_FILTER_7);
/*---------------SENSOR 1----------------------------------*/
tcaselect(1);
delay(50);
if (! sensor1.begin_I2C(0x0C)) { // hardware I2C mode, can pass in address & alt Wire
Serial.println("No sensor 1 found ... check your wiring?");
}
else{
Serial.println(" S1 ok");
}
sensor1.setGain(MLX90393_GAIN_5X);
sensor1.setResolution(MLX90393_X, MLX90393_RES_17);
sensor1.setResolution(MLX90393_Y, MLX90393_RES_17);
sensor1.setResolution(MLX90393_Z, MLX90393_RES_16);
sensor1.setOversampling(MLX90393_OSR_3);
sensor1.setFilter(MLX90393_FILTER_7);
/*-------------SENSOR 2--------------------------*/
tcaselect(2);
delay(50);
if (! sensor2.begin_I2C(0x0C)) { // hardware I2C mode, can pass in address & alt Wire
Serial.println("No sensor 2 found ... check your wiring?");
}
else{
Serial.println(" S2 ok");
}
sensor2.setGain(MLX90393_GAIN_5X);
sensor2.setResolution(MLX90393_X, MLX90393_RES_17);
sensor2.setResolution(MLX90393_Y, MLX90393_RES_17);
sensor2.setResolution(MLX90393_Z, MLX90393_RES_16);
sensor2.setOversampling(MLX90393_OSR_3);
sensor2.setFilter(MLX90393_FILTER_7);
/*-------------SENSORE 3--------------------------*/
tcaselect(3);
delay(50);
if (! sensor3.begin_I2C(0x18)) { // hardware I2C mode, can pass in address & alt Wire
Serial.println("No sensor 3 found ... check your wiring?");
}
else{
Serial.println(" S3 ok");
}
sensor3.setGain(MLX90393_GAIN_5X);
sensor3.setResolution(MLX90393_X, MLX90393_RES_17);
sensor3.setResolution(MLX90393_Y, MLX90393_RES_17);
sensor3.setResolution(MLX90393_Z, MLX90393_RES_16);
sensor3.setOversampling(MLX90393_OSR_3);
sensor3.setFilter(MLX90393_FILTER_7);
/*-------------SENSORE 4--------------------------*/
tcaselect(4);
delay(50);
if (! sensor4.begin_I2C(0x0C)) { // hardware I2C mode, can pass in address & alt Wire
Serial.println("No sensor 4 found ... check your wiring?");
}
else{
Serial.println(" S4 ok");
}
sensor4.setGain(MLX90393_GAIN_5X);
sensor4.setResolution(MLX90393_X, MLX90393_RES_17);
sensor4.setResolution(MLX90393_Y, MLX90393_RES_17);
sensor4.setResolution(MLX90393_Z, MLX90393_RES_16);
sensor4.setOversampling(MLX90393_OSR_3);
sensor4.setFilter(MLX90393_FILTER_7);
};
In the void loop, for now, i did not write anything but obviously i am interested in reading in the loop the parameters of each of the four sensors for all 8 mux channels.
There reason why in the loop i am still not writing anything is that even with the following code in the setup, I am seeing the led flashing red 8 times as in memory leak.
Do you have any suggestions on how to improve the firmware to avoid such problem and to write it in a more efficient way?