Multiplexing MPU9150s (i2c)

I'm trying to connect 3 MPU9150 sensors to Arduino using I2C, but can't get it working. A single MPU9150 without Multiplexer works well. The multiplexer I use is CD4067BE. All resistors are 2.2k.

scheme.png
A larger image is attached.

Since I can imagine that I made some mistake (I'm not good at electronics), I chose to ask a question here. What did I do wrong? Wrong Multiplexer maybe? Wrong wiring? It may be a programming mistake, it's my first attempt to write anything for arduino, but there isn't much to do wrong. I don't even try to read from 2nd and 3rd sensors. An attempt to test connection to the first one results in "MPU6050 connection failed".

#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"

MPU6050 accelgyro;
int EN = 12;
int MA = 8;
int MB = 9;
int MC = 10;
int MD = 11;
int mux_id = 0;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t mx, my, mz;


void mux(int n) {
   Serial.print("MUX: "); Serial.print(n); Serial.println(".");
  digitalWrite(EN, LOW);
  if(n%2==1) {
    digitalWrite(MA, HIGH);
    Serial.print(1);
  } else {
    digitalWrite(MA, LOW);
    Serial.print(0);
  }
  if(n%4>1) { 
    digitalWrite(MB, HIGH);
    Serial.print(1);
  } else {
    digitalWrite(MB, LOW);
    Serial.print(0);
  }
  if(n%8>3) {
    digitalWrite(MC, HIGH);
    Serial.print(1);
  } else {
    digitalWrite(MC, LOW);
    Serial.print(0);
  }
  if(n>7) {
    digitalWrite(MD, HIGH);
    Serial.print(1);
  } else {
    digitalWrite(MD, LOW);
    Serial.print(0);
  }
  Serial.println("");
}
void setup() {
  
    pinMode(EN, OUTPUT);
    pinMode(MA, OUTPUT);
    pinMode(MB, OUTPUT);
    pinMode(MC, OUTPUT);
    pinMode(MD, OUTPUT);
    mux(0);
    
    Wire.begin();

    Serial.begin(38400);

    Serial.println("Initializing I2C devices...");
    accelgyro.initialize();

    // verify connection
    Serial.println("Testing device connections...");
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
    delay(2000);
}

void loop() {
    // read raw accel/gyro measurements from device
    accelgyro.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);

    // display accel/gyro x/y/z values
    Serial.print("(");
    Serial.print(ax); Serial.print(",");
    Serial.print(ay); Serial.print(",");
    Serial.print(az); Serial.print(",");
    Serial.print(gx); Serial.print(",");
    Serial.print(gy); Serial.print(",");
    Serial.print(gz); Serial.print(",");
    Serial.print(mx); Serial.print(",");
    Serial.print(my); Serial.print(",");
    Serial.print(mz); 
    Serial.println("");

 
    //mux_id = (mux_id + 1)%3;
    //mux(mux_id);
}

Resolved by Multiplexing AD0 instead of SCL.

Good that you have solved it but that circuit does not have the SCL connected to any clock source so it would not work.

Grumpy_Mike:
Good that you have solved it but that circuit does not have the SCL connected to any clock source so it would not work.

OP,

Could you post schematic of your final solution? I am trying to do something nearly identical, but new to multiplexing I2C. I also noticed the same thing as Grumpy_Mike -- SCL doesn't appear to be connected properly? (You are connecting VCC to SCL?)

In my case, I am using MPU6050, but setup should be nearly identical (in fact, I think it even has the same I2C address at the 9150 -- which is part of the reason I have to multiplex instead of just using a combination of sensors):