Go Down

Topic: MPU6050/MPU6500/MPU9150/MPU9250 library over I2c (Read 15407 times) previous topic - next topic

gregd72002

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.

gregd72002

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.


nmirod

#32
Feb 02, 2015, 08:17 pm Last Edit: Feb 02, 2015, 08:28 pm by nmirod
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.

borenis

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 ! ;-)



borenis

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


gregd72002

#35
Mar 16, 2015, 11:52 pm Last Edit: Mar 16, 2015, 11:55 pm by gregd72002
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.

cwhy

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

gregd72002

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

cwhy

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

juraj5

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?

mugenIMU

#40
Apr 12, 2015, 01:32 am Last Edit: Apr 15, 2015, 05:31 am by mugenIMU
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?

fish_men

Hi All
Any Luck to solve ''READ ERROR''?

Thanks

David C

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;




Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy