MPU-6050 (I2C) Library

Can someone help me port this library?
juanpintom
Posts: 6
Joined: Tue Jun 16, 2015 7:35 pm

MPU-6050 (I2C) Library

Post by juanpintom » Tue Jun 23, 2015 11:04 pm

Hi all, Im trying to get it working an MPU6050 on Maple Mini, I started with this library:
https://github.com/jrowberg/i2cdevlib/t ... no/MPU6050

On Arduino the INT pin is connected on D2 (interrupt #0), but I don't know what pin is on Maple Mini I tried with pin 2 and pin 0.
I readed this reference: http://leaflabs.com/docs/external-inter ... light=exti thats why I tried with pin 0.

I worked with no problems using DMP6 example on Arduino.

On MapleMini the i2c device is detected but gives an error on DMP start (code 1) from this line on setup()
https://github.com/jrowberg/i2cdevlib/b ... 6.ino#L228

I dont know if this can be related with this issue:
https://github.com/rogerclarkmelbourne/ ... 2/issues/5

I tried with RAW example and get strange values, I need to get a G force acceleration.

I'll do more tests tomorrow, anyone have this sensor working?

Really thanks.

Regards.

User avatar
RogerClark
Posts: 7538
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: MPU-6050 (I2C) Library

Post by RogerClark » Fri Jul 03, 2015 1:58 am

I looked at the MPU9150 some time ago, but I recall there being issues even on AVR.

I was using the RTImuLib, but it seemed to use a special version of i2cdev, and when I used the normal version of I2Cdev RTImuLib would not work :-(

If you are planning on using the MPU for anything useful, I'd advise that you look at using the RTImuLib as it handles all the complex maths that are needed to make use of the MPU's (there is lots of complicated maths)

https://github.com/RTIMULib/RTIMULib-Arduino

However I think Richard has given up all support for it on Arduino's and even stopped supporting Teensy and now just uses RPI.

Incidentially, using an MPU was why I initially looked at using the STM32, as I found that the AVR Arduino was too slow and the single precision maths (even if you use the double data type), was not accurate to make the MPU's usable.

However I have ended up spending all my time supporting different aspects of the STM32 and hosting the repo etc

juanpintom
Posts: 6
Joined: Tue Jun 16, 2015 7:35 pm

Re: MPU-6050 (I2C) Library

Post by juanpintom » Mon Jul 13, 2015 6:29 pm

Sorry for the late response! :( I forget to enable notifications :S

Im still working on it, my idea is to make a G sensor with the MPU6050.

Ill take a look to RTIMULib-Arduino

Really thanks for your work!, and thank you for share!

bdbell
Posts: 20
Joined: Tue Apr 28, 2015 7:35 am

Re: MPU-6050 (I2C) Library

Post by bdbell » Thu Jul 16, 2015 1:42 pm

I have a MPU9150 working with maple mini - both of the attached sketches work for me. The DMP6 sketch is configured for the Teapot demo, which worked well - actually left it running on my desk all afternoon and it worked great.

The MPU6150 should work as well for both sketches, although you may have to modify the MPU9150_RAW file to get it to work for MPU6150.

I initially had a problem getting it to work because the programming adapter setup I was using to test the MPU9150 did not have AD0 tied low so the i2c address was 0x69 instead of 0x68 the sketches are set to. I have INT connected to pin 0 and the LED is flashing.
Attachments
MPU6050_DMP6_STM.zip
(55.65 KiB) Downloaded 670 times
MPU9150_RAW.zip
(52.2 KiB) Downloaded 256 times

juanpintom
Posts: 6
Joined: Tue Jun 16, 2015 7:35 pm

Re: MPU-6050 (I2C) Library

Post by juanpintom » Thu Jul 16, 2015 2:05 pm

You're awesome! Ty so much! I'll try this night and let you know !

Regards!

juanpintom
Posts: 6
Joined: Tue Jun 16, 2015 7:35 pm

Re: MPU-6050 (I2C) Library

Post by juanpintom » Thu Jul 16, 2015 11:25 pm

With the DMP6 example I get the same (code 1) error :( I tested RAW example and works well, but I don't know how I can get G force from this values.
I'll do more test tomorrow.

Ty Again :P

Regards

User avatar
RogerClark
Posts: 7538
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: MPU-6050 (I2C) Library

Post by RogerClark » Thu Jul 16, 2015 11:31 pm

Guys,

Unless you just need very basic data from these devices, you will almost certainly need to use RTIMU.

Well, unless you have a degree in mathematics that is.

I have looked into this field and it was well beyond any maths that I did at school up to Year 12, and we didn't cover the maths of this sort of stuff on my degree course.

So.. Unless you are familiar with coding Kalman filters and working with quaterions, I think you are going to be doomed to failure trying to code this yourselves.

bdbell
Posts: 20
Joined: Tue Apr 28, 2015 7:35 am

Re: MPU-6050 (I2C) Library

Post by bdbell » Fri Jul 17, 2015 3:47 am

juanpintom wrote:With the DMP6 example I get the same (code 1) error :( I tested RAW example and works well, but I don't know how I can get G force from this values.
Did you try running an i2cscanner sketch to make sure the MPU6150 is set to the proper i2c address (that is how I discovered the problem).
RogerClark wrote: So.. Unless you are familiar with coding Kalman filters and working with quaterions, I think you are going to be doomed to failure trying to code this yourselves.
Yes, the math is way beyond me too - no intention of trying to deal with that part of the programming! I find the DMP sketch I attached can be configured to output quaternion, euler, yaw/pitch/roll, and real or world acceleration data. I have been using it for quite a while with an Arduino (32U4) based IMU I designed with MPU9150, MS5611 Pressure sensor and Bluetooth - I am planning on using STM32 MCU for the next version.

Thanks for the RTIMU link Roger! Surprised I did not come upon it before. The main repository is gone now so your link does not work - I found 15 repositories here;

https://github.com/search?utf8=%E2%9C%93&q=rtimu

this is a copy of the original missing repository (it has the source for the Windows Host);

https://github.com/sailoog/RTIMULib

and this one seems to be the most recently updated Arduino one;

https://github.com/richards-tech/RTIMULib-Arduino

all of the sketches compile and work for me under Arduino. They all also work on Maple Mini - except RTArduLinkIMU which is needed for communication with the Windows Host - gives me the following error which I am not sure how to solve yet;

Code: Select all

D:\My Documents\Arduino\libraries\RTArduLink\RTArduLinkHAL.cpp: In function 'bool RTArduLinkHALAddHardwarePort(RTARDULINKHAL_PORT*, long int, unsigned char)':
D:\My Documents\Arduino\libraries\RTArduLink\RTArduLinkHAL.cpp:86:22: error: cannot convert 'USBSerial*' to 'HardwareSerial*' in assignment
             hardPort = &Serial;
                      ^
Error compiling.

User avatar
RogerClark
Posts: 7538
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: MPU-6050 (I2C) Library

Post by RogerClark » Fri Jul 17, 2015 5:11 am

@bdbell

I recall having some initial issues because the RTImuLib used some strange version non-standard version of i2dev, but perhaps its fixed now.

I did some work on AVR using the lib about 9 months ago, but found that the normal floating point precision on the AVR was too low and using double on STM32 would be better,

Also the more samples per second you can get from the IMU device the greater the accuracy when integrating acceleration into velocity etc.
Hence the STM32 would be better for this than AVR, but I suspect you'd need to change some settings in RTImu to tell the IMU device to sample faster

I'd really like to get back to looking at this, as I have some IMU9150s and also bought some 9250's which are suppose to be more precise, but they are still in their anti static packets ;-(

bdbell
Posts: 20
Joined: Tue Apr 28, 2015 7:35 am

Re: MPU-6050 (I2C) Library

Post by bdbell » Fri Jul 17, 2015 10:19 am

@RogerClark

There was a copy of i2cdev in the libraries folder included with the RTIMULib-Arduino download but I did not use it - just used the same one I always use.

There are settings in "RTIMUSettings.cpp" for MPU9150GyroAccelSampleRate and MPU9150CompassSampleRate - the defaults were 50/25. I tested with my Arduino based IMU's (running 2.7v @ 8MHz) - max sample rate I can get is ~64. With Maple mini I can get ~330 :D - will need to do more playing around with it to see what works best, but definitely looking good!

Please let me know if you have a chance to look at it and figure out the USBSerial error I am getting from the RTArduLinkIMU sketch.

Post Reply