Spark Logic

MPU-6050 (I2C) Library

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.

Replies

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 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 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.

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 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

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 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.

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 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.

RogerClark Fri Jul 17, 2015 10:33 am

Re; ‘HardwareSerial*’ in assignment
hardPort = &Serial;

Thats because USBSerial is not an instance of HardwareSerial

You’ll need to change RTIMULib, try changing the defintion of RTARDULINKHAL_PORT to USBSerial instead of HardwareSerial

Actually, both HardwareSerial and USBSerial are both inherited from the Stream class, so you could try changing the library file to specify the port as Stream rather than HardwareSerial, and it may work for both. Or possibly as an instance of Print

Actually, I’d need to download and look at the code, but basically find the code that is hard coded to use HardwareSerial and change it ;-)

bdbell Fri Jul 17, 2015 11:08 am

RogerClark wrote:You’ll need to change RTIMULib, try changing the defintion of RTARDULINKHAL_PORT to USBSerial instead of HardwareSerial

aster Mon May 01, 2017 1:40 pm

hello! so is this library working with stm32f103c8? could someone send me a working copy?

Fingolin Wed May 17, 2017 1:34 pm

Is this topic still active?
I am currentyl working on a prjoject with an quadrocopter, where I want to develop the flight controller etc all by myself.
Since the greater speed of and stm32 I switched to this board, however I am a bloody beginner.
But I made a MPU6050 library, that works for the arduino, which I am currently porting to the stm32103c8t.
The library is not yet working the same way as on the arduino, but I am looking foorward to share my results and get further inputs/tips/help whatever, since I am a beginner with stm32!

aster Fri May 19, 2017 1:37 pm

Fingolin wrote:Is this topic still active?
I am currentyl working on a prjoject with an quadrocopter, where I want to develop the flight controller etc all by myself.
Since the greater speed of and stm32 I switched to this board, however I am a bloody beginner.
But I made a MPU6050 library, that works for the arduino, which I am currently porting to the stm32103c8t.
The library is not yet working the same way as on the arduino, but I am looking foorward to share my results and get further inputs/tips/help whatever, since I am a beginner with stm32!

garindo Sun May 21, 2017 2:03 pm

Fingolin wrote:Is this topic still active?
I am currentyl working on a prjoject with an quadrocopter, where I want to develop the flight controller etc all by myself.
Since the greater speed of and stm32 I switched to this board, however I am a bloody beginner.
But I made a MPU6050 library, that works for the arduino, which I am currently porting to the stm32103c8t.
The library is not yet working the same way as on the arduino, but I am looking foorward to share my results and get further inputs/tips/help whatever, since I am a beginner with stm32!

garindo Sun May 21, 2017 2:45 pm

STM32F103RET6
Image

STM32F103C8T6
Image

Fingolin Sun May 21, 2017 2:47 pm

Hi Garindo,
I am working on a similar matter and would be very happy to share!
Currently I have auto-leveling working with arduino but I have trouble moving to the stm32 board.
If u want I can email you my code? (or post it here of course)

ag123 Sun May 21, 2017 3:04 pm

i’m not familar with drones, in terms of drones it seem there are lots of stm32f405 boards based drones
http://www.stm32duino.com/viewtopic.php?f=39&t=1977
http://www.ebay.com/sch/i.html?_odkw=dr … 4&_sacat=0
they seem to be the CC3D or betaflight variety
http://www.dronetrest.com/t/cc3d-flight … -guide/830
https://github.com/betaflight/betaflight
those drone specific boards often have the mems accelerometer / gyroscope on board, the pins also seemed to be geared towards drone/motor control purposes
those stm32f405 drone boards probably won’t make good generic dev boards as too few of the gpio pins are broken out but may likely be good drone boards
i think stm32f405 generally has a (whopping) 1M on chip flash

bdbell Mon May 22, 2017 3:43 pm

I have been a busy with other projects, but finally got a chance to look at this tonight. I am attaching both the original DMP6/Teapot sketch and the latest working RTIMULib and libraries for them. I am using these with a small BT 4.0 motion controller I designed using STM32, MPU9150/9250, and MS5611 altimeter/pressure sensor (the attached sketches output to data to USB, although I have them working using Serial2 to BT). I have been using MPU9250 lately, but have also tested both these in the past with MPU9150 – I don’t have MPU6050 to test but should be fine as they are both written for it also.

It’s been a while since I modified the RTIMULib to work with STM32, so I can’t remember exactly what I did, but if you compare the files in the libraries folder with the originals you can see there are small changes to 2 files in each library.

Please note that these are currently configured for MPU9250 on i2c address of 0x69 so you will need to change them to match your configuration.

Hope this helps!

garindo Mon May 22, 2017 11:44 pm

Hi, fingolin, for me there is no problem in sharing, I will clean my code and upload it, in arduino autolevel it works for me.

Sign in to reply