Hello,
I am trying to use the MPRLS Sensor and the MPU6050 Sensor combined with one Arduino Uno via the I2C. I am not very familiar with programming so I try to use the code that I find.
I'm working with the MPU 6050 code by Jeff Rosberg. I want to get pitch and raw. This works really good. But as soon as I call the mpr.readPressure() function from the Adafruit library, the values from the MPU6050 start to become jumpy and crazy. Does anybody know what I might be doing wrong? When I comment the funtion out its working fine.
MPU6050_DMP6.ino (18.2 KB)
When you ran the I2C scanner what address did you get for each device? Did you have both sensors connected when you ran the I2C scanner? I know that the 2 devices are supposed to have widely different address but, as the issue as described, starting at the beginning might be worth it.
I did not run an I2C scanner, but now I did and it says:
Scanning...
I2C device found at address 0x18 !
I2C device found at address 0x68 !
done
What happens when you run this first?
//preassure
if (! mpr.begin()) {
// Serial.println("Failed to communicate with MPRLS sensor, check wiring?");
while (1) {
delay(10);
}
}
When I put it first, it makes no difference.
pull-up resistors on the scl/sda lines.
It is important to make sure that the MPRLS sensor works alone, using the provided example code, and that you understand how the code and sensor works.
jremington:
It is important to make sure that the MPRLS sensor works alone, using the provided example code, and that you understand how the code and sensor works.
Thanks for the information, but I checked both sensors. They work fine alone. When I combine them, the MPRLS still works fine, the only problem is that the MPU starts acting weird. In the begging the MPU also works fine and then aftr a few seconds it gets all messy.
Idahowalker:
pull-up resistors on the scl/sda lines.
This means to make a connection between SCA/SDA to VCC right? Could you maybe help me figure out what value the resistors should be?
Using the words 'arduino i2c pullup resistors' with my favorite search engine yielded some good results on the subject.
Perhaps you are interfering with the timing of the MPU-6050 DMP calculations.
If you can use stationary pitch and roll angles, consider starting with a much simpler pitch and roll calculation that does not use the gyro or DMP, and is more accurate to boot:
// minimal MPU-6050 tilt and roll (sjr)
// works perfectly with GY-521, pitch and roll signs agree with arrows on sensor module 7/2019
// tested with eBay Pro Mini, **no external pullups on SDA and SCL** (works with internal pullups!)
//
#include<Wire.h>
const int MPU_addr1 = 0x68;
float xa, ya, za, roll, pitch;
void setup() {
Wire.begin(); //begin the wire communication
Wire.beginTransmission(MPU_addr1); //begin, send the slave adress (in this case 68)
Wire.write(0x6B); //make the reset (place a 0 into the 6B register)
Wire.write(0);
Wire.endTransmission(true); //end the transmission
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(MPU_addr1);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr1, 6, true); //get six bytes accelerometer data
xa = Wire.read() << 8 | Wire.read();
ya = Wire.read() << 8 | Wire.read();
za = Wire.read() << 8 | Wire.read();
roll = atan2(ya , za) * 180.0 / PI;
pitch = atan2(-xa , sqrt(ya * ya + za * za)) * 180.0 / PI;
Serial.print("roll = ");
Serial.print(roll,1);
Serial.print(", pitch = ");
Serial.println(pitch,1);
delay(400);
}
An explanation of the above code is outlined here: How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing-DFRobot
jremington:
Perhaps you are interfering with the timing of the MPU-6050 DMP calculations.
If you can use stationary pitch and roll angles, consider starting with a much simpler pitch and roll calculation that does not use the gyro or DMP, and is more accurate to boot:
Thank you for the code! That seems to work just fine, is there any 'disadvantage' to only using this? Mostly I am using the Tilt value for pitch selection in digital musical instruments.
The method assumes that the only acceleration being measured is due to the Earth's gravity, which is not true if the sensor is rotating or being accelerated by some other force as well.
The DMP uses the gyro in an attempt to correct for rotation, but the correction is not very accurate.