# I2C MPU-6050

I am using an accelerometer in my most recent device to capture gesture and orientation information, as the device itself has no traditional user interface. Since the device is running a node.js app to capture data and push it to a cloud service the first prototype required a quick solution to getting data from an MPU.

To capture data I am using a few node modules. In particular the @@html:@@cylon.js@@html:@@ module, along with the @@html:@@cylon-i2c@@html:@@ module. This allows accelerometer data to be easily used by the following code block

    Cylon
.robot()
.connection("edison", { adaptor: "intel-iot", i2cPort: 1})
.device("accel", { driver: "mpu6050" })
setInterval(function() {
bot.accel.getAcceleration(function(err, data) {
//use data
});
});
});


## Connecting the MPU

For the first prototype I am using SparkFun Edison blocks, as I have a a few sets of these interchangeable blocks that are quick to assemble into a prototype. In this case I am using the SparkFun I2C block with an Edison. This block allows the Edison to be snapped onto the block, and the MPU-6050 board to be connected with 4 jumpers (VCC, GND, SDA, SCL).

Most MPU-6050 boards will have an I2C address of 0x68, but if you choose a different MPU and it isn't working with Cylon, the first thing to check will be whether the address is 0x68. The error message from Cylon will be a "RangeError: Trying to access beyond buffer length" for most errors where the MPU is not connected properly. To check the address use the following command when the MPU is connected via I2C.

    i2cdetect -y -r 1


The result will look something like:

         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --


You will see either a 68 or a 69 if the MPU-6050 is connected properly. If the address displayed is 69, you will need to change the address to 68 using the technique recommended for your board (AD0 jumper). You may see other numbers in the results if you have other I2C components included in your assembled device, but if you are using an MPU-6050 and it is connected correctly either a 68 or a 69 should appear in the i2cdetect results.

I won't get into calibration or gesture recognition in this post, but will try to post more on MPU calibration, gesture recognition, etc in future posts. Given not all MPU-6050 breakouts work with the Edison because of their compatibility with 5V Arduino boards I wanted to post the notes of my experience with a few of them.