Hello,
I am trying to connect two mpu6050 (will eventually be using 5 sensors total which is why I was choosing to use multiplexer) sensors using the CD74HC4067 breakout board. I have tried connecting the sensors as well as the multiplexer to my Arduino Due and Arduino Uno using the schematic in this link:
I am trying to simultaneously read raw data from both MPU6050 which are connected to channels 1 and 2. However, when I try to read values off of channels c1,c2 it results in all zeros. I have double and triple checked my connections to assure that my sensors and mux are connected properly. I believe the problem has to be in my code. If you have any suggestions or solutions please let me know. Thank you in advance!
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"
// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050.h"
MPU6050 accel_i2c_68(MPU6050_ADDRESS_AD0_LOW);
int16_t ax, ay, az, gx, gy, gz, ax1, ay1, az1, gx1, gy1, gz1;
//ASSIGN DIGITAL PINS (MUX)
int EN = 41; //These are the pins I used instead of those in the schematic
int S0 = 43;
int S1 = 45;
int S2 = 47;
int S3 = 49;
void out1()
{
digitalWrite(EN, LOW);
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
}
void out2()
{
digitalWrite(EN, LOW);
digitalWrite(S0, LOW);
digitalWrite(S1, HIGH);
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
}
void setup()
{
out1();
out2();
out1();
pinMode(EN,OUTPUT);
pinMode(S0,OUTPUT);
pinMode(S1,OUTPUT);
pinMode(S2,OUTPUT);
pinMode(S3,OUTPUT);
Wire.begin();
Serial.begin(57600);
}
void loop()
{
int i;
int j;
int x;
for(i == 0; i < 2; i++)
{
out1();
j = 0;
accel_i2c_68.getAcceleration(&ax, &ay, &az);
accel_i2c_68.getRotation(&gx, &gy, &gz);
Serial.print(ax);
Serial.print("\t");
Serial.print(ay);
Serial.print("\t");
Serial.print(az);
Serial.print("\t");
Serial.print(gx);
Serial.print("\t");
Serial.print(gy);
Serial.print("\t");
Serial.print(gz);
Serial.print("\t");
Serial.print("\n");
delay(50);
for(j == 0; j < 2; j++)
out2();
i = 0;
accel_i2c_68.getAcceleration(&ax1, &ay1, &az1);
accel_i2c_68.getRotation(&gx1, &gy1, &gz1);
Serial.print(ax1);
Serial.print("\t");
Serial.print(ay1);
Serial.print("\t");
Serial.print(az1);
Serial.print("\t");
Serial.print(gx1);
Serial.print("\t");
Serial.print(gy1);
Serial.print("\t");
Serial.print(gz1);
Serial.print("\t");
Serial.print("\n");
Serial.print("\n");
delay(200);
}
}