Can't find MPU6050 connected to TCA9548A multiplexer

Hi,

I try to make a datalogger using 3 different MPU6050. I use the TCA9548A multiplexer to communicate in I2C with my arduino (Leonardo or MKR1010, I use both but I have the same problem with each).
When I launch a scanner dedicated to find the devices linked to the TCA multiplexer I find all of my sensors. However when I launch the basic_reading script from adafruit (modified to use the multiplexer) I can't find any of the mpu.

My problem is exactly the same as this topic :

If you have an answer I'll be very grateful .
Thank's for reading and have a nice day.

We need to see YOUR code, and YOUR wiring.

Ok so here is my wiring


And this is my code

// Basic demo for accelerometer readings from Adafruit MPU6050

#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

Adafruit_MPU6050 mpu;

//
//Connection avec le multiplexer
//

void tcaChannel(uint8_t i){

  Wire.beginTransmission(0x70);
  Serial.println("1");
  Wire.write(1<<i);
  Serial.println("2");
  Wire.endTransmission();
  Serial.println("3");
}

void setup(void) {
  Serial.begin(115200);
  while (!Serial)
    delay(10); // will pause Zero, Leonardo, etc until serial console opens

  Serial.println("Adafruit MPU6050 test!");

  // Try to initialize!
  tcaChannel(3);
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }
  Serial.println("MPU6050 Found!");

  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  Serial.print("Accelerometer range set to: ");
  switch (mpu.getAccelerometerRange()) {
  case MPU6050_RANGE_2_G:
    Serial.println("+-2G");
    break;
  case MPU6050_RANGE_4_G:
    Serial.println("+-4G");
    break;
  case MPU6050_RANGE_8_G:
    Serial.println("+-8G");
    break;
  case MPU6050_RANGE_16_G:
    Serial.println("+-16G");
    break;
  }
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  Serial.print("Gyro range set to: ");
  switch (mpu.getGyroRange()) {
  case MPU6050_RANGE_250_DEG:
    Serial.println("+- 250 deg/s");
    break;
  case MPU6050_RANGE_500_DEG:
    Serial.println("+- 500 deg/s");
    break;
  case MPU6050_RANGE_1000_DEG:
    Serial.println("+- 1000 deg/s");
    break;
  case MPU6050_RANGE_2000_DEG:
    Serial.println("+- 2000 deg/s");
    break;
  }

  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
  Serial.print("Filter bandwidth set to: ");
  switch (mpu.getFilterBandwidth()) {
  case MPU6050_BAND_260_HZ:
    Serial.println("260 Hz");
    break;
  case MPU6050_BAND_184_HZ:
    Serial.println("184 Hz");
    break;
  case MPU6050_BAND_94_HZ:
    Serial.println("94 Hz");
    break;
  case MPU6050_BAND_44_HZ:
    Serial.println("44 Hz");
    break;
  case MPU6050_BAND_21_HZ:
    Serial.println("21 Hz");
    break;
  case MPU6050_BAND_10_HZ:
    Serial.println("10 Hz");
    break;
  case MPU6050_BAND_5_HZ:
    Serial.println("5 Hz");
    break;
  }

  Serial.println("");
  delay(100);
}

void loop() {

  tcaChannel(2);
  
  /* Get new sensor events with the readings */
  sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);

  /* Print out the values */
  Serial.print("Acceleration X: ");
  Serial.print(a.acceleration.x);
  Serial.print(", Y: ");
  Serial.print(a.acceleration.y);
  Serial.print(", Z: ");
  Serial.print(a.acceleration.z);
  Serial.println(" m/s^2");

  Serial.print("Rotation X: ");
  Serial.print(g.gyro.x);
  Serial.print(", Y: ");
  Serial.print(g.gyro.y);
  Serial.print(", Z: ");
  Serial.print(g.gyro.z);
  Serial.println(" rad/s");

  Serial.print("Temperature: ");
  Serial.print(temp.temperature);
  Serial.println(" degC");

  Serial.println("");
  delay(500);
}

Thanks a lot

@ferme, your topic has been moved to a more suitable location on the forum.

Please edit your post #3, select all code and click the </>button to apply code tags; next save your post.

Can you please take some time to read How to get the best out of this forum.

Sorry but that is not a wiring diagram. It's a Fritzing impressing no helper. Please post code, not text. Use autoformat in the IDE and code tags when posting.

You should post code by using code-tags
There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

best regards Stefan

Here is a scanner-version for the I2C-multiplexer

//I2C-Scanner fuer TCA9548A
//Code fuer Arduino
//Author Retian
//Version 1.0

#include <Wire.h>

//Prototype
void scanneTCA(void);

byte tcaI2cAdd;

void setup() {
  Serial.begin(115200);
  Wire.begin();
  Serial.println(F("I2C-Scanner fuer TCA9548A"));
  Serial.println();
}

void loop() {
  bool tcaGefunden = false;
  Serial.print(F("Scanne TCA9548A-Adressen:"));
  for (byte tcaI2cAdd = 0x70; tcaI2cAdd < 0x78; tcaI2cAdd++)
  {
    Wire.beginTransmission(tcaI2cAdd);
    if (Wire.endTransmission() == 0)
    {
      tcaGefunden = true;
      Serial.print(F(" 0x"));
      Serial.print(tcaI2cAdd, HEX);
      Serial.println(F(" gefunden"));
      Serial.println(F("Scanne Kanaele:"));
      scanneTCA(tcaI2cAdd);
    }
  }
  if (!tcaGefunden) Serial.println(F("TCA9548A nicht gefunden"));
  Serial.println();
  delay(2000);
}

void scanneTCA(byte tcaAdd) { 
  bool adresseGefunden = false;
  for (byte channel = 0; channel < 8; channel++)
  {
    Wire.beginTransmission(tcaAdd);
    Wire.write(1 << channel);
    Wire.endTransmission();
    
    for (byte add = 1; add < 128; add++)
    {
      if (add != tcaAdd)
      {
        Wire.beginTransmission(add);
        if (Wire.endTransmission() == 0)
        {
          adresseGefunden = true;
          Serial.print(F("Kanal "));
          Serial.print(channel);
          Serial.print(F(": Adresse 0x"));
          Serial.print(add, HEX);
          Serial.println(F(" gefunden"));
        }
      }
    }
  }
  if (!adresseGefunden) Serial.println(F("Keine Adresse gefunden"));
}

best regards Stefan

Thanks! That's code the best way it can be!
Sorry but that multiplexer calls for experience I haven't got.

Thanks for your advices, I changed it

Hi, @ferme
Welcome to the forum.

What MPU module do you have?

Does it have some address jumpers on it so you can give each MPU a different address and run them all of the same I2C bus without a multiplexer?

Tom... :smiley: :+1: :coffee: :australia:

Hi,

I have two MPU 6050. I know I could change the adress of each multiplexer (0x68 and 0x69) but in the long term I would like to make a system with three mpu. And these MPU have only two different adresses.

Thanks for your help

Hi,
Look at this diagram and the link thats is in it.
You can have two IMU with the same address with this configuration and the other with the different address.
Or expand it to three IMU in this diode switching configuration.

Tom.... :smiley: :+1: :coffee: :australia:

Hi,

I'll look at it.
I made a diagram, as you asked. I hope it is clear.

Hi,

Do anyone knows how to do with the TCA9548A ?

Thanks for your help

Hi,
Have you looked at this Adafruit tutorial and looked at and tried their example with two I2C units collected?
They even have a scanner.

Tom... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.