I'm trying to do a data acquisition test of a single MLX90395 sensor with my Arduino MKR WIFI 1010 through the TCA9548A I2C address multiplexer and things are not going well. (To clarify, I obviously want to connect more sensors later, that's why I'm using the TCA9548A address multiplexer, but at the moment I'm only testing with one sensor...)
As for the pre-checks I've done before getting to my problem...
On the one hand, the TCA9548A multiplexer is being well recognized by the arduino, since when doing an i2c scanner it finds a device at address 0x70 which is that of the device in question (addresses 0x60 and 0x6B are from the Arduino MKR WIFI modules 1010, so ignore them), the result is:
Scanning I2C 7-bit address range 0x08 to 0x77.
I2C device found at address 0x60
I2C device found at address 0x6B
I2C device found at address 0x70
Scan complete. Devices found: 3
On the other hand, the TCA9548A is correctly recognizing that among its 8 possible I2C channels (SD0 SC0, ... , SD7 SC7), my MLX90395 sensor (whose address is 0x0C) is connected to channel 0, the result is:
TCAScanner ready!
TCA Port #0
Found I2C 0x0
Found I2C 0xC
Found I2C 0x60
Found I2C 0x6B
TCA Port #1
Found I2C 0x60
Found I2C 0x6B
TCA Port #2
Found I2C 0x60
Found I2C 0x6B
TCA Port #3
Found I2C 0x60
Found I2C 0x6B
TCA Port #4
Found I2C 0x60
Found I2C 0x6B
TCA Port #5
Found I2C 0x60
Found I2C 0x6B
TCA Port #6
Found I2C 0x60
Found I2C 0x6B
Finally, regarding the sensor, I have already acquired its signal through the I2C protocol directly to my arduino, without the intermediate step of going through the multiplexer, and it works correctly.
Once the previous checks are done, I am trying to execute the following test code to see if I can acquire the output of the sensor passing through the multiplexer. In the program I use the Adafruit_MLX90395 library.
#include "Adafruit_MLX90395.h"
#include "Wire.h"
Adafruit_MLX90395 sensor = Adafruit_MLX90395(); // instance of the Adafruit_MLX90395 class
#define TCAADDR 0x70
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup(void){
Serial.begin(9600);
/* Wait for serial on USB platforms. */
while (!Serial) {
delay(10);
}
Serial.println("Selecting TCA port...");
tcaselect(0);
Serial.println("TCA port selected!");
if (! sensor.begin_I2C()) { // hardware I2C mode, can pass in address & alt Wire
Serial.println("No sensor found ... check your wiring?");
while (1) { delay(10); }
}
sensor.setOSR(MLX90395_OSR_8);
sensor.setResolution(MLX90395_RES_17);
}
float Bx = 0;
float By = 0;
float Bz = 0;
void loop(void) {
tcaselect(0);
/* Get a new sensor event, normalized to uTesla */
sensors_event_t event;
sensor.getEvent(&event);
Bx = event.magnetic.x;
By = event.magnetic.y;
Bz = event.magnetic.z;
Serial.print(Bx);
Serial.print("\t"); Serial.print(By);
Serial.print("\t"); Serial.print(Bz);
Serial.print("\t"); Serial.println(sqrt(pow(Bx,2)+pow(By,2 )+pow(Bz,2)));
}
The problem is that when I run it, I only get:
Selecting TCA port...
That is, it gets stuck at the point of tcaselect(0) and I don't understand why. It's like the multiplexer is preventing me from establishing a good I2C connection between my sensor and the Arduino.
The assembly of my project is this by the way:
