I want to connect two MPU6050 sensor on Esp32 using the I2C protocol.
ESP32 to MPU6050 connection, I'm using -
VCC(ESP32) - VCC(MPU6050_1) - VCC(MPU6050_2)
GND(ESP32) - GND(MPU6050_1) - GND(MPU6050_2)
G21(ESP32) - SDA(MPU6050_1) - SDA(MPU6050_2)
G22(ESP32) - SCL(MPU6050_1) - SCL(MPU6050_2)
3V (ESP32) - AD0 (MPU6050_2)
and both the MPU6050 device are also detected by the I2C scanner program 0x68 , 0x69
but when the basic reading program to read for MPU6050 data , one MPU6050 is giving zero value for all accelerate axis and gyro axis.
// Basic demo for accelerometer readings from Adafruit MPU6050
#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); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MPU6050 test!");
// Try to initialize!
if (!mpu1.begin(0x68)) {
Serial.println("Failed to find MPU6050 chip1");
while (1) {
delay(10);
}
}
if (!mpu2.begin(0x69)) {
Serial.println("Failed to find MPU6050 chip2");
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 first() {
/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu1.getEvent(&a, &g, &temp);
Serial.println("Sensor 1");
/* Print out the values */
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");
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" degC");
Serial.println("");
delay(500);
}
void second() {
/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu2.getEvent(&a, &g, &temp);
Serial.println("Sensor 2");
/* Print out the values */
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");
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" degC");
Serial.println("");
delay(500);
}
void loop(){
first();
delay(1000);
second();
}
All connection and config are correct both still MPU6050 sensor two not giving the correct data.
I request you to please check and see, what wrong I'm doing in it.
Serial Monitor -
Adafruit MPU6050 test!
MPU6050 Found!
Sensor 1
Acceleration X: -2.18, Y: 1.27, Z: 9.20 m/s^2
Rotation X: 0.23, Y: 8.34, Z: 2.97 rad/s
Temperature: 31.69 degC
Sensor 2
Acceleration X: 0.00, Y: 0.00, Z: 0.00 m/s^2
Rotation X: 0.00, Y: 0.00, Z: 0.00 rad/s
Temperature: 36.53 degC
Sensor 1
Acceleration X: -2.21, Y: 1.29, Z: 9.17 m/s^2
Rotation X: 0.06, Y: 8.29, Z: 2.96 rad/s
Temperature: 31.70 degC
Sensor 2
Acceleration X: 0.00, Y: 0.00, Z: 0.00 m/s^2
Rotation X: 0.00, Y: 0.00, Z: 0.00 rad/s
Temperature: 36.53 degC
-
1please add the content of the serial monitor ... copy and paste, then format same as code ... NO pictures pleasejsotola– jsotola10/04/2023 17:05:02Commented Oct 4, 2023 at 17:05
-
@jsotola , I added the serial monitor data in the question lower sections, please check above. actually, the Sensor 1 (MPU6050) data is correct but the sensor 2 (MPU6050) data is showing zero only.Sourabh Tiwari– Sourabh Tiwari10/05/2023 05:45:01Commented Oct 5, 2023 at 5:45
-
you forgot to format as code ... did it for youjsotola– jsotola10/05/2023 05:51:41Commented Oct 5, 2023 at 5:51
-
swap the modules ... what is the resulting data?jsotola– jsotola10/05/2023 05:53:12Commented Oct 5, 2023 at 5:53
-
Same results as previous , sensor which AD0 pin connected to 3.3V is giving Zero values.Sourabh Tiwari– Sourabh Tiwari10/06/2023 17:55:50Commented Oct 6, 2023 at 17:55