Need Help with Arduino Code Errors

Hi everyone,

I'm new to Arduino and I'm currently working on a project that involves using an MPU6050 accelerometer and a BMP085 barometric pressure sensor. However, I've run into some errors in my code that I can't seem to fix on my own.

Here is the code that I'm working with:

#include <Wire.h>
#include <I2Cdev.h>
#include <MPU6050.h>
#include <Adafruit_BMP085.h>

MPU6050 mpu;
Adafruit_BMP085 bmp;

void setup() {
Wire.begin();
Serial.begin(9600);
mpu.initialize();
if (mpu.dmpInitialize() != 0) {
Serial.println("MPU6050 initialization failed");
while (1);
}
bmp.begin();
}

void loop() {
float pressure = bmp.getPressure() / 100.0F;
Serial.print("Pressure: ");
Serial.print(pressure);
Serial.print(" hPa");

VectorInt16 rawAccel = mpu.getAccelerationRaw();
VectorFloat normAccel = mpu.getAcceleration();
Serial.print("Accel X: ");
Serial.print(rawAccel.x);
Serial.print(", Y: ");
Serial.print(rawAccel.y);
Serial.print(", Z: ");
Serial.print(rawAccel.z);
Serial.print(", Normalized: ");
Serial.print(normAccel.x);
Serial.print(", ");
Serial.print(normAccel.y);
Serial.print(", ");
Serial.println(normAccel.z);

VectorInt16 rawGyro = mpu.getRotationRaw();
VectorFloat normGyro = mpu.getRotation();
Serial.print("Gyro X: ");
Serial.print(rawGyro.x);
Serial.print(", Y: ");
Serial.print(rawGyro.y);
Serial.print(", Z: ");
Serial.print(rawGyro.z);
Serial.print(", Normalized: ");
Serial.print(normGyro.x);
Serial.print(", ");
Serial.print(normGyro.y);
Serial.print(", ");
Serial.println(normGyro.z);

delay(500);

}

And here is the error message that I'm getting:

In function 'void setup()':
error: 'class MPU6050' has no member named 'dmpInitialize'; did you mean 'initialize'?

In function 'void loop()':
error: no matching function for call to 'Adafruit_BMP085_Unified::getPressure()'
error: 'VectorInt16' was not declared in this scope
error: 'VectorFloat' was not declared in this scope
error: expected ';' before 'rawGyro'
error: expected ';' before 'normGyro'

I would really appreciate any suggestions or insights that you might have on how to fix these errors. Thank you in advance for your help!

you said "dmp", did you mean "bmp"? :slight_smile:

Are you combining different codes that you don't fully understand?

thanks for answering.
yes and i also use chatgpt as a help.

Do you mean, as a crutch? Did you do anything with the suggestion I gave you?

-A human being

this is what you mean?

// Initialize MPU6050
mpu.initialize();
if (mpu.bmpInitialize() != 0) {
Serial.println(F("Failed to initialize MPU6050"));
while (1);
}

If you modified the sketch, please repost the entire sketch.

#include <Wire.h>
#include <I2Cdev.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#include <MPU6050.h>

MPU6050 mpu;
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

void setup() {
Serial.begin(9600);
Wire.begin();

// Initialize MPU6050
mpu.initialize();
if (mpu.bmpInitialize() != 0) {
Serial.println(F("Failed to initialize MPU6050"));
while (1);
}

// Initialize BMP085
if (!bmp.begin()) {
Serial.println(F("Could not find BMP085 sensor"));
while (1);
}
}

void loop() {
// Read temperature from BMP085
sensors_event_t event;
bmp.getEvent(&event);
float temperature = event.temperature;

// Read pressure from BMP085
float pressure = bmp.getPressure() / 100.0F;

// Read accelerometer and gyro from MPU6050
VectorInt16 rawAccel = mpu.getAccelerationRaw();
VectorFloat normAccel = mpu.getAcceleration();
VectorInt16 rawGyro = mpu.getRotationRaw();
VectorFloat normGyro = mpu.getRotation();

// Print sensor data
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" *C\tPressure: ");
Serial.print(pressure);
Serial.println(" Pa");

Serial.print("Raw Accel: (");
Serial.print(rawAccel.x);
Serial.print(", ");
Serial.print(rawAccel.y);
Serial.print(", ");
Serial.print(rawAccel.z);
Serial.print(")\tNormalized Accel: (");
Serial.print(normAccel.x);
Serial.print(", ");
Serial.print(normAccel.y);
Serial.print(", ");
Serial.print(normAccel.z);
Serial.println(")");

Serial.print("Raw Gyro: (");
Serial.print(rawGyro.x);
Serial.print(", ");
Serial.print(rawGyro.y);
Serial.print(", ");
Serial.print(rawGyro.z);
Serial.print(")\tNormalized Gyro: (");
Serial.print(normGyro.x);
Serial.print(", ");
Serial.print(normGyro.y);
Serial.print(", ");
Serial.print(normGyro.z);
Serial.println(")");

delay(500);
}

Does it compile without errors? If so, what happens when you run it?

If it still won't compile without errors, you need to consult the documentation for the MPU library in use, to see what functions it offers. Because it may not have that one at all.

Compilation error: 'class MPU6050' has no member named 'bmpInitialize'; did you mean 'initialize'?

Yeah. So you need to do what I said, read the documentation and some examples from the MPU library.

Hi, @bcoder70s

To add code please click this link;

It will put your code in a scrolling window, making it easier to read.

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

Hi,
What model Arduino are you using?

Did you test the codes you are trying to combine, separately BEFORE trying to combine them?

Can you please post the codes you sourced your and chatGPT code from?

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

So, there is no real understanding of what the code does on either end.

A much better idea is to learn how to use the MPU6050, starting with an MPU6050 library and the examples that come with it, then learn how to use the pressure sensor, starting with a library and the examples that come with it.

Then put your understanding to use, combining the two.

Why not ask chatgpt to fix this for you.

We need a chatgpt forum where people who use it can go and be coddled.