Go Down

Topic: Multiple MPU6050 (Read 13574 times) previous topic - next topic

tanminggui


Yes, but I don't see the multiplexer input pin connected high.

You have to select the multiplexer address first before you address the MPU6050 that is selected.



Sorry but I do not quite understand with this statement.

When you said multiplexer input pin connected high, do you mean the common input pin of multiplexer connected to digital port of Arduino Uno as shown in the figure below?

So during coding I need to set the digital port that is connected to common input pin of multiplexer as high only like this?

Code: [Select]

#include "Wire.h"



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

MPU6050 accelgryo;
int16_t  ax, ay, az, gx, gy, gz, ax1, ay1, az1, gx1, gy1, gz1,ax2, ay2, az2, gx2, gy2, gz2, ax3, ay3, az3, gx3, gy3, gz3;




int S0 = 3;
int S1 = 2;
int S2 = 1;
int input = 8;

unsigned long time;



//MANUALLY CONTROL THE LINE OF MULTIPLEXER TO SELECT THE PIN CONNECTED TO AD0
void out1()
{
  digitalWrite(S0, HIGH);
  digitalWrite(S1, LOW);
  digitalWrite(S2, LOW);
   
}

void out2()
{
  digitalWrite(S0, LOW);
  digitalWrite(S1, HIGH);
  digitalWrite(S2, LOW);
   
}

void out3()
{
  digitalWrite(S0, HIGH);
  digitalWrite(S1, HIGH);
  digitalWrite(S2, LOW);
   
}

void out4()
{
  digitalWrite(S0, LOW);
  digitalWrite(S1, LOW);
  digitalWrite(S2, HIGH);
   
}



void setup()
{

 
  #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif

  Serial.begin(36400);
  Serial.println("CLEARDATA");
  Serial.println("LABEL,Time,time,ax1,ay1,az1,gx1,gy1,gz1,ax2,ay2,az2,gx2,gy2,gz2,ax3,ay3,az3,gx3,gy3,gz3,ax4,ay4,az4,gx4,gy4,gz4");
 
  pinMode (input, OUTPUT);
 
  digitalWrite(input,HIGH);

 
}



void loop()
{
time=millis();
    out1();
     
   
    accelgryo.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
   
    out2();
    accelgryo.getMotion6(&ax1, &ay1, &az1, &gx1, &gy1, &gz1);
   
    out3();
    accelgryo.getMotion6(&ax2, &ay2, &az2, &gx2, &gy2, &gz2);
   
     out4();
    accelgryo.getMotion6(&ax3, &ay3, &az3, &gx3, &gy3, &gz3);
   
   
    Serial.print("DATA,TIME,");
    Serial.print(time);
    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(ax1);
    Serial.print(",");
    Serial.print(ay1);
    Serial.print(",");
    Serial.print(az1);
    Serial.print(",");
    Serial.print(gx1);
    Serial.print(",");
    Serial.print(gy1);
    Serial.print(",");
    Serial.print(gz1);
    Serial.print(",");
    Serial.print(ax2);
    Serial.print(",");
    Serial.print(ay2);
    Serial.print(",");
    Serial.print(az2);
    Serial.print(",");
    Serial.print(gx2);
    Serial.print(",");
    Serial.print(gy2);
    Serial.print(",");
    Serial.print(gz2);
    Serial.print(",");
    Serial.print(ax3);
    Serial.print(",");
    Serial.print(ay3);
    Serial.print(",");
    Serial.print(az3);
    Serial.print(",");
    Serial.print(gx3);
    Serial.print(",");
    Serial.print(gy3);
    Serial.print(",");
    Serial.println(gz3);
   
   
     delay(10);
 
}


Isnt all the MPU6050 will set to 0x69 with this connection when the multiplexer is multiplexing?  Or do I miss anything with my code?




steinie44

Just connect it to +5v so its high all the time. That way when you address the multiplexer, that high is passed to the MPU6050 that you want to select.
Just think of it as a 4 way switch. The high signal is passed to the switch that you address.
Not to confuse you, but you can use a Low, if you want to use 0x68 all the time instead of 0x69.

