Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No need to wait after Wire.requestFrom() #4

Closed
Koepel opened this issue Jan 19, 2018 · 5 comments
Closed

No need to wait after Wire.requestFrom() #4

Koepel opened this issue Jan 19, 2018 · 5 comments

Comments

@Koepel
Copy link

Koepel commented Jan 19, 2018

In the file raPID/src/imu.cpp you can remove this line: while (Wire.available() < 6) {}. It is used twice.

The Wire.requestFrom() waits until the complete I2C transaction on the bus has finished. There is no need to wait for something after the call to Wire.requestFrom().
In case of a bus collision or an error that the Wire library could detect (it can not detect most problems), then the Wire.available() will probably return zero, and that loop will halt the sketch.

@barafael
Copy link
Owner

Thanks for spotting that! I will remove the line. Awesome!

@Koepel
Copy link
Author

Koepel commented Jan 19, 2018

Thanks. That was fast.

You use the I2Cdev code, which is using the Wire library in a wrong way ( jrowberg/i2cdevlib#265 ). That library is no longer maintained and the issues are piling up. The library is also a little outdated. Your copy of "init_mpu6050" is therefor also a little outdated. The FastWire option is not really needed and setting the TWBR for the speed is no longer needed, since there is a Wire.setClock() function now.

Changing the I2Cdev.cpp is risky. There is not much you or me can do about the library at Github. Keep in mind that the library is slower than needed, with extra unnecessary bus activity that slows it down. With the current version of the AVR Wire library the I2Cdev library works (despite the wrong use), so for now it is okay.

@barafael
Copy link
Owner

I guess it would be possible to use the i2c_t3 library in I2Cdev, however as you said it could be a lot of work.

I have sufficient power on my microcontroller to be able to do my own sensor fusion, so this library by Kris Winer is worth looking at for me.
In the long run, I want to use a different sensor anyway, as InvenSense has presented really good new options as recent as CES.

Thank you for pointing out the issues!

@Koepel
Copy link
Author

Koepel commented Jan 19, 2018

You might consider to upgrade to the MPU-9250 and try the Kris Winer AHRS fusion. Sometimes a MPU-6050 module is shipped with a smaller capacitor which causes extra noise. The MPU-9250 doesn't have that capacitor.

@barafael
Copy link
Owner

Ok, that sounds like it will improve the IMU quite a bit. I am wondering about the tradeoffs of using on-chip sensor fusion vs. doing it on the main board. I guess I will try both!

BTW, great job on helping all those other people use the Wire library correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants