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



