pask98
October 21, 2022, 8:35am
1
Hello everyone,
I am trying to connect 2 MPU5060 with my esp32.
The connections of the MPU5060s are:
MPU 1
VCC > 3.3V
SDA > SDA
SCL > SCL
GND > GND
MPU 2
AD0 > 3.3V
SDA > SDA
SCL > SCL
GND > GND
Like this:
The cose is this:
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 MPU1;
Adafruit_MPU6050 MPU2;
void setup(void) {
Serial.begin(115200);
while (!Serial)
delay(10);
Serial.println("Adafruit MPU6050 test!");
if (!MPU1.begin() || !MPU2.begin(0x69)) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
MPU1.setAccelerometerRange(MPU6050_RANGE_8_G);
MPU1.setGyroRange(MPU6050_RANGE_500_DEG);
MPU1.setFilterBandwidth(MPU6050_BAND_21_HZ);
MPU2.setAccelerometerRange(MPU6050_RANGE_8_G);
MPU2.setGyroRange(MPU6050_RANGE_500_DEG);
MPU2.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.println("");
delay(100);
}
void loop() {
GetMPU1();
GetMPU2();
Serial.println("-----------");
delay(500);
}
void GetMPU1(){
sensors_event_t a, g, temp;
MPU1.getEvent(&a, &g, &temp);
Serial.print("Acceleration X: ");
Serial.print(a.acceleration.x);
Serial.print(", Y: ");
Serial.print(a.acceleration.y);
Serial.print(", Z: ");
Serial.print(a.acceleration.z);
Serial.println(" m/s^2");
Serial.print("Rotation X: ");
Serial.print(g.gyro.x);
Serial.print(", Y: ");
Serial.print(g.gyro.y);
Serial.print(", Z: ");
Serial.print(g.gyro.z);
Serial.println(" rad/s");
}
void GetMPU2(){
sensors_event_t a, g, temp;
MPU2.getEvent(&a, &g, &temp);
Serial.print("Acceleration X: ");
Serial.print(a.acceleration.x);
Serial.print(", Y: ");
Serial.print(a.acceleration.y);
Serial.print(", Z: ");
Serial.print(a.acceleration.z);
Serial.println(" m/s^2");
Serial.print("Rotation X: ");
Serial.print(g.gyro.x);
Serial.print(", Y: ");
Serial.print(g.gyro.y);
Serial.print(", Z: ");
Serial.print(g.gyro.z);
Serial.println(" rad/s");
}
The problem is that the second MPU always prints all zero:
Someone can help me?
Welcome to the forum
How does the code know which device it is addressing ?
Koepel
October 21, 2022, 8:46am
3
Start with a I2C Scanner sketch.
Every sensor on the I2C bus needs its own I2C address.
When two devices have the same I2C address, then it does not work.
The AD0 pin can select either 0x68 or 0x69. Connect one to GND and the other to 3.3V (not to 5V).
If the I2C Scanner can not find them, then perhaps you need to power the module with 5V to VCC. The sensor module has a voltage regulator which causes a voltage drop.
Do you see those tiny black smd components with "222". Those are the 2k2 pullup resistors for SDA and SCL. They are low in value, 10k would be better. If you add more I2C devices, then maybe you have to remove a few pullup resistors.
pask98
October 21, 2022, 9:19am
4
I use this code to scan IC2 bus:
// I2C address scanner program
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(115200);
Serial.println("I2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address < 16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address < 16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found");
else
Serial.println("done");
delay(5000); // wait 5 seconds for next scan
}
It finds 2 devices:
pask98
October 21, 2022, 9:23am
5
What do you mean?
I use Adafruit_MPU6050.h library to begin (default IC2 address 0x68) a connection with MPU6050.
pask98:
default IC2 address 0x68
Exactly, but using the scanner you have discovered that the 2 devices have different addresses so you need to use an address other than the default for one of them
pask98
October 21, 2022, 1:22pm
7
In the code I initialized MPU2 with 0x69:
if (!MPU1.begin() || !MPU2.begin(0x69)) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
while MPU1 uses 0x68
Try each sensor on its own using its own address
Do each of them work ?
pask98
October 21, 2022, 2:28pm
10
So, I have connected two new MPU5060s and now both are printing values. Maybe, the previous ones were defective.
MPU1 seems to work while MPU2 does not update values based on motion.
The code is the same.
If I test them separately, everything works correctly.
Koepel
October 21, 2022, 7:55pm
11
Have you tried with 5V to the MPU-6050 module VCC pin ?
You must be 100% sure that AD0 is connected to 3.3V or GND and never to 5V.
Do you use a breadboard ? Breadboards have bad contacts and jumper wires can be broken.
Can you show a photo, so we can check the wires and the soldering.
A chip can be half-damaged. Is it always one MPU-6050 module that causes the problem ? Maybe it it is damaged, even if it works on its own.
Some breadboards have intentional breaks in the centre of their power strips, denoted by a break in the associated marking (red/black/blue) of the associated painted line in the plastic
after this post, could the OP post the latest code they are using and a image of the project?
system
Closed
April 19, 2023, 8:17pm
14
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.