Each time you want to read a MPU6050, you have to address it via the output pins to the multiplexer first.

Like a paper route: go to address and deliver, go to next address and deliver, ....................
Payday: go to address and collect, go to next address and collect, ..................

tanminggui


Just connect it to +5v so its high all the time. That way when you address the multiplexer, that high is passed to the MPU6050 that you want to select.
Just think of it as a 4 way switch. The high signal is passed to the switch that you address.
Not to confuse you, but you can use a Low, if you want to use 0x68 all the time instead of 0x69.

Each time you want to read a MPU6050, you have to address it via the output pins to the multiplexer first.

Like a paper route: go to address and deliver, go to next address and deliver, ....................
Payday: go to address and collect, go to next address and collect, ..................


Hi,

So far what I have done and understand from you:
Use the 5V to set the 4 MPU6050 to HIGH one at the time by using multiplexer digital control. When the selected MPU6050 is address high 0x69, the arduino board will only read the selected IMU. So this process will continue to loop until I stop.

I hope the attached figure is finally correct.

For multiplexer, now I connected
-The common input to 5V
-Supply voltage Vcc to 3.3V
-Ground to ground
-S0,S1,S2 (select input) to digital port 1,2,3
-Y0,Y1,Y2,Y3 (Independent output) to AD0 pin of each MPU6050 respectively

-Supply voltage unconnected
-Enable input unconnected

For MPU6050
-AD0 pin to multiplexer independent output (Y0,Y1,Y2,Y3)
-Vcc to 3.3V
-GND to ground
-SCL connected together with other MPU6050 on breadboard and connected to arduino A5
-SDS connected together with other MPU6050 on breadboard and connected to arduino A4
-Int to digital port (4,5,6,7 for each MPU6050 respectively)
-Vio to 3.3V

Code: [Select]

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

MPU6050 accelgryo(MPU6050_ADDRESS_AD0_HIGH) ;
int16_t  ax, ay, az, gx, gy, gz, ax1, ay1, az1, gx1, gy1, gz1,ax2, ay2, az2, gx2, gy2, gz2, ax3, ay3, az3, gx3, gy3, gz3;
//ASSIGN DIGITAL PINS (MUX)

int S0 = 3;
int S1 = 2;
int S2 = 1;

unsigned long time;

//MANUALLY CONTROL THE LINE OF MULTIPLEXER TO SELECT THE PIN CONNECTED TO AD0
void out1()
{
  digitalWrite(S0, HIGH);
  digitalWrite(S1, LOW);
  digitalWrite(S2, LOW);
   
}

void out2()
{
  digitalWrite(S0, LOW);
  digitalWrite(S1, HIGH);
  digitalWrite(S2, LOW);
   
}

void out3()
{
  digitalWrite(S0, HIGH);
  digitalWrite(S1, HIGH);
  digitalWrite(S2, LOW);
   
}

void out4()
{
  digitalWrite(S0, LOW);
  digitalWrite(S1, LOW);
  digitalWrite(S2, HIGH);
   
}
void setup()
{

 
  #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif

  Serial.begin(36400);
  Serial.println("CLEARDATA");
  Serial.println("LABEL,Time,time,ax1,ay1,az1,gx1,gy1,gz1,ax2,ay2,az2,gx2,gy2,gz2,ax3,ay3,az3,gx3,gy3,gz3,ax4,ay4,az4,gx4,gy4,gz4");
   
}



