-
Notifications
You must be signed in to change notification settings - Fork 10
multiple tinyMPU6050 #23
Comments
Hi @jorritxl thanks for writing. You do not need to edit anything. You can use the constructor as follows: MPU6050 (TwoWire &w, int i2cAddress = MPU6050_ADDRESS); As you can see, the If you need further help, please let me know. |
Thanks for the fast response! Unfortunately, I am not able to fully understand your answer. This is the code which I want to convert to do the same for 2 MPU's at the same time:/*
/*
MPU6050 mpu (Wire); /*
// Initialization // Calibration /*
/*
float sqDevSum = 0.0; for(int i = 0; i < SAMPLES; i++) { float stDev = sqrt(sqDevSum/float(SAMPLES)); sampleSum = 0; }I tried to replace But I get an error. Can you tell me how I can make it work? Thankx |
Markdown formatting tipWhenever you write code on your issue, please wrap it using three backticks, like this: ``` That way, it gets more readable. The output would be this:
Anyway, let's now focus on your issue. TL;DR
MPU6050 mpu (Wire); with MPU6050 mpu0 (Wire, 0x68);
MPU6050 mpu1 (Wire, 0x69);
Full explanationThe constructor I've shown previously: MPU6050 (TwoWire &w, int i2cAddress = MPU6050_ADDRESS); is only shown for better understanding of the parameters passed when constructing the MPU6050 mpu (Wire); which maps onto the constructor If you want to construct an object using that constructor I've shown, you'll need something like this: MPU6050 mpu0 (Wire, 0x68);
MPU6050 mpu1 (Wire, 0x69); That way, for both of them, But then remember that, for each method you'd call on Finally, your code would look like this: /*
* Mandatory includes
*/
#include <Arduino.h>
#include <TinyMPU6050.h>
/*
* Constant values
*/
#define MPU6050_ADDRESS_ZERO 0x68
#define MPU6050_ADDRESS_ONE 0x69
/*
* Constructing MPU-6050
*/
MPU6050 mpu0 (Wire, MPU6050_ADDRESS_ZERO);
MPU6050 mpu1 (Wire, MPU6050_ADDRESS_ONE);
float myNum[200];
float sampleSum = 0;
int SAMPLES = 199;
/*
* Setup
*/
void setup() {
// Initialization
mpu0.Initialize();
mpu1.Initialize();
// Calibration
Serial.begin(9600);
Serial.println("=====================================");
Serial.println("Calibrating device #0...");
mpu0.Calibrate();
Serial.println("Calibrating device #1...");
mpu1.Calibrate();
Serial.println("Calibration complete!");
// I've removed printing offsets for shorting the code
}
/*
* Get sensor data
*/
void loop() {
for(int i = 0; i < SAMPLES; i++){
mpu0.Execute();
mpu1.Execute();
// TODO> Please set here from which MPU device you'd like to extract data
// myNum[i] = mpuX.GetAngX();
// sampleSum += myNum[i];
delay(20);
}
/*
* Get statistics every x reading
*/
float meanSample = sampleSum/float(SAMPLES);
float sqDevSum = 0.0;
for(int i = 0; i < SAMPLES; i++) {
// pow(x, 2) is x squared.
sqDevSum += pow((meanSample - float(myNum[i])), 2);
}
float stDev = sqrt(sqDevSum/float(SAMPLES));
Serial.print("stdev:");
Serial.println(stDev, 4);
Serial.print("mean: ");
Serial.println(meanSample, 4);
Serial.println("------");
sampleSum = 0;
sqDevSum = 0.0;
meanSample = 0;
} |
I'd like to thank you for your help Gabriel! Fully understood. When you have the time, continue reading otherwise, don't bother. Another question about the complimentary filtering out of curiosity: I found the following lines which are about the filtering: static float angle_average(float wa, float a, float wb, float b) Can you explain how these lines are increasing the accuracy of the MPU6050? Thanx |
Glad I could help with that. Now answering your other question, the On the other hand, when you do angX = angle_average(filterAccelCoeff, angAccX, filterGyroCoeff, angX + gyroX * dt); you're averaging the angle computed using the accelerometer data ( |
Hello Gabriel,
How can I edit the library or my own arduino code to access 2 MPU6050's (0x68 and 0x69) while using the tinyMPU6050 libary?
Thankx
The text was updated successfully, but these errors were encountered: