mjs513 / FreeIMU-Updates

IMU - FreeIMU Library Zero Drift, Altitude & LSM303 Heading Stability
MIT License
330 stars 160 forks source link

MPU9150 Erratic Magnetometer Readings #51

Closed martinferris closed 8 years ago

martinferris commented 8 years ago

Having uploaded and implemented the MPU9150_AHRS.ino example, I'm getting strange and erratic mag readings and was hoping you could help identify the problem. I have edited the code to only display the mag serial prints and this is a series of outputs when the arduino is stationary:

mx = -12521 my = 9042 mz = -31466 mG mx = -12521 my = 9042 mz = -31466 mG mx = -9448 my = 1084 mz = -29930 mG mx = -10985 my = -20424 mz = -27625 mG mx = -10985 my = -20424 mz = -27625 mG mx = -11753 my = -15047 mz = -29930 mG mx = -11753 my = -15047 mz = -29930 mG mx = -7912 my = -22728 mz = -26089 mG mx = -14825 my = 24404 mz = -26857 mG mx = -14825 my = 24404 mz = -26857 mG mx = -16361 my = -19655 mz = -27625 mG mx = -13289 my = -27337 mz = -24553 mG mx = -13289 my = -27337 mz = -24553 mG mx = -8680 my = -28873 mz = -29162 mG mx = -8680 my = -28873 mz = -29162 mG

Is this a problem with my setup? I am using an arduino nano328 with an MPU9150 IMU and bluetooth HC-05 module. The test code above was over read USB COM port. I'd appreciate any help, thanks!

mjs513 commented 8 years ago

Hi Martin

A couple of things: 1) make sure you have go into the FreeIMU.h file and uncomment the 9150 imu and make sure all the other boards are commented out. It sounds like the wrong board is selected and 2) use the serial arm CPU sketch. The one you are using was a special case if the mpl3115 pressure sensor is used.

Hope this helps

Mike

martinferris commented 8 years ago

Hi Mike,

It turns out I had forgotten to add this line of code in the setup: Wire.begin();

Thank you for the quick response and feedback, it was greatly appreciated. I didn't have a chance to try your solutions but as it is working now I'd rather not tinker with it anymore in case I break something!

All the best, Martin