void loop()
{
time=millis();
    out1();
     
   
    accelgryo.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
   
    out2();
    accelgryo.getMotion6(&ax1, &ay1, &az1, &gx1, &gy1, &gz1);
   
    out3();
    accelgryo.getMotion6(&ax2, &ay2, &az2, &gx2, &gy2, &gz2);
   
     out4();
    accelgryo.getMotion6(&ax3, &ay3, &az3, &gx3, &gy3, &gz3);
   
   
    Serial.print("DATA,TIME,");
    Serial.print(time);
    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(ax1);
    Serial.print(",");
    Serial.print(ay1);
    Serial.print(",");
    Serial.print(az1);
    Serial.print(",");
    Serial.print(gx1);
    Serial.print(",");
    Serial.print(gy1);
    Serial.print(",");
    Serial.print(gz1);
    Serial.print(",");
    Serial.print(ax2);
    Serial.print(",");
    Serial.print(ay2);
    Serial.print(",");
    Serial.print(az2);
    Serial.print(",");
    Serial.print(gx2);
    Serial.print(",");
    Serial.print(gy2);
    Serial.print(",");
    Serial.print(gz2);
    Serial.print(",");
    Serial.print(ax3);
    Serial.print(",");
    Serial.print(ay3);
    Serial.print(",");
    Serial.print(az3);
    Serial.print(",");
    Serial.print(gx3);
    Serial.print(",");
    Serial.print(gy3);
    Serial.print(",");
    Serial.println(gz3);
   
   
     delay(10);
 
}


I hope what I have done so far is correct and I will like to hear an approval from you.  :)

Thank you so much for your time.



steinie44

#18
Aug 12, 2014, 07:41 pm Last Edit: Aug 12, 2014, 07:49 pm by steinie44 Reason: 1
Connect pin 3 to 3.3V not 5v  Sorry.

The use of pin 1.  I would move pins 1 through 7 up one pin to 2 through 8.
Pins 0 and 1  are used by USB.

Also why are the interrupt lines connected to 4 through 7?

tanminggui


Connect pin 3 to 3.3V not 5v  Sorry.

The use of pin 1.  I would move pins 1 through 7 up one pin to 2 through 8.
Pins 0 and 1  are used by USB.

Also why are the interrupt lines connected to 4 through 7?



The default setting for interrupt line is to connected to digital pin 2, but since I have 4, so I simply connected them to other digital pin. Is that alright?


tanminggui


Connect pin 3 to 3.3V not 5v  Sorry.

The use of pin 1.  I would move pins 1 through 7 up one pin to 2 through 8.
Pins 0 and 1  are used by USB.

Also why are the interrupt lines connected to 4 through 7?



Hi sir,

Now that I am doing the soldering part for sparkfun MPU6050 and I find a very big problem.
Sparkfun breakout board by default is connected to ground, and if I want to use 0x69 i need to desolder the solder bridge between AD0 and GND and solder the AD0 to Vcc. Which mean I cannot connect solely AD0 to multiplexer and my MPU6050 will always be in high (which mean 0x69).

So i am wondering after I solder the AD0 to Vcc on my sparkfun breakout board, can I connect the Vcc to the independent output (Y0,Y1,Y2,Y3) instead of AD0 pin? Then the multiplexer will control the current input to MPU6050 and I only read one mpu6050 at the time?

tanminggui

Thank you everyone for the kindness reply.

My latest way to connect 4 sparkfun MPU6050 is to mux the current input as shown in this :

https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xpf1/v/t34.0-12/10601215_10152620418379820_1607617664_n.jpg?oh=50b29d2bb18cbab3da7546da82b0ae35&oe=53F56286&__gda__=1408606551_6572cb1d9f7c1e14aa02df745cd8e15f

I know is not a good way to do it but i cant think of another way to do that. It does connect 4 IMU but something still wrong with the transmission. I will continue to work on this and finally sort everything out.

Peter_n

Switching Vcc ? anything is better than that.

tanminggui


Switching Vcc ? anything is better than that.


Well for sparkfun breakout board the AD0 pin is a pain in the ass. I cant do the switching between 69 and 68 suggested by steinie44 because the AD0 pin for sparkfun does not allow me to do so. And I really have no idea of what should I do.

Any suggestion?

michinyon

Use different devices which have a different i2c address.

ninhxuanthuan

#25
May 09, 2015, 12:46 pm Last Edit: May 09, 2015, 12:47 pm by ninhxuanthuan
selector multi = 74LS138.
74LS138 select output = LOW; all other output = HIGH;
More information 74LS138/74HC138 datasheet

afzal-raza

where i should connects the interrupts pins od other sensors?

Go Up