kriswiner / MPU9250

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

Can't connect to MPU9250 #246

Open Jan-Jelle opened 6 years ago

Jan-Jelle commented 6 years ago

Good afternoon Kris,

First of all I'd like to thank you for all the work you put into this library. it helped me a great deal to get my project going!

I started to re-write my arduino sketch to include your libraries as files instead of having all the code in the sketch itself. after changing all the function names and adding the necessary variables etc. it seems to compile fine, but i can't connect to the sensor anymore. an I2C scan shows it has address 0x68 so it should be OK. and running an example you made also works fine, but with the included libraries as a header file it seems like it doesn't read the WHOAMI register properly (0xFF comes back). after going through your header and cpp file the only difference I could find was in the read_Byte function. in the working example you've put:

Wire.requestFrom(address, (uint8_t) 1);  // Read one byte from slave register address 

And in the CPP file it says:

Wire.requestFrom(address, 1); // Read two bytes from slave register address

I wondered if this extra byte could give an issue in the buffer and it doesn't read the WHOAMI register value properly. but after changing this in the CPP file to the line above it didn't help either.

I know this sounds a bit fuzzy but i've been staring at this for too long now. perhaps you can help me with this otherwise i'll try to rephrase my question tomorrow.

Thanks!

kriswiner commented 6 years ago

Are you sure you are using 0x68 as the MPU9250 address?

On Mon, Mar 12, 2018 at 1:54 PM, Jan-Jelle notifications@github.com wrote:

Good afternoon Kris,

First of all I'd like to thank you for all the work you put into this library. it helped me a great deal to get my project going!

I started to re-write my arduino sketch to include your libraries as files instead of having all the code in the sketch itself. after changing all the function names and adding the necessary variables etc. it seems to compile fine, but i can't connect to the sensor anymore. an I2C scan shows it has address 0x68 so it should be OK. and running an example you made also works fine, but with the included libraries as a header file it seems like it doesn't read the WHOAMI register properly (0xFF comes back). after going through your header and cpp file the only difference I could find was in the read_Byte function. in the working example you've put:

Wire.requestFrom(address, (uint8_t) 1); // Read one byte from slave register address

And in the CPP file it says:

Wire.requestFrom(address, 1); // Read two bytes from slave register address

I wondered if this extra byte could give an issue in the buffer and it doesn't read the WHOAMI register value properly. but after changing this in the CPP file to the line above it didn't help either.

I know this sounds a bit fuzzy but i've been staring at this for too long now. perhaps you can help me with this otherwise i'll try to rephrase my question tomorrow.

Thanks!

— 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/246, or mute the thread https://github.com/notifications/unsubscribe-auth/AGY1qlya3WLT1aTGoiB2PNAKRjm3ORdXks5tduB1gaJpZM4SnfxV .

Jan-Jelle commented 6 years ago

I've taken out the #if #endif construction for the possible address of 0x69. the header file now contains:

// Define I2C addresses of MPU9250

define MPU9250_ADDRESS 0x68 // Device address when ADO = 0

define AK8963_ADDRESS 0x0C // Address of magnetometer

The GetMPU9250ID function should use this address and the WHOAMI 0x75 register as far as i can see. did i forget to include some function to define the address in the arduino sketch? i havn't done anything in the sketch regarding addressing..

Jan-Jelle commented 6 years ago

Ok I figured it out... like i said i've been staring at it for too long. appearantly i removed the "Wire.begin();" function in the setup part during some tinkering...

apologies for this silly mistake, it works like a charm now! :) again, good work on this library! very pleased with the result. I'll show you some pictures of what is build if you are interested? just let me know how you feel about that.