I have a project in which i need to get data from 5 IMU sensors (LSM9DS1) in order to track motion. I already have a working prototype: i can read all 5 of them and pass the data through to an Arduino Uno and read everything through serial. The thing is... I've run into a weird problem: it all works just fine when I have the VIN of the I2C MUX connected to the 5V of the Arduino, but when I connect it to the 3,3V pin it just doesn't work anymore. I tested the sensors alone on 3,3V and they work just fine, I tested the MUX on 3,3V and it works fine, but when i put them together there's no more data that passes through. If I run an I2C Scanner the MUX still shows up, and if I run the MUX Scanner every individual sensor shows up, so I'm really confused.
I also uploaded the schematics of how everything is connected, i hope it shows up fine. If anyone has any idea, please let me know because i realy can't figure this one out.
Thank you in advance!
It's checking if lsm1 was actually activated en it lets me know if it wasn't triggered/activated, hence the warning:
if (!lsm1.begin()) {
Serial.println(F("Oops ... unable to initialize the LSM9DS1 on MPX_Line_1. Check your wiring!"));
while (1);
I had some issues in the beginning with reading them all at the same time, so I wrote a lot of checks to make sure everything goes correctly. They can be deleted as they wouldn't serve any more purpouse once it all works well.
That's correct, I set each sensor in setupSensor() and than i call my function setupSensor() inside setup(). I thought it provided more clarity in my code, but I will change it if this isn't the proper way to do it.
Edit: Yeah I forgot to change the schematics, but my sensors are now soldered to MUX channels 1 through 5. Sorry for that!
//Libraries
#include <Wire.h>
#include <Adafruit_LSM9DS1.h>
#include <Adafruit_Sensor.h>
//Define multiplexer TCA9548A and the 5 LSM9DS1 IMUs
#define TCAADDR 0x70
const byte sensorCount = 5;
Adafruit_LSM9DS1 lsm[sensorCount];
//Bus select function for the multiplexer
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
//Setup sensor parameters (range, sensibility, ...); later called on in setup
void setupSensor() {
for (byte s=0; s<sensorCount; s++) {
tcaselect(s+1);
//Try to initialise and warn if the chip wasn't detected
if (!lsm[s].begin()) {
Serial.print(F("Oops ... unable to initialize the LSM9DS1 on MPX_Line_"));
Serial.print(s);
Serial.println(F(". Check your wiring!"));
while (1);
}
Serial.print(F("Found LSM9DS1 9DOF on MPX_Line_"));
Serial.println(s);
lsm[s].setupAccel(lsm[s].LSM9DS1_ACCELRANGE_8G, lsm[s].LSM9DS1_ACCELDATARATE_119HZ);
lsm[s].setupMag(lsm[s].LSM9DS1_MAGGAIN_16GAUSS);
lsm[s].setupGyro(lsm[s].LSM9DS1_GYROSCALE_2000DPS);
}
}
void setup() {
//Start serial communication and wait on initialisation
Serial.begin(115200);
while (!Serial) {
delay(1);
}
Serial.println(F("LSM9DS1 data read demo"));
delay(100);
//Go to setup for the sensor parameters
setupSensor();
//Setup redundancy ???
//setupSensor();
}
void printSensorVal(byte s, char *name, char *units, sensors_vec_t *v) {
Serial.print(name);
Serial.print(s);
Serial.print("\tX: ");
Serial.print(v->x);
Serial.print(units);
Serial.print("\tY: ");
Serial.print(v->y);
Serial.print(units);
Serial.print("\tZ: ");
Serial.print(v->z);
Serial.println(units);
}
void valSensor(byte s) {
//select the bus on the multiplexer and ask the sensor on that bus to read in the data (done the same for the rest of the busses/sensors)
tcaselect(s+1);
lsm[s].read();
//Get a new sensor event
sensors_event_t a, m, g, temp;
lsm[s].getEvent(&a, &m, &g, &temp);
//Print the data from the sensor
printSensorVal(s, "Accel ", " m/s^2", &a.acceleration);
printSensorVal(s, "Mag ", " uT", &m.magnetic);
printSensorVal(s, "Gyro ", " rad/s", &g.gyro);
Serial.println();
}
void loop() {
for (byte s=0; s<sensorCount; s++) valSensor(s);
}