mpu6050 not working with esp32

Hello .
I want to start Module mpu6050 with Module esp32, but Rajab does not show me the module mpu6050 serial printout output.
I put program i2c scanner on module mpu6050 and was able to see Ardes i2c, but I do not know why it does not work with esp32.
please help...

If the I2C Scanner can find the sensor, then the I2C bus is working.
Which library or sketch do you use for the MPU-6050 ?

#include<Wire.h>
const int MPU=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
  Serial.begin(115200);
}
void loop(){
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  
//  Serial.print("Accelerometer: ");
  Serial.print("X = "); Serial.print(AcX);
  Serial.print(" | Y = "); Serial.print(AcY);
  Serial.print(" | Z = "); Serial.println(AcZ);
  //equation for temperature in degrees C from datasheet
  Serial.print("Temperature: "); Serial.print(Tmp/340.00+36.53); Serial.println(" C "); 
  
  Serial.print("Gyroscope: ");
  Serial.print("X = "); Serial.print(GyX);
  Serial.print(" | Y = "); Serial.print(GyY);
  Serial.print(" | Z = "); Serial.println(GyZ);
  Serial.println(" ");
  delay(100);

That sketch does not compile. Probably missing a '}' at the end.

I think that sketch should work.
Did you set the serial monitor to 115200 baud ? It might be still at the default of 9600 baud.

You could add a message that it has started:

void setup()
{
  Serial.begin( 115200);
  Serial.println( "The sketch has started.");
  ...

I have had similar problems in the past.
You can try manually defining the SDA and SCL pins in setup, that seemed to solve the issue for me.

void setup() {
  Wire.begin(5,4); //SDA (PIN 5), SCL (PIN 4) could be different for your board
  Serial.begin(115200);
  delay(10);

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.