3 MPU6050s, SN74HC138N Multiplexer & Arduino Uno

Hi all

I needed to get 3 MPU6050, to communicate to one Arduino UNO. I am using a multiplexer (SN74HC138N) in order to achieve this.

I have written the code and set up the circuit. I have attached the code and an image of my circuit diagram.

I have coded for the multiplexer to read each MPU separately, by forcing the the MPU6050 AD0 line low(0x68) while the other MPU6050 AD0 lines are high (0x69). To my understanding, this should enable me to read each MPU reading separately on the monitor. However, my readings, which are displayed on the monitor, read all the MPU6050 signals as if they are all one device.

Therefore, when I rotate or move one MPU6050, the readings of the all the MPUs change.

I would greatly appreciate your assistance.

Code for 3 MPU6050.txt (7.94 KB)

Wow. This is some very complex stuff. What are you trying to achieve? I had a quick look at your code. But did I notice that you give all 3 devices the same address? 0x69?

Can you tell us more about the project?

rmvansomeren:
Wow. This is some very complex stuff. What are you trying to achieve? I had a quick look at your code. But did I notice that you give all 3 devices the same address? 0x69?

Can you tell us more about the project?

My project is to design a sensory glove that can track the orientation and speed of a human hand. I'm trying to extract all the information from the MPUs at once so that I can fuse the information together. Yes, they are all addressed to 0x69. I use the multiplexer to change the address, one at a time, in order to extract information from each MPU.

Do you have the chance to use the SPI interface those sensors? In that case you can get rid of the MUX and just select the sensor you want to have at a specific time. Plus the fact that the SPI interface can run at 1MHz..

The two 4k7 resistors should be pullups resistors and be connected from SDA and SCL to Vcc.

forcing the MPU6050 AD0 line low(0x68) while the other MPU6050 AD0 lines are high (0x69).

Rather than a multiplexer, most people use an Arduino output pin connected to each AD0 line. You need 10K resistors in series with the I/O lines. As already pointed out, the 4.7K resistors are used incorrectly, and should be pullups to 3.3V (the sensor is a 3.3V device).

That is a 3.3V sensor with a 5V Arduino board. You can not connect them to each other.

Was the SN74HC138N meant as level shifter ? Please explain.
Is it just three MPU-6050 sensors ? Then using three pins for addresses to create three pins for the AD0 has no advantage.

It is know to work to keep all the sensors default at 0x69 and select them one at a time by setting the I2C address at 0x68.
I doubt if your code is correct.
The library should work with the sensor at 0x68, for all sensors.
You can make a function selectMPU() to select 0, 1, or 2.
The Wire.begin() should be used once (which you do), but you have to initialize all three sensors.

When you put the objects of the sensors in an array, then you can do this:

Wire.begin().
for( i=0; i<3; i++)
{
  selectMPU(i);
  initializeMPU(accelgyro[i]);  // initialize the one at 0x68, for all three sensors
}

I'm not sure if the library is able to use multiple sensors. Some libraries store data outside the object.

This can only work with a 3.3V Arduino board !

This can only work with a 3.3V Arduino board !

It works fine with a 5V board, as long as the I2C lines are pulled up to 3.3V. The I2C lines are never driven high by the Arduino during normal I2C communications.

But 10K resistors are needed in series with the I/O lines used to drive AD0 HIGH.