
To get started you need to follow these simple steps: Also, you might check out the “teapot demo” post from Debra at “Geek Mom Projects” that pointed me to the i2cdev library in the first place.
Imu arduino serial example code#
Here is where credit and a big thanks is due to Jeff Rowberg for his I2Cdev library and sample code for interfacing with the InvenSense MPU6050 chip and partially reverse-engineering the DMP functions. I opted for simplicity over safety, in my set-up and (so far) all is well. If you want to be absolutely safe, you could use a level shifter, voltage divider, or an inline 10k resistor to protect the MPU6050 I2C lines. I tested powering the chip both with 3.3V and 5V from the Arduino successfully, but in my final set-up opted for the 5V input.īased on what I have read online and what I saw on my tests, the 3.3V SDA / SCL lines of the IMU work fine connected directly to the corresponding Arduino 5V I2C pins. This is recommended, as due to the voltage drop-out of the regulator on the VCC line, using the Arduino 3.3V rail may not provide enough voltage. As you can see from the schematics above, the GY-521 breakout board has a built in low drop-out voltage regulator, so it is safe to power the chip through the Arduino 5V rail. The InvenSense MPU6050 chip is a 3.3V IC, with a working voltage range of 2.375V-3.46V, according to its datasheet. Hooking the MPU-6050 / GY-521 to an Arduino Uno MPU-6050 / GY-521 break-out board schematicsīelow is the schematic of the GY-521 break-out board for the MPU6050 chip. It can be instructed to place the sensor data in the buffer and the interrupt pin will tell the Arduino, when data is ready to be read. Lastly, the MPU-6050 has a FIFO buffer, together with a built-in interrupt signal.

Imu arduino serial example how to#
I have not found much detail on how to make the DMP use external magnetometer data yet, but fortunately that is not needed for my self-balancing robot at this point. The intention is for the IMU to read data from say, an external magnetometer (hooked up via those XDA / XCL pins you see on the breakout board) and send it to the DMP for processing. It even has a built in an additional I2C controller, that allows it to act as a master on a second I2C bus. The MPU-6050 communicates with a microcontroller through an I2C interface. You can still pull the raw, accelerometer and gyro data as well, disabling the DMP, if this works better for your application, or you want to apply your own filtering and sensor fusion algorithms. Nevertheless, smart and creative folks figured out how to use its main features, and were nice enough to share the results with the rest of us. The main downside is that it seems that the manufacturer did not provide much information on the proprietary inner workings of the DMP. The biggest advantage of the DMP is that it eliminates the need to perform complex and resource intensive calculations on the Arduino side. The DMP also has a built in auto-calibration function that definitely comes in handy, as we will see later.

These can then can be converted to yaw-pitch-roll, or to Euler angles for us humans to read and understand. The DMP on the MPU6050 does exactly that and returns the result in “quaternions”. By combining the data from the two types of sensors and using some math wizardry (a process referred to as sensor fusion), you apparently can get a much more accurate and robust estimate of the heading. Accelerometers and gyros have different inherent limitations, when used on their own.


The DMP combines the raw sensor data and performs some complex calculations onboard to minimize the errors in each sensor. Other features include a built in 16-bit analog to digital conversion on each channel and a proprietary Digital Motion Processor™ (DMP) unit. This makes it a “6 degrees of freedom inertial measurement unit” or 6DOF IMU, for short. So here it is documented for future reference! MPU-6050 OverviewĪccording to the InvenSense MPU-6050 datasheet, this chip contains a 3-axis gyroscope and a 3-axis accelerometer. Even too easy: it took me a while to sift through many partial, or “almost” working implementations before I found a relatively easy to use, clean and reliable set of instructions and Arduino sample code. The MPU-6050 breakout boards are quite popular in the Arduino community and information was easy to find. As with almost anything from eBay, it came with no documentation. Recently, I decided to finally get to building a self-balancing robot and dug it out. For a long time it sat quietly in my box of “possibly cool things to check in the future”. A while back I bought the InvenSense MPU-6050 sensor in a “GY-521” breakout board from eBay.
