ESP32 not finding MPU6050 Gyroscope

Hi,

I am hoping some one on here can help me. I am trying to connect an MPU6050 to an ESP32 I think it is the DOIT DEVKIT 1 ( I have attached pictures of the esp to be sure?). The board does not find the MPU and then does not boot. It shows me a NACK error when I press the EN button. THe 2IC scan finds the board correctly connected to pins 22 and 21. Reading online has indicated that we need 4.7K pull up resistors. I just want to ask if any one on here has had any luck with the sensor working when you add the pull ups ? Here is the code base that worked on an older ESP32 ( The one I am using currently is USB C, the older board is Micro USB). I am not a pro, so apologies for any silly questions. Here is my code:

#include <Adafruit_NeoPixel.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>


#define LED_PIN    5
#define LED_COUNT  60

Adafruit_MPU6050 mpu;

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800);

void setup() {
 

   Serial.begin(115200);
   delay(1000);
   Serial.print('File is running');
    Serial.print("hello");

  // while (!Serial)
   // delay(10);

  strip.begin();
  strip.show();
  strip.setBrightness(255);
  // put your setup code here, to run once:


  Serial.print("Adafruit MPU6050 test!");

  // Try to initialize!
  if (!mpu.begin()) {
    Serial.print("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }
  Serial.println("MPU6050 Found!");

  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  Serial.print("Accelerometer range set to: ");
  switch (mpu.getAccelerometerRange()) {
  case MPU6050_RANGE_2_G:
    Serial.println("+-2G");
    break;
  case MPU6050_RANGE_4_G:
    Serial.println("+-4G");
    break;
  case MPU6050_RANGE_8_G:
    Serial.println("+-8G");
    break;
  case MPU6050_RANGE_16_G:
    Serial.println("+-16G");
    break;
  }
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  Serial.print("Gyro range set to: ");
  switch (mpu.getGyroRange()) {
  case MPU6050_RANGE_250_DEG:
    Serial.println("+- 250 deg/s");
    break;
  case MPU6050_RANGE_500_DEG:
    Serial.println("+- 500 deg/s");
    break;
  case MPU6050_RANGE_1000_DEG:
    Serial.println("+- 1000 deg/s");
    break;
  case MPU6050_RANGE_2000_DEG:
    Serial.println("+- 2000 deg/s");
    break;
  }

  mpu.setFilterBandwidth(MPU6050_BAND_5_HZ);
  Serial.print("Filter bandwidth set to: ");
  switch (mpu.getFilterBandwidth()) {
  case MPU6050_BAND_260_HZ:
    Serial.println("260 Hz");
    break;
  case MPU6050_BAND_184_HZ:
    Serial.println("184 Hz");
    break;
  case MPU6050_BAND_94_HZ:
    Serial.println("94 Hz");
    break;
  case MPU6050_BAND_44_HZ:
    Serial.println("44 Hz");
    break;
  case MPU6050_BAND_21_HZ:
    Serial.println("21 Hz");
    break;
  case MPU6050_BAND_10_HZ:
    Serial.println("10 Hz");
    break;
  case MPU6050_BAND_5_HZ:
    Serial.println("5 Hz");
    break;
  }

  Serial.println("");
  //delay(100);

  
   //colorWipe(strip.Color(  255, 255, 255), 50);  

}

void loop() {
  // put your main code here, to run repeatedly:

   colorWipe(strip.Color(  255, 255, 255), 50);  
    sensors_event_t a, g, temp;
    mpu.getEvent(&a, &g, &temp);
   if(a.acceleration.x < -6 || a.acceleration.x >5)
   {

    Serial.print("jumped");
    
  
  colorWipe(strip.Color( 0,   0, 255), 50); // Red
  colorWipe(strip.Color(  0, 255,   0), 50); // Green
  colorWipe(strip.Color(  0,   0, 255), 50); // Blue

  // colorWipe(strip.Color(100,   0,   0), 50); // Red
  // colorWipe(strip.Color(  0, 100,   0), 50); // Green
  // colorWipe(strip.Color(  0,   0, 100), 50); // Blue
 

   }
     
 



    /* 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(100);

 

  



}

void colorWipe(uint32_t color, int wait) {
  for(int i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, color);
    strip.show();
    delay(wait);
  }
}

I am sure the code could be a lot better aswell. Any recommendations are welcome. Images of the current ESP32

Thank yo so much for yoru time !

Sarina

Hi, @sartill

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

1 Like

Step 1 is to run an I2C scan to verify the MPU6050 address.
Step 2 is remove all the extraneous RGB code.
As far as the rest of your sketch it does not look familiar. What I often do is pick a library then try a supplied example sketch that is closest to what you wantr and then copy it and start modifying it.
I would start with the following

found at the following

When you used the I2C scanner to confirm that the mpu6050 could be found, what address did it return? 0x68?
Post a link to your mpu6050 board. The pullup resistors that you've talked about may already be there, possibly jumpered.