kriswiner / MPU9250

Arduino sketches for MPU9250 9DoF with AHRS sensor fusion
1.04k stars 470 forks source link

mpu9250 output #328

Open amirhosseinqasemi opened 6 years ago

amirhosseinqasemi commented 6 years ago

Hi dear kris, I use of arduino pro mini 3.3 and mpu9250. For my university project I need to yaw, pitch and roll. I know pro mini isn’t suitable for this work, but I due to use this. Now if I do a good calibration, is it possible to have a rather good output? It’s important for me that pitch doesn’t affect on yaw or roll. deflection about 5 degree isn’t important for me.

kriswiner commented 6 years ago

I would start with this https://github.com/kriswiner/ESP32/blob/master/MPU9250_MS5637/MPU9250_MS5637_AHRS.ino sketch, you will have to add the quaternionFilters.ino sketch using the tab. You will also have to change a few of the wire calls for the Arduino Pro Mini, byt this should give you what you need. The Pro Mini is really too slow to do this job properly, so you will see a lot of latency and not very accurate orientation estimation.

On Thu, Nov 22, 2018 at 1:46 PM amir96 notifications@github.com wrote:

Hi dear kris, I use of arduino pro mini 3.3 and mpu9250. For my university project I need to yaw, pitch and roll. I know pro mini isn’t suitable for this work, but I due to use this. Now if I do a good calibration, is it possible to have rather good output? It’s important for me that pitch doesn’t affect on yaw or roll. deflection about 5 degree isn’t important for me.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/328, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qouuAoU-dIWNLtqRTHGrEPM7oDbrks5uxxslgaJpZM4Yv6fT .

amirhosseinqasemi commented 6 years ago

Thank you kris. And how can I plot calibration data? What should I plot? By arduino plotter?! Do you have sketch for plotting?

kriswiner commented 6 years ago

You are on your own now...but see this https://github.com/kriswiner/MPU6050/wiki/Simple-and-Effective-Magnetometer-Calibration .

On Thu, Nov 22, 2018 at 2:21 PM amir96 notifications@github.com wrote:

Thank you kris. And how can I plot calibration data? What should I plot? By arduino plotter?! Do you have sketch for plotting?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/328#issuecomment-441128030, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qukaLfDmZE5QGOCnXMctEeGo17FFks5uxyNagaJpZM4Yv6fT .

amirhosseinqasemi commented 6 years ago

Hi, I think this part of your code has a problem:

`// If intPin goes high, all data registers have new data
if(newData == true) { 
 newData = false;  
 readMPU9250Data(MPU9250Data);

// Now we'll calculate the accleration value into actual g's
 ax = (float)MPU9250Data[0]*aRes - accelBias[0];  // get actual g value, this depends on scale being set
 ay = (float)MPU9250Data[1]*aRes - accelBias[1];   
 az = (float)MPU9250Data[2]*aRes - accelBias[2];  

// Calculate the gyro value into actual degrees per second
 gx = (float)MPU9250Data[4]*gRes;  // get actual gyro value, this depends on scale being set
 gy = (float)MPU9250Data[5]*gRes;  
 gz = (float)MPU9250Data[6]*gRes; 

newMagData = (readByte(AK8963_ADDRESS, AK8963_ST1) & 0x01);
if(newMagData == true) { // wait for magnetometer data ready bit to be set
  readMagData(magCount);  // Read the x/y/z adc values  
// Calculate the magnetometer values in milliGauss
// Include factory calibration per data sheet and user environmental corrections
  mx = (float)magCount[0]*mRes*magCalibration[0] - magBias[0];  // get actual magnetometer value, this depends on scale being set
  my = (float)magCount[1]*mRes*magCalibration[1] - magBias[1];  
  mz = (float)magCount[2]*mRes*magCalibration[2] - magBias[2];  
  mx *= magScale[0];
  my *= magScale[1];
  mz *= magScale[2]; 
}`

when I superseded by this, I see the data:

` if (readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) {  // On interrupt, check if data ready interrupt
readAccelData(accelCount);  // Read the x/y/z adc values
getAres();

// Now we'll calculate the accleration value into actual g's
ax = (float)accelCount[0]*aRes - accelBias[0];  // get actual g value, this depends on scale being set
ay = (float)accelCount[1]*aRes - accelBias[1];   
az = (float)accelCount[2]*aRes - accelBias[2];  

readGyroData(gyroCount);  // Read the x/y/z adc values
getGres();

// Calculate the gyro value into actual degrees per second
gx = (float)gyroCount[0]*gRes;  // get actual gyro value, this depends on scale being set
gy = (float)gyroCount[1]*gRes;  
gz = (float)gyroCount[2]*gRes;   

readMagData(magCount);  // Read the x/y/z adc values
getMres();

// Calculate the magnetometer values in milliGauss
// Include factory calibration per data sheet and user environmental corrections
mx = (float)magCount[0]*mRes*magCalibration[0] - magBias[0];  // get actual magnetometer value, 
this depends on scale being set
my = (float)magCount[1]*mRes*magCalibration[1] - magBias[1];  
mz = (float)magCount[2]*mRes*magCalibration[2] - magBias[2];   
 }`

what's the problem of first code? how can I fix it? I used old code. please help me. tnx

kriswiner commented 6 years ago

The problem is you are not setting up tour interrupt properly. Which pin are you using for interrupt?

On Fri, Nov 23, 2018 at 12:25 AM amir96 notifications@github.com wrote:

Hi, I think this part of your code has a problem: ` // If intPin goes high, all data registers have new data if(newData == true) { // On interrupt, read data newData = false; // reset newData flag readMPU9250Data(MPU9250Data); // INT cleared on any read

// Now we'll calculate the accleration value into actual g's ax = (float)MPU9250Data[0]aRes - accelBias[0]; // get actual g value, this depends on scale being set ay = (float)MPU9250Data[1]aRes - accelBias[1]; az = (float)MPU9250Data[2]*aRes - accelBias[2];

// Calculate the gyro value into actual degrees per second gx = (float)MPU9250Data[4]gRes; // get actual gyro value, this depends on scale being set gy = (float)MPU9250Data[5]gRes; gz = (float)MPU9250Data[6]*gRes;

newMagData = (readByte(AK8963_ADDRESS, AK8963_ST1) & 0x01); if(newMagData == true) { // wait for magnetometer data ready bit to be set readMagData(magCount); // Read the x/y/z adc values

// Calculate the magnetometer values in milliGauss // Include factory calibration per data sheet and user environmental corrections mx = (float)magCount[0]mResmagCalibration[0] - magBias[0]; // get actual magnetometer value, this depends on scale being set my = (float)magCount[1]mResmagCalibration[1] - magBias[1]; mz = (float)magCount[2]mResmagCalibration[2] - magBias[2]; mx = magScale[0]; my = magScale[1]; mz *= magScale[2]; }`

when I superseded by this, I see the data: `if (readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) { // On interrupt, check if data ready interrupt readAccelData(accelCount); // Read the x/y/z adc values getAres();

// Now we'll calculate the accleration value into actual g's ax = (float)accelCount[0]aRes - accelBias[0]; // get actual g value, this depends on scale being set ay = (float)accelCount[1]aRes - accelBias[1]; az = (float)accelCount[2]*aRes - accelBias[2];

readGyroData(gyroCount); // Read the x/y/z adc values getGres();

// Calculate the gyro value into actual degrees per second gx = (float)gyroCount[0]gRes; // get actual gyro value, this depends on scale being set gy = (float)gyroCount[1]gRes; gz = (float)gyroCount[2]*gRes;

readMagData(magCount); // Read the x/y/z adc values getMres();

// Calculate the magnetometer values in milliGauss // Include factory calibration per data sheet and user environmental corrections mx = (float)magCount[0]mResmagCalibration[0] - magBias[0]; // get actual magnetometer value, this depends on scale being set my = (float)magCount[1]mResmagCalibration[1] - magBias[1]; mz = (float)magCount[2]mResmagCalibration[2] - magBias[2];

}` what's the problem of first code? how can I fix it? I used old code. please help me. tnx

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/328#issuecomment-441178164, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qri899gtP6OpDjfBycFW4q_hP6goks5ux7DkgaJpZM4Yv6fT .

amirhosseinqasemi commented 6 years ago

I didn't change default settings.

int intPin = 12; // can be any pin

define DMP_INT_STATUS 0x39 // Check DMP interrupt

define INT_STATUS 0x3A

is that what you pointed or not?

amirhosseinqasemi commented 6 years ago

untitledaaa this is my calibration plot. I repeat calibration process, but no change in result. why? I've done it by rotating in figure 8.

kriswiner commented 6 years ago

So are you using pin 12 as the interrupt or not?

On Sat, Nov 24, 2018 at 9:17 AM amir96 notifications@github.com wrote:

[image: untitledaaa] https://user-images.githubusercontent.com/26376234/48971025-d6a0fc00-f029-11e8-981b-c97a42c1a5c3.png this is my calibration plot. I repeat calibration process, but no change in result. why? I've done it by rotating in figure 8/

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/328#issuecomment-441382203, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qqdUvWsZKGee09xQTcR1luw69xJ0ks5uyX8SgaJpZM4Yv6fT .

amirhosseinqasemi commented 6 years ago

yes, I don't change it.

kriswiner commented 6 years ago

Show mw a picture of your setup with the interrupt connected.

On Sat, Nov 24, 2018 at 9:19 AM amir96 notifications@github.com wrote:

yes, I don't change it.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/328#issuecomment-441382314, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qsBbJhXhE_gZuNtVZe0DTAfLpDiwks5uyX-QgaJpZM4Yv6fT .

amirhosseinqasemi commented 6 years ago

// Set up the interrupt pin, its set as active high, push-pull pinMode(intPin, INPUT); digitalWrite(intPin, LOW); pinMode(myLed, OUTPUT); digitalWrite(myLed, LOW);

kriswiner commented 6 years ago

Delete this line: digitalWrite(intPin, LOW);

This is not a picture, I want to see the wires.

On Sat, Nov 24, 2018 at 9:39 AM amir96 notifications@github.com wrote:

// Set up the interrupt pin, its set as active high, push-pull pinMode(intPin, INPUT); digitalWrite(intPin, LOW); pinMode(myLed, OUTPUT); digitalWrite(myLed, LOW);

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/328#issuecomment-441383585, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qjeTooqFncmVTOvkG-XzroO6zIk9ks5uyYRKgaJpZM4Yv6fT .

amirhosseinqasemi commented 6 years ago

I didn't connect pin 12 to int pin.I though just SDA and SCL is needed. is it possible that all of my problem caused from this part?

kriswiner commented 6 years ago

Electronics is not magic, if you don't connect something how can it possible work?!

On Sat, Nov 24, 2018 at 9:49 AM amir96 notifications@github.com wrote:

I didn't connect pin 12 to int pin.I though just SDA and SCL is needed. is it possible that all of my problem caused from this part?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kriswiner/MPU9250/issues/328#issuecomment-441384198, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qqFQjny_1SzwjbRk-7_cJHG91mDsks5uyYaTgaJpZM4Yv6fT .

amirhosseinqasemi commented 6 years ago

untitledaaa what about calibration? this is my calibration plot. I repeat calibration process, but no change in result. why? I've done it by rotating in figure 8.