How to connect 1 MPU6050 to an Arduino uno and Arduino mega simultaneously

Is there a way of using 1 single MPU6050 for
two different Arduino uno or 1 Arduino and 1 mega
simultaneously.

I have 1 MPU6050 and wondering if i can use it
for two Arduinos at the same time . Anyone with
an idea if this is possible or how to achieve this.
thanks

I don't think you can have multiple masters for a single slave. I think it's one slave , one master

I2C MULTIMASTERS

The I2C can have two Masters, but then you must be aware that collisions can happen, or that the bus is busy, and the MPU-6050 might get confused. To stay out of trouble, use one Master, the Uno or the Mega. The other Arduino board will be the Slave.

The Master can send data to a Slave or request data from a Slave or read data from the MPU-6050.
That means the Master can read data from the MPU-6050 and after that send that data to the Slave.

I wonder why do you want to do that ? Can you tell about your project ?

thanks for your response

the reason i want to do that is this am using the MPU6050 to stabilize a quadcopter and also wants to send the sensor values via xbee to my computer; i discovered that sending it through the xbee interrupts the flight, so i decided to use another arduino to send the sensor values to the xbee.

thats why am trying to use 1 mpu6050 for 2 arduinos

Again is it possible to connect MPU6050 to 1 arduino and then transfer the sensor values to the second arduino Serially. i mean the first arduino will be talking to the second arduino serially feeding it with the sensor values

Yes, that's a much better way to do it.

Thanks MorganS

I tried this method, but was receiving different values i guess this was noise, when i removed the connection of the serial from the Arduino, it still read same values meaning it was not receiving the sensor values. What could be the course of this and how can i possible Solve this problem.

thanks

nickson1277, you had one problem, and now you have two. When working on a project, test every part on its own. Can you make a small sketch for two Arduino boards that use the Serial. Show us both sketches. Be sure to connect the grounds. The serial port is often used to upload a sketch. Tell us how it is connected.

ok here is code

for the first arduino where the mpu6050 is connected

//////////////////////////////////////////////////////////// // mpu6050 ////////////////////////////////////////////////////////////

include "Wire.h"

include "I2Cdev.h"

include "MPU6050.h"

MPU6050 accelgyro; //int cal_int; unsigned long UL_timer; int16_t gyro_roll,gyro_pitch, gyro_yaw; int16_t acc_roll, acc_pitch, acc_yaw; double gyro_roll1,gyro_pitch1, gyro_yaw1; double acc_roll1, acc_pitch1, acc_yaw1; double gyro_roll_cal, gyro_pitch_cal, gyro_yaw_cal;

float acc_r; float acc_p; float acc_y; float gyr_r; float gyr_p; float gyr_y;

void setup(){ Wire.begin(); Serial.begin(9600); mag.initialize();

}

void loop(){ printGyroAcce();

}

void MPU6050Sensor(){ accelgyro.getMotion6(&acc_roll, &acc_pitch, &acc_yaw,&gyro_roll, &gyro_pitch, &gyro_yaw);

acc_r = acc_roll; acc_p = acc_pitch; acc_y = acc_yaw;

gyr_r = gyro_roll; gyr_p = acc_pitch; gyr_y = acc_yaw;

acc_roll1 = acc_roll; acc_pitch1 = acc_pitch; acc_yaw1 = acc_yaw;

gyro_roll1 = gyro_roll; gyro_pitch1 = gyro_pitch; gyro_yaw1 = gyro_yaw;

}

void printGyroAcce(){ Serial.print(acc_r); Serial.print(";"); Serial.print(acc_p); Serial.print(";"); Serial.print(acc_y); Serial.print(";"); Serial.print(gyr_r); Serial.print(";"); Serial.print(gyr_p); Serial.print(";"); Serial.print(gyr_y);

}

Code for Receiving Arduino

SoftwareSerial sensor(5, 6); //(RX,TX) RX of arduino 1 to Tx of Arduino 2 and TX of arduino 1 to Rx of // Ardiuno 2

void setup(){ Serial.begin(9600); sensor.begin(9600);

}

void loop(){ sensors();

}

void sensors(){

if (sensor.available()>0){ Serial.println(sensor.read()); }

}

Which one is the Mega ? Do you use the first Serial port of the Mega board ? That serial port is used for the serial monitor and to upload a sketch. The 9600 baud is extremely slow for that amount of data. The is no specific timing, the delay in the loop() is the time used by the functions. There is no way to tell the start of the data, since the last readable float number is tight to the first one. The TX will get full, and that will slow down the sketch. The receiving Arduino uses SoftwareSerial. I doubt if that will work, if that Arduino has other things to do. You read a byte, and print it as a number. That is not the same as the readable text with floats that the transmitting Arduino is sending. Please use code tags.

Please use the CODE TAGS toolbutton in the future “[</>]” (top leftmost icon)

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

MPU6050 accelgyro;
//int cal_int;
unsigned long UL_timer;
int16_t gyro_roll,gyro_pitch, gyro_yaw;
int16_t acc_roll, acc_pitch, acc_yaw;
double gyro_roll1,gyro_pitch1, gyro_yaw1;
double acc_roll1, acc_pitch1, acc_yaw1;
double gyro_roll_cal, gyro_pitch_cal, gyro_yaw_cal;

float acc_r;
float acc_p;
float acc_y;
float gyr_r;
float gyr_p;
float gyr_y;




void setup(){
Wire.begin();
Serial.begin(9600);
mag.initialize();

}

void loop(){
printGyroAcce();

}


void MPU6050Sensor(){
 accelgyro.getMotion6(&acc_roll, &acc_pitch, &acc_yaw,&gyro_roll, &gyro_pitch, &gyro_yaw);

 acc_r = acc_roll;
 acc_p = acc_pitch;
 acc_y = acc_yaw;

 gyr_r = gyro_roll;
 gyr_p = acc_pitch;
 gyr_y = acc_yaw;

 acc_roll1 = acc_roll;
 acc_pitch1 = acc_pitch;
 acc_yaw1   = acc_yaw; 

 gyro_roll1 = gyro_roll;
 gyro_pitch1 = gyro_pitch;
 gyro_yaw1   = gyro_yaw; 

 

}


void printGyroAcce(){
 Serial.print(acc_r);               
 Serial.print(";");
 Serial.print(acc_p);                
 Serial.print(";");
 Serial.print(acc_y);                 
 Serial.print(";");
 Serial.print(gyr_r);
 Serial.print(";");
 Serial.print(gyr_p);
 Serial.print(";");
 Serial.print(gyr_y);
 

}



Code for Receiving Arduino 

SoftwareSerial sensor(5, 6); //(RX,TX)  RX of arduino 1 to Tx of Arduino 2 and TX of arduino 1 to Rx of 
                                        // Ardiuno 2

void setup(){
Serial.begin(9600);
sensor.begin(9600);

}

void loop(){
sensors();

}


void sensors(){

if (sensor.available()>0){
Serial.println(sensor.read());
 }

}

thanks Koepel and raschemmel

raschemmel i got your point, am actually a newbie here and have noted that

Koepel The Arduino mega is the one MPU6050 is connected to. am sorry i don't quiet get this statement You read a byte, and print it as a number. That is not the same as the readable text with floats that the transmitting Arduino is sending.

because an sending float and expect to get back float. is there something am missing? thanks

The Serial.read() reads a byte. The Serial.println() prints the number of that byte I think. You print readable ascii, like this : "123.45;200.99;300.01;-80.01;-120.02;-240.95".

Before you start making a sketch, you have to know what will be connected to what and how, and in what way the data is transferred. The Arduino Mega2560 has 4 serial ports, but the first one is used to upload a sketch and for the serial monitor.

Thanks Koepel

I will check that out. You did made mention of Software serial
does that mean that the data am sending to the Arduino Uno
will overwhelm it? Do you suggest i use two Arduino Mega instead

thanks

The Arduino Mega has three spare hardware serial ports. That is always handy.
The Arduino Leonardo has one spare hardware serial port. That might be enough for you. They are at pin 0 and 1, and they are not used to upload a sketch, because that is done via the USB part of the ATmega32U4 microcontroller.
The Micro, Pro Micro and others with ATmeg32U4 have also that spare hardware serial port.

There is still an option to use I2C as I mentioned in my Reply #2. It is not easy, and many things can go wrong. The Mega requests data from the sensor, and then the Mega sends that data to the Uno via the same I2C bus. You must use a level shifter for SDA and SCL, because the Mega and Uno use 5V and the MPU-6050 uses 3.3V.

Search for : i2c level
They are 25 eurocents on AliExpress, inclusive shipping.

Thanks Koepel

I will update you guys with the development