Mpu6050 direction for the OculusDiy

Hi Mats,

I'm very interested in the Mpu6050 service you've created.
Alessandro made a OculusDiy service using a Mpu6050, and an Android phone.  We made a "custom" MRLComm with "custom" messages many moons ago...  

I'm hoping to remove all the "custom" stuff.  And our new MRLComm will support the Mpu6050 as a generic I2C Device easily.

 
I've just add the Mpu6050 as a peer service to OculusDiy, but need some direction for setup & initialization. I assume the appropriate place for this code would be in the CoculusDiy.connect(port) after the Arduino connects ...
 
Just some general inquires to get it gowing...
Thanks !
 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Mats's picture

Mpu6050

Hi GroG

I looked in OclusDYI to understand wow it works today. It connects to the Arduino service and it's using a version of MRLComm that isn't available in MRL. My guess is that the MRLCommversion that Alessandruino uses is a combination of MRLComm and the MPU6050 library that was created by Jeff Rowberg.

https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050

The MPU6050 service is based on the same code. I "simply" converted it from C to Java. It took a while but was good time consumer when I was hospitalized earlier this spring. So it contains many methods to change parameters in the MPU that we probably never will use. But it also contains the important DMP code, that combines the 6 values from the Accelerometer/Gyro and turns into something useful. However I never finished the testing of the DMP code and the FIFO buffer. One reason was that I needed to understand the raw values and the data that the DMP returned. So to judge if the raw values were good enough for my purpose or not, I needed a GUI. I have been working with database and business logic for many years, but never worked on the GUI side. So I had to take several steps back. So my journey now has been to:

1. Learn how to make Swing GUI ( assuming that it was easier than Web GUI's ) by creating Swing GUI for Adafruit16CServoDriver, AdafruitIna219 and Mpu6050. All just very simple and ugly gui's. Very much copy/paste from other gui's.

2. Learn how to make WebGui's using Angular.js. Also a lot of copy paste, but to my surprise it wasn't that difficult, thanks to the very good templates that I could reuse.

3, Since I wanted a 3D gui for the Mpu6050, I also tried to learn a little bit of Three.js. So that's where I am now. This week was excitng because now I have a working Teapot demo in MRL. Only using the raw values from the Accelerometer, not the gyro or the DMP. 

Now back to answering your question.

I have to start with how the Mpu6050 connects. It is an i2c device that uses the methods defined in the I2CControl interface. So it can connect either thru an Arduino, RasPi or I2CMux service because all three implements the I2CControl interface. So Arduino should not be a peer in the OculusDIY service. The Mpu6050 can be a peer as long as it's the only Accelerometer/Gyro service avaliable in MRL, but I think that may change soon. A MPU-9255 is on it's way from Hong-Kong. It also has a magnotometer so that it can sense direction. 

So the start sequece would be to start a I2CControl service ( currently Arduino or RasPi ) outside from the OculusDIY. If you start the RasPi service, that's all that you need to do. If you start an Arduino service, it needs to ardino.connect(port).

The next step would be to start a Mpu6050 service.

Then the OculusDIY. has to tell the Mpu6050 what I2CController, bus and address it should use.

Mpu6050.setController(<Controller Name>,<Bus>,<Address>)

<Controller Name> is the name of the Arduino or Raspi service.

<Bus> is ignored by Arduino. Should be "1" for the RasPi service and "0" thru "8" if the I2CMux is used. I have to write some instructions on how to use the I2CMux ( https://learn.adafruit.com/adafruit-tca9548a-1-to-8-i2c-multiplexer-brea... ).

<Address> is the MPU6050 i2c address. It can be 0x68 or 0x69.

That's all there is to initialize.

To read the raw values use Mpu6050.refresh()

The really raw that the Mpu6050 returns are available as

public int accelX;
public int accelY;
public int accelZ;
public int temperature;
public int gyroX;
public int gyroY;
public int gyroZ;
 
They are also converted more understandable units of measure in
// Accel values converted to G
// Temperature converted to Celcius
// Gyro values converted degrees/s
public double accelGX = 0;
public double accelGY = 0;
public double accelGZ = 0;
public double temperatureC = 0;
public double gyroDegreeX = 0;
public double gyroDegreeY = 0;
public double gyroDegreeZ = 0;
 
It's possible to load the DMP using Mpu6050.dmpInitialize();
But as I wrote before, some more testing is needed before I can describe how to use it. If possible I will use the same data structure and just change the refresh() method to use FIFO data from the DMP when it has been initialized.
 
This is the Mpu6050 WebGui as it is today.