Arduino Forum

Development => Other Software Development => Topic started by: gregd72002 on May 24, 2014, 01:03 pm

Title: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on May 24, 2014, 01:03 pm
Hi,

As a subtask for my main project I ported the entire InvenSense MPU/DMP 5.1 library to Arduino. Hopefully this will save time someone in the future.

I am well aware of other implementations of this library, however this implementation is intended to be comprehensive and clean. As such it is not the most space efficient but it features all functions and is easy to debug.

The encapsulating demo does a simple Quaternions calculation and outputs them along with some additional debug data.

Main features:
- uses FastWire and I2Cdev from Jeff Rowberg
- DMP enabled
- calculates and displays gyro and quaternions
- Makefile provided for Arduino-Makefile (https://github.com/sudar/Arduino-Makefile)

https://github.com/rpicopter/ArduinoMotionSensorExample

Thanks,
Gregory
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: robtillaart on May 24, 2014, 02:31 pm
Thanks for sharing
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: Takostyle on Jun 19, 2014, 09:05 pm
Hi,

I'm actualy trying to use your library but i've encountered some errors.

I first downloaded the .zip with all the files. I extracted it in my project folder and opened it in Arduino IDE. It didn'T build at first because of the #define i had to put in inv_mpu.cpp.

Once i've put my "#define MPU6050" i tried to build but got some more errors:

C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp: In static member function 'static int8_t I2Cdev::readBytes(uint8_t, uint8_t, uint8_t, uint8_t*, uint16_t)':
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp:276: error: 'BUFFER_LENGTH' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp:277: error: 'Wire' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp: In static member function 'static int8_t I2Cdev::readWords(uint8_t, uint8_t, uint8_t, uint16_t*, uint16_t)':
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp:414: error: 'BUFFER_LENGTH' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp:415: error: 'Wire' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp: In static member function 'static bool I2Cdev::writeBytes(uint8_t, uint8_t, uint8_t, uint8_t*)':
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp:598: error: 'Wire' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp: In static member function 'static bool I2Cdev::writeWords(uint8_t, uint8_t, uint8_t, uint16_t*)':
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp:653: error: 'Wire' was not declared in this scope

These are quite simple errors but i can't find the origine.

Wire is declared a bit higher in the code:

#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE

    #ifdef I2CDEV_IMPLEMENTATION_WARNINGS
        #warning Using I2CDEV_BUILTIN_NBWIRE implementation may adversely affect interrupt detection.
        #warning This I2Cdev implementation does not support:
        #warning - Repeated starts conditions
    #endif

    // NBWire implementation based heavily on code by Gene Knight <Gene@Telobot.com>
    // Originally posted on the Arduino forum at http://arduino.cc/forum/index.php/topic,70705.0.html
    // Originally offered to the i2cdevlib project at http://arduino.cc/forum/index.php/topic,68210.30.html
    TwoWire Wire;

#endif

At fisrt I tought that it was because it was in a if condition and the compiler just ignored it, but even if i put just after the if condition, the compiler says:

I2Cdev.cpp:90: error: 'TwoWire' does not name a type

I know for sure that all the code in the if condition is not executed because i wrote some random code and it didn't flaged it.

Once there, i don't realy know what else to do.
For the BUFFER_LENGTH error i can't find the problem either. This constant is used in other functions but the readBytes and readWords don't recognize the BUFFER_LENGTH.

Since i didn't wrote anything in the code, i trust that it should be working fine but it won't on my computer.

If you have anything to help me it would be realy awesome !

Thanks in advance,
Marvin.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Jun 26, 2014, 12:20 pm
Hi,

These error look like something has changed. Or is not included as it should.

It looks like I2CDev.h is not included correctly.

If you look into I2Cdev.h, on line 53 it specified to use I2CDEV_BUILTIN_FASTWIRE

But the errors reported by you (line 276 - BUFFER_LENGTH) does not execute when I2CDEV_BUILTIN_FASTWIRE is defined but it will execute when I2CDEV_ARDUINO_WIRE is define. See line 220 I2Cdev.cpp.

Hope this helps.


Of course, you can try to use I2CDEV_ARDUINO_WIRE but then you need to include Wire.h. However, I have not tested this extensively.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: wswong on Jul 10, 2014, 04:02 pm
Hi,

I am getting the exactly same error as Takostyle.

Could you please tell me the information as written below?
1. Where exactly should we include the #define MPU6050? At the beginning of inv_mpu.cpp? (I am using MPU6050 in my application)
2. Which version of IDE you are using?
3. Which Arduino boards you have tested working?

Thanks in advance.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Jul 15, 2014, 02:41 pm
Hi,

The errors are unrelated to the directive #define MPU6050. Placing it at the beginning of in inv_mpu.cpp should be fine. If this is incorrectly defined the compiler will return an error: "Which gyro are you using?"

1) at the beginning of inv_mpu.cpp is fine
2) used the official 1.0.5 libraries in connection with Arduino-Makefile https://github.com/sudar/Arduino-Makefile
3) tested on a few variants of Pro Mini

If you get a chance please attach the full build log.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: conrads1arduino on Aug 04, 2014, 11:44 pm
This works great, thanks!!  :D
Took me less than 5 minutes to get everything up and running on a new setup, showing y,r,p values on the serial port.
Do you also see some initial 'drifting' of the values right after powerup before the values stabilize?
Just as confirmation, I need to set the #define MP6050 in the inv_mpu.h file, and I am using a gy-521 board populated with a mpu6050 and the ardiono uno board.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Aug 13, 2014, 10:33 am
Thanks for trying! Yes, it is not as difficult as it sounds :)

There is initial drift. In fact there are 2 types of drifts:
- initial
- yaw

The MPU has an internal calibration mechanism that is triggered after 8 seconds of no motion. You can find more information in mpu.c and google DMP_FEATURE_SEND_CAL_GYRO.

The yaw drift is normal for this MPU and is very marginal.

Hope this clarifies.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: conrads1arduino on Aug 19, 2014, 07:40 pm
I found some nice work done here http://www.i2cdevlib.com/forums/topic/96-arduino-sketch-to-automatically-calculate-mpu6050-offsets/ to calibrate the MPU.
I modified his code a bit to write the calibrated offset values to EEPROM during calibration and then read it back and apply it during the setup phase of my sketch. The stability on yaw looks really good, still need to test repeated 360 degrees loops to makes sure the values come back to zero after a few loops.
Thanks,
Conrad
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: borenis on Aug 20, 2014, 10:35 am
Hi !

Thanks  a lot for sharing AvrCopter.ino !

I recently bought a MPU9250 breakout board from Drotek, and succeeded to access to accelerometer and gyro values.

I want to use the DMP function of the MPU9250, in order to use it as an integrated AHRS.
After downloading your AvrCopter project, as I use the Arduino IDE, I've added "#define MPU9250" in "inv_pmu.cpp", and the compilation and upload is ok, but I get the following error : "READ ERROR!  " again and again.
I've tryed to find the reason, but after 3 hours yesterday night, I'm a little bit lost !

I've seen the founction "dmp_enable_feature" in inv_mpu_dmp_motion_driver.cpp, but it seems it is never called...

If you could help me, that would be great !!!!

Regards,

Sylvain
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: borenis on Aug 20, 2014, 10:37 am
I just forgot to tell you the board I'm using : Arduino mega2560.
I also have a Leonardo that I can try...

Sylvain
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Aug 27, 2014, 05:20 pm
Hi Sylvain,

READ ERROR message might appear when your wiring is incorrect.

Can you try running i2c scan to see if your device is connected correctly and check what address it uses?
http://playground.arduino.cc/Main/I2cScanner

To change i2c address, see: https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/mpu.cpp#L28
Value 0 = 0x68, Value 1= 0x69

If this does not help please specify #define MPU_DEBUG  in mpu.h and recompile. Post the output (MPU Init value).

Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: borenis on Aug 30, 2014, 01:03 am
Hi,
Thanks for your answer !

I have uploaded i2c-scanner, and I get that :

Scanning...
I2C device found at address 0x68  !
done

So, it's ok, the MPU9250 is present.

I've tried other source codes, basic examples, and I can read accelerometer and gyrometer values (but no magnetometers values at this time).

When I add #define MPU_DEBUG  in mpu.h, I get this :

START
MPU init: 3
Free mem: 6802

READ ERROR!  -1
READ ERROR!  -1
READ ERROR!  -1
READ ERROR!  -1
READ ERROR!  -1
READ ERROR!  -1

Many thanks for yout help !

Sylvain



Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: borenis on Aug 31, 2014, 12:07 am
Hi again !

I've tried that :
in function "mympu_open", with MPU_DEBUG activated, I have suppressed the line
"if (ret) return 10+ret;"

Then, the program ouputs that :
"Firmware compare failed addr 0
0 0 112 0 0 0 0 36 0 0
33 55 0 118 7 0 1 4 40 1 "

Probably an interesting information... but difficult to understand for me !

Regards,

Sylvain
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Sep 01, 2014, 02:16 pm

Hi,
Thanks for your answer !

I have uploaded i2c-scanner, and I get that :

Scanning...
I2C device found at address 0x68  !
done

So, it's ok, the MPU9250 is present.

I've tried other source codes, basic examples, and I can read accelerometer and gyrometer values (but no magnetometers values at this time).

When I add #define MPU_DEBUG  in mpu.h, I get this :

START
MPU init: 3
Free mem: 6802

READ ERROR!  -1
READ ERROR!  -1
READ ERROR!  -1
READ ERROR!  -1
READ ERROR!  -1
READ ERROR!  -1

Many thanks for yout help !

Sylvain






Thanks, this explains quite a bit.

MPU Init: 3
indicates that the following call fails:
https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/mpu.cpp#L31

Following the references, this can be traced to the following call:
https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/inv_mpu.cpp#L634
This above call is a generic driver call and should not fail. The only explanation I have is that one or more parameters are not set properly. Unfortunately, I do not have MPU9250 to test it.
The parameters are all set in here: https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/inv_mpu.cpp#L408

This would have to be compared with other implementations to find any discrepancies.
Alternatively, this could also be related to i2c library used.

I will try to look into it once I get some free time.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: joshchab on Sep 08, 2014, 05:34 pm
Hello,

I'm interested in using the MPU-6500 along with this library in my project. As far as hardware is concerned, is this all that's needed aside from the Arduino:

http://store.invensense.com/ProductDetail/EMSENSR6500-Embedded-Masters/495014/

They also have an evaluation board:

http://store.invensense.com/ProductDetail/MPU6500EVB-InvenSense-Inc/488434/

I wanted to make sure I get the correct board.

Thanks!
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Sep 11, 2014, 06:14 pm
Hi,

I'm unsure about the evaluation boards. What you need for this library is any of MPU6050, MPU6500, MPU9150 or MPU9250.
You can get it off ebay, sparkfun, etc.

Gregory
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Sep 11, 2014, 06:16 pm

Hi again !

I've tried that :
in function "mympu_open", with MPU_DEBUG activated, I have suppressed the line
"if (ret) return 10+ret;"

Then, the program ouputs that :
"Firmware compare failed addr 0
0 0 112 0 0 0 0 36 0 0
33 55 0 118 7 0 1 4 40 1 "

Probably an interesting information... but difficult to understand for me !

Regards,

Sylvain



Hi,

I believe I fixed the issue with MPU9250. Can you pull and update and re-try?

Thanks,
Gregory
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: apitaru on Sep 11, 2014, 09:54 pm
Hi, I've been having a similar issue with the 9250.

Thanks for attempting a fix! I've just tried the latest commit and it's still resulting in the same error notice. Let me know if there's any debugging I can help with.

And thanks for the great work - it works great with the 6050!

Amit
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: ddeard on Sep 19, 2014, 01:04 am
I can get the sketch to work with the 9250 now, but I had to do two things:

1. Had to add a line
#define MPU9250
in the file inv_mpu.h.
2. Had to use a Mega.  On an Uno, it still spews the error -1's.

Dan
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Sep 22, 2014, 03:45 pm
Dan,

If this works on one board but not on the other, this might be down to I2c library.

Can you try changing fastwire speed to 400 ?
https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/AvrCopter.ino#L8


If this does not help you can try to use ArduinoWire library instead of FastWire:
- comment line 53 and uncomment line 52:
https://github.com/rpicopter/ArduinoMotionSensorExample/blob/5c4bdf2aa464bdfcf903bc166afd3bb8752bf83d/I2Cdev.h#L52

- also the setup needs to change slightly in https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/AvrCopter.ino#L8
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: conrads1arduino on Oct 09, 2014, 05:16 am
Hi Greg,

I have debugged this issue on the 9250 a bit and it seems to be related to the programming the DMP firmware to the 9250 board.
I have logged the bytes written and bytes read back and when the issue happens it seems to be when the bytes read back does not match the bytes written. Furthermore, it seems that the bytes read back is always the same as the previous written buffer.
It seems the something in either the i2c state machine or the memory bank/write machine on the mpu gets stuck.
I have also added some retry mechanism to try to reprogram the bank if at first it failed. It improved a bit but it still not very stable.
Here is an output dump of the bytes written and read back
[font=courier]write mem 0 0 112 0 0 0 0 36 0 0 0 2 0 3 0 0
read mem 0 0 112 0 0 0 0 36 0 0 0 2 0 3 0 0
write mem 0 101 0 84 255 239 0 0 250 128 0 11 18 130 0 1
read mem 0 101 0 84 255 239 0 0 250 128 0 11 18 130 0 1
write mem 3 12 48 195 14 140 140 233 20 213 64 2 19 113 15 142
read mem 3 12 48 195 14 140 140 233 20 213 64 2 19 113 15 142
write mem 56 131 248 131 48 0 248 131 37 142 248 131 48 0 248 131
read mem 3 12 48 195 14 140 140 233 20 213 64 2 19 113 15 142
Firmware compare failed addr 48
write mem 56 131 248 131 48 0 248 131 37 142 248 131 48 0 248 131
read mem 3 12 48 195 14 140 140 233 20 213 64 2 19 113 15 142
Firmware compare failed addr 48
write mem 56 131 248 131 48 0 248 131 37 142 248 131 48 0 248 131
read mem 3 12 48 195 14 140 140 233 20 213 64 2 19 113 15 142
[/font]

Weirdly though if i use some of the other libraries available (for example the one from Jeff for the 9axis motion sensor) the DMP programming works fine and I do not run into the same issue)

I have ordered some 9150 devices now (which has the mpu6050 inside), to see if is exposes the same problem.
I like your library since it utilizes  the internal sensor fusion of the DMP if you use the quaternion outputs, but I need to correct for yaw drift now and that is why i want to move to either the 9150 or 9250 to be able to use the compass.

Cheers,
Conrad
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: Alexvc14 on Oct 09, 2014, 11:52 pm
Hi Gregory,

Great library, that is what I was looking for. Got it up and running on Nano + GY-521. And even connected it to famous teapot demo.

I have a few questions.

1. Why you produced your own version mpu.cpp? Can I use inv_mpu.cpp?
2.What should I do to change FSR from 2000 to 250 ? (as far as I understand it is much more than just simple #define FSR 250 in mpu.cpp)
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: Alexvc14 on Oct 11, 2014, 11:52 am
Here is what I found on Invensense forum.

Post Re: Wrong Quaternion angle with DMP at 500 DPS
This is a know bug on our end. 2000 DPS is the only full scale range the MotionDriver firmware currently supports for the gyroscope.

July 7th, 2014, 3:14 pm
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Oct 15, 2014, 11:33 pm

Hi Gregory,

Great library, that is what I was looking for. Got it up and running on Nano + GY-521. And even connected it to famous teapot demo.

I have a few questions.

1. Why you produced your own version mpu.cpp? Can I use inv_mpu.cpp?
2.What should I do to change FSR from 2000 to 250 ? (as far as I understand it is much more than just simple #define FSR 250 in mpu.cpp)


Hi,

The mpu.cpp is not a substitution of inv_mpu.cpp. It contains just a common initialisation code that in turn calls for inv_mpu functions.

You should be able to change FSR, just remember to update GYRO_SENS accordingly. See line 6 and 7 in mpu.cpp

Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Oct 15, 2014, 11:37 pm

Hi Greg,

I have debugged this issue on the 9250 a bit and it seems to be related to the programming the DMP firmware to the 9250 board.
I have logged the bytes written and bytes read back and when the issue happens it seems to be when the bytes read back does not match the bytes written. Furthermore, it seems that the bytes read back is always the same as the previous written buffer.
It seems the something in either the i2c state machine or the memory bank/write machine on the mpu gets stuck.
I have also added some retry mechanism to try to reprogram the bank if at first it failed. It improved a bit but it still not very stable.
[...]



Hi Conrad,

This really might be down to the i2c library used. Have you tried to use slower transmission speeds? See my previous posts for details.

I'm using myself 9150 on pro mini and this works flawlessly. But again, this might be different on other arduino models.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: Alexvc14 on Oct 16, 2014, 10:59 am
I dug deeper and found the answer on Invensense forum.
The answer to my question is NO. I cant do FSR_250 and use DMP.

http://www.invensense.com/developers/forum/viewtopic.php?f=3&t=1096&p=4631#p4631
"This is a know bug on our end. 2000 DPS is the only full scale range the MotionDriver firmware currently supports for the gyroscope."
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Oct 16, 2014, 02:24 pm
Well found! Thanks for sharing Alexvc14
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: theinlinaung2010 on Nov 05, 2014, 02:56 am
Hi,

I'm actualy trying to use your library but i've encountered some errors.

I first downloaded the .zip with all the files. I extracted it in my project folder and opened it in Arduino IDE. It didn'T build at first because of the #define i had to put in inv_mpu.cpp.

Once i've put my "#define MPU6050" i tried to build but got some more errors:

C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp: In static member function 'static int8_t I2Cdev::readBytes(uint8_t, uint8_t, uint8_t, uint8_t*, uint16_t)':
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp:276: error: 'BUFFER_LENGTH' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp:277: error: 'Wire' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp: In static member function 'static int8_t I2Cdev::readWords(uint8_t, uint8_t, uint8_t, uint16_t*, uint16_t)':
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp:414: error: 'BUFFER_LENGTH' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp:415: error: 'Wire' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp: In static member function 'static bool I2Cdev::writeBytes(uint8_t, uint8_t, uint8_t, uint8_t*)':
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp:598: error: 'Wire' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp: In static member function 'static bool I2Cdev::writeWords(uint8_t, uint8_t, uint8_t, uint16_t*)':
C:\Program Files (x86)\Arduino\libraries\I2Cdev\I2Cdev.cpp:653: error: 'Wire' was not declared in this scope

These are quite simple errors but i can't find the origine.

Wire is declared a bit higher in the code:

#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE

    #ifdef I2CDEV_IMPLEMENTATION_WARNINGS
        #warning Using I2CDEV_BUILTIN_NBWIRE implementation may adversely affect interrupt detection.
        #warning This I2Cdev implementation does not support:
        #warning - Repeated starts conditions
    #endif

    // NBWire implementation based heavily on code by Gene Knight <Gene@Telobot.com>
    // Originally posted on the Arduino forum at http://arduino.cc/forum/index.php/topic,70705.0.html
    // Originally offered to the i2cdevlib project at http://arduino.cc/forum/index.php/topic,68210.30.html
    TwoWire Wire;

#endif

At fisrt I tought that it was because it was in a if condition and the compiler just ignored it, but even if i put just after the if condition, the compiler says:

I2Cdev.cpp:90: error: 'TwoWire' does not name a type

I know for sure that all the code in the if condition is not executed because i wrote some random code and it didn't flaged it.

Once there, i don't realy know what else to do.
For the BUFFER_LENGTH error i can't find the problem either. This constant is used in other functions but the readBytes and readWords don't recognize the BUFFER_LENGTH.

Since i didn't wrote anything in the code, i trust that it should be working fine but it won't on my computer.

If you have anything to help me it would be realy awesome !

Thanks in advance,
Marvin.
I had the same problem as you. I renamed the original library "I2Cdev" in my libraries folder and it compiled fine.
But after the values show up on Serial monitor for about  5s, it froze. When I close and reopen Serial monitor, it shows the values and froze again after 5s. I don't know what's wrong.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: kitsooftlk on Jan 17, 2015, 06:37 pm
Hello,

I'm novice to this library. I'm looking for a way to detect acceleration also to determine the platform speed and acceleration. Is it possible to get using this library?

Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Jan 19, 2015, 10:31 am
I had the same problem as you. I renamed the original library "I2Cdev" in my libraries folder and it compiled fine.
But after the values show up on Serial monitor for about  5s, it froze. When I close and reopen Serial monitor, it shows the values and froze again after 5s. I don't know what's wrong.
Does it report something like 'READ ERROR' when it freezes? If it does, can you try to increase Serial speed to 115200: https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/AvrCopter.ino#L9

You could also try to decrese I2C speed on Line 8 to 200 to see if it helps.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Jan 19, 2015, 10:34 am
Hello,

I'm novice to this library. I'm looking for a way to detect acceleration also to determine the platform speed and acceleration. Is it possible to get using this library?


Platform speed is more complex than just measuring acceleration. Obviously you could derive some kind of velocity but from my experience it will not be accurate. Usually people couple more sensors to derive velocity like GPS and accelerometer or barometer and accelerometer.
However the library does not do anything like that.

Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: nmirod on Feb 02, 2015, 08:17 pm
For starters thanks for your library!

I have been trying to use your library to get data from an IMU connected to an arduino UNO. Moreover, the sketch on the arduino will work as an ROS node (don't know if you are familiar with ROS).
After some problems I was able to get the IMU to work and I was able to receive the IMU data published by the arduino. However I want to use the same arduino to control some motors using an H-bridge. When I implement the subscriber (basically a function that will get the controls from the computer and execute the necessary motor control) the IMU stopped working.

At that point the output of mympu_open() is zero, while the output of mympu_update() becomes "-1" and I'm unable to read the IMU.
Can you help me understand what might be going on?

Thanks in advance.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: borenis on Feb 15, 2015, 09:38 pm
Hi Gregory !

Fisrt, I'm sorry for my long silence, I've had urgent problems to solve and my MPU9250 was not my priority since september !
I yesterday downloaded your last version of avrcopter, and... It doesn' work :-(

I use an Arduino UNO, just like you.
When using I2C-scanner, I can find a device at I2C adress 0x68.

I do not use the makefile, but the ide compiler... Is that a problem ?
In your code, I've add  #define MPU9250 in inv_mpu.h, and  #define MPU_DEBUG in all .h

I get this :
MPU init: 3
Free mem: 208

I've searched were the error comes from.


It happens at the very beginning of the program, at the call of ret = mympu_open(200);

I've searched a bit more...
In mpu.cpp, function mympu_open(...), call to mpu_init(NULL) returns -7

Then, I've found that comes from inv_mpu.cpp, function mpu-read_mem, in wich
st->chip_cfg.sensors equal 0

Have you any Idea of the origin of the problem ?

Many thanks !

PS : have you tryed the MPU9250 ? If not, and if you are interested, I'd be happy to send you one on a breakout board ! ;-)


Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: borenis on Feb 20, 2015, 11:43 pm
Hi Dan ! Hi Greg !
Dan, you've said you have been able to run the code with an MPU9250 + Arduino MEGA ?
I've just tryed the same, but I'm unable to make it work :-(
I've been trying for months now, not every nights, but...
Would you tell me which code you used ? which libraries ?
I'm afraid there's just a little thing different and nothing works...
Tonight, I've tryed an i2c_scanner with the same arduino mega and MPU9250, with a windows 7 computer runing arduino 1.0.6, and with a windows 8.1 computer runing arduino 1.5.7.
In the first case, I get the address 0x68, and in the second case, I get 0x69 !?? Strange thing !
Would you give me your complete configuration so that I can do exactly the same ?
Thanks a lot for your help !
Sylvain

Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Mar 16, 2015, 11:52 pm
Hi Gregory !

Fisrt, I'm sorry for my long silence, I've had urgent problems to solve and my MPU9250 was not my priority since september !
I yesterday downloaded your last version of avrcopter, and... It doesn' work :-(

I use an Arduino UNO, just like you.
When using I2C-scanner, I can find a device at I2C adress 0x68.

I do not use the makefile, but the ide compiler... Is that a problem ?
In your code, I've add  #define MPU9250 in inv_mpu.h, and  #define MPU_DEBUG in all .h

I get this :
MPU init: 3
Free mem: 208

I've searched were the error comes from.


It happens at the very beginning of the program, at the call of ret = mympu_open(200);

I've searched a bit more...
In mpu.cpp, function mympu_open(...), call to mpu_init(NULL) returns -7

Then, I've found that comes from inv_mpu.cpp, function mpu-read_mem, in wich
st->chip_cfg.sensors equal 0

Have you any Idea of the origin of the problem ?

Many thanks !

PS : have you tryed the MPU9250 ? If not, and if you are interested, I'd be happy to send you one on a breakout board ! ;-)



Hi,

The key issue in here is mpu_init which returns -7.

the chip_cfg.sensors is correct to be 0 at this stage. It will change its value after mpu_set_sensor is called: https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/mpu.cpp#L36

As you rightly point out the value -7 comes due to an error on mpu_read_mem:
https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/inv_mpu.cpp#L720
What makes me think that the address (0x17) might not be correct. I do not have the datasheet in front but google tells me that there are devices with revision address of 0x16. Can you please try changing the address?

Thanks,
Gregory

P.S. Alternatively, you might want to just comment out/delete lines 720-729.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: cwhy on Mar 21, 2015, 04:00 pm
Hi,

I had the same issue with mpu_init returning -7 using MPU6500.
As you mentioned that the chip_cfg.sensors is correct to be 0 at this stage, but in mpu_read_mem it will directly return -1 before chip_cfg.sensors is set.

I tried to delete https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/inv_mpu.cpp#L2239, but it still return READ ERROR with error code -1.

I am new with Arduino and motion sensors. Thanks for your help!
CWhy
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Mar 25, 2015, 03:49 pm
Hi CWhy,

Can you try to call mpu_set_sensors before mpu_init: https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/mpu.cpp#L36

What does mpu_set_sensors return?

Thanks,
Gregory
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: cwhy on Mar 28, 2015, 01:23 pm
Hi CWhy,

Can you try to call mpu_set_sensors before mpu_init: https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/mpu.cpp#L36

What does mpu_set_sensors return?

Thanks,
Gregory
Hi Gregory,

Thanks for replying. It returns 0.

Regards,
CWhy
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: juraj5 on Apr 09, 2015, 09:28 pm
H
Hi CWhy,

Can you try to call mpu_set_sensors before mpu_init: https://github.com/rpicopter/ArduinoMotionSensorExample/blob/master/mpu.cpp#L36

What does mpu_set_sensors return?

Thanks,
Gregory
Hi! I have the same "problem". When I turn off debugging, though, it works. When it's turned on, I get the same issue: mpu_read_mem from address 0x17 fails. I've tried putting 0x16; then, it reads 127, or sometimes 0, and complains about the revision. I've disabled the check and then it works fine. Is that something important?
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: mugenIMU on Apr 12, 2015, 01:32 am
Hey guys,

I am getting some really large values:
Code: [Select]

flag=0, yaw=1113416067, pitch=-1037714598, roll=1113299994
flag=0, yaw=1113416553, pitch=-1037714800, roll=1113299207
flag=0, yaw=1113416335, pitch=-1037714964, roll=1113299377
flag=0, yaw=1113416579, pitch=-1037715221, roll=1113298567
flag=0, yaw=1113416122, pitch=-1037715394, roll=1113299198
flag=0, yaw=1113415981, pitch=-1037715258, roll=1113299644
flag=0, yaw=1113415786, pitch=-1037715344, roll=1113299659

But I can see they change according to the angles, and go back to the original value when they return to original position. What's wrong here, can anyone point me a direction? Thanks

Edit #1:
I was using long to store the output and it should be float. Now I need to figure out how to fix the drifting.

Edit #2:
Not just the problem with drifting. Values from three axis change at the same time from ypr[].
When the IMU is rotating around z axis, yaw, roll, pitch change at the same time like from 0 to 180. It's yaw for gyro that changes.
When the IMU is rotating around x axis, only roll changes as it's supposed to like from 0 to 90, and yaw and pitch goes +- 3 degrees. gyro pitch changes.
When the IMU is rotating around y axis and yaw changes from 0 to 90, pitch change by 30 and roll change by 50 degrees. For gyro[], it's pitch that changes.
What is wrong here?

Edit #3:
I found I was using DMP_FEATURE_LP_QUAT which should be DMP_FEATURE_6X_LP_QUAT. I guess the quaternion formula is for 6X mode only.

Edit #4:
Weird I am testing out the angles, when the IMU is rotated around the y axis in one way for 90 degrees, it gets about 90 degrees, but when it's rotated in the other direction for 90 degrees, it gets only to 60. Does anyone get this?
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: fish_men on Apr 28, 2015, 03:27 pm
Hi All
Any Luck to solve ''READ ERROR''?

Thanks
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: David C on May 13, 2015, 01:16 pm
Here's some observations from my own experiments.

1. My READ ERROR was an I2C thing. Probably because I'm on breadboard. Try:


Code: [Select]
Fastwire::setup(200,0);

in AvrCopter.ino L14. Worked for me.


2. Once it goes wrong, it will freeze without recovering. You can check this by adding something like:

Code: [Select]
case 2: err_o++; Serial.println(err_o); return;

at L47

It is possible to recover from some buffer overflow freezes by clearing the FIFO buffer. To do this, add the following line to mpu.h:

Code: [Select]
int mympu_clearfifo();


then change L47 to this:

Code: [Select]
case 2: err_o++; ret = mympu_clearfifo(); err_o++; Serial.println(err_o); return;



Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: fish_men on Sep 11, 2015, 03:28 pm
Hi
It works perfectly!
The only problem is: No matter what the  Serial.begin (Baud rate) is, It always serial.print with the same speed!  How can I increase the baud rate?!

Thanks
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: gregd72002 on Nov 17, 2015, 10:44 am
Hi, I do not see any reason why you shouldnt be able to increase the Serial speed. Sorry
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: Neluma on Dec 30, 2015, 12:57 pm
Hi
I tried to use your library with multiple sensors but it was not working. Is there any method.
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: ind3 on Jan 08, 2016, 03:44 am
Thank you for the library- very helpful!

I am pretty new to this and am hoping to use the EM MPU9250 breakout with my Arduino Uno, unfortunately I'm having an issue finding the device.  When I run the i2c scanner, I see the following:

I2C Scanner
Scanning...
No I2C devices found

I don't quite know how to address this problem and hope you might offer some insight.

Thank you
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: yerzhik on Jan 11, 2016, 10:53 am
Hello! Using AvrCopter project to run the arduino Uno with MPU 9150.
It runs ok. But for a few seconds only I get some results, after that I receive the following error:

Seems like the quaternion check fails. its out of range. and never comes to normal range. So

ret = mympu_update();

after few seconds starts returning 3.

Before there was an issue with firmware compare failure. Which I fixed by setting Fastwire speed from 400 to 200.

No trying to understand the nature of this error I saw the following comments:

* We can detect a corrupted FIFO by monitoring the quaternion data and
         * ensuring that the magnitude is always normalized to one. This
         * shouldn't happen in normal operation, but if an I2C error occurs,
         * the FIFO reads might become misaligned.
         *
         * Let's start by scaling down the quaternion data to avoid long long
         * math.
         */

How can I find out if there was a I2C error (if that was the cause)?
In any case how can I resolve the issue?
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: ThePuiu on Apr 20, 2017, 05:24 pm
Hi,
I'm trying to use this software with a MPU6500 that has the address 0x1c instead of 0x68. I tried to change the MPU6050.h file by changing everywhere I found 0x68 with the new value but no luck...
Result is:
Testing device connections...
MPU6050 connection failed
a/g:   67   -4965   -930   17388   -25604   24072
......



I'm new with arduino, can someone to help me? Thank you!
Title: Re: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c
Post by: SL06 on Jan 27, 2019, 10:06 pm
I could not get this sketch working with my MPU9255 chip at first. 

I have tried that slightly modified  sketch  and it worked :   https://github.com/moderndevice/MotionPlug

I went back to the avrcopter sketch and inexplicably it sudently it work.  I am scratching my head.

Be careful : long SDA and SLC cable (or poor connection)  an cause problem.  Use pull up resistor if you use 5V board - see Motionplug.ino  intro remarques for more info.