Hi KinathThank you for the guide - it's the clearest one around for sure.I'm having issues at the Arduino code stage. I've uploaded Jeff's script to the Arduino Mega after checking that I am definitely receiving a variety of the Raw data from the mpu6050.
My friend and I have been working on a PCB. It contains an ATmega328P which is supposed to communicate with an MPU6050 via I2C. It also contains a circuit for charging a connected Li-Ion battery as well as a 3.7 to 3.3V converter. We are able to flash the ATmega and control the transistor connected to D8. Here is the code that I used to get the yaw, pitch and roll sensor data. It is based on the “Teapot” demonstration program which comes with the MPU-6050 Motion Apps library. Once again, you need to have the “MPU6050” and the “I2Cdev” libraries installed to use this code.
Unfortunately when I bring up the Serial Monitor after uploading Jeff's code I am just seeing:Initializing I2C devices.Testing device connections.MPU6050 connection successfulSend any character to begin DMP programming and demo.and then nothing. Also me moving the MPU itself is having no effect on thisThanks and I hope you can help!
In March, (mounted in a GY-521 breakout board). It seems that many people are using the MPU-6050, and I wanted to follow up with some more information, because there are better ways to access and process the combined sensor data than were demonstrated in that post. The previous experiment compared the raw data from the 3-axis accelerometer and 3-axis gyroscope sensors to the results when the raw data are combined via a complementary filter.For the comparison, I had adapted a program from the to pull the raw accelerometer and gyroscope data from the MPU-6050, The program calculated pitch, roll and yaw (rotation about the X, Y and Z axes, respectively, also knows as Euler Angles). These calculations were limited by certain properties of both the accelerometer and gyroscope. Gyroscope data has a tendency to drift with time, and accelerometer data is noisy and makes it difficult to calculate rotations over ranges greater than 180 degrees. The formulas(.) for computing roll, and pitch, (you can’t compute yaw, from accelerometer data) from the accelerometer readings are:The range of the function is, which determines the range of motion you can detect easily from the IMU using these functions. Additionally, using Euler angles for the rotation calculations can lead to a problem known as.
Because Euler angle rotations are performed in sequence (e.g, roll, pitch, and then yaw), problems arise when the second rotation in the sequence approaches 90 degrees ( ), because this brings first and third rotation axes into alignment with each other. This concept is tricky to explain, but the YouTube video below does quite a good job with it:One way to avoid the problems with Euler angles is to use an alternate method of representing rotation called. Quaternions describe rotation in three dimensions by using four scalar values.
Three of these scalars define an axis, and the fourth specifies a rotation around that axis. I won’t go into the mathematics of quaternions which is fairly complicated, and which I’m just starting to learn myself.
The salient points of quaternions are that they avoid the problem of gimbal lock and can represent rotations over ranges of greater than 180 degrees without difficulty. Additionally, they have some useful mathematical properties, such as allowing for straightforward interpolation between two quaternions, which can be useful in animation, and reducing round-off error when multiple rotation operations are performed in sequence. Using the DMP for Data ProcessingThe MPU6050 IMU contains a DMP (Digital Motion Processor) which fuses the accelerometer and gyroscope data together to minimize the effects of errors inherent in each sensor. The DMP computes the results in terms of quaternions, and can convert the results to Euler angles and perform other computations with the data as well. Invensense will not reveal the algorithm that they use to combine the data, but I was curious to see how the results the DMP produces compare to those I had computed with a.Therefore the next step was to figure out how to extract data from the DMP. Fortunately, Jeff Rowberg has written and made public a very useful library, i2cdevlib, which does just that.
It is available for download at:. To use it with the MPU 6050, you will need the library functions in the folder labeled Arduino/MPU6050. To install the library, simply copy the Arduino/MPU6050 folder to the same location as your other Arduino libraries.I used an Arduino Nano and GY-521 breakout board containing the MPU-6050 to run the demos.
This setup requires the following connections: (ArduinoGY-521) 5 connections are required between the MPU-6050 and Arduino when using i2cdevlib. 5VVCC (the GY-521 contains a voltage regulator and can use 3.3V or 5V). GNDGND.
A5SCL. A4SDA. Arduino Pin 2INT (used for interrupts)The Teapot DemoThe MPU6050 library contains a folder called “Examples”, with a demo called. Inside that folder are an Arduino sketch, to read quaternion data from the DMP and send it over the serial port, and a Processing sketch, to read the data from the serial port and display the rotations graphically.The demo ran more or less right out of the box, with a few tweaks. The only change I made to the Arduino sketch was to reduce the Serial port communication rate from 115200 to 38400 (This is set on line 163 of the sketch). The 115200 rate seemed to overwhelm the Nano, but the 38400 rate worked well.The Processing sketch is called MPUTeapot.pde, even though the figure it displays is a 3-D arrow, not a teapot. I assume that earlier versions of this sketch showed a teapot.
I’ve seen some working demos with the teapot version online, e.g. This YouTube video:If you are going to run this example, make sure you use the 32-bit version of Processing, since last I checked, it is the only version that works with serial communications.To get the Processing sketch working, I had to make the following changes:. Changed the Serial port data rate to 38400 to match the Arduino rate. I also specified which serial port to read the data from. The data, which comes across the Serial port in 14 byte packets was not getting properly aligned. Each 14-byte packet starts with the ‘$’ character, so I modified the program to ignore all bytes read before the first ‘$’.
The Processing sketch sends a character over the serial port to the Arduino to tell it to begin sending data. I found that the sketch was hanging here, so I had the Processing sketch send over a couple of additional characters for good measure. It seemed to fix the problem. You can download my slightly modified version of the Processing sketch here. Below is a video demonstration of the “teapot” demo sketches.
The 3-D airplane/arrow in the Processing sketch follows the rotation of the IMU without significant jitter or lag. In addition, the demo easily performs rotations of any angle, even those greater than 180 degrees. What was also interesting is that for the first few seconds, the figure shows significant yaw drift, but after about 8 seconds of keeping the IMU motionless, the drift stops.
I presume the DMP performs some sort of calibration to correct for the yaw drift. The complementary filter I had used in my previous post was able to correct for gyroscope drift in pitch and roll by combining accelerometer and gyroscope data on these axes, but since accelerometers don’t provide yaw, it was not able to correct for the yaw drift. I think that, unless you have good calibration and data fusion algorithms, there is a significant advantage to using the DMP calculated data.I am working on a side-by-side comparison of DMP data vs. The complementary filter discussed in my, and hope to be writing it up soon.(.) As an unrelated aside, I’ve just discovered the use of LaTeX for formatting equations within WordPress, and I’m having a lot of fun with it.
How much is the yaw drift of the MPU-6050 DMP output (during your experiments)?I’m looking for a gyro that has a minimal yaw drift, currently I’m using a L3G4200D and it has a yaw drift of 1-2 degree per minute. Of course, I’m using calibration. I cannot use a compass, because there are large motors in this small robot, and there’s no chance to measure anything else magnetic for a compass than the motorsSo how large is the yaw drift in the MPU-6050 (degress per minute) compared to by L3G4200D (1-2 degree yaw drift per second) – Thanks ?.
“This post talks about where to put the toxi libraries. Hopefully it will help:”Thanks for your fast respons, the link above helped me to put the libraries in the correct folder.So when running Processing and the Teapotdemo I get a nice graph of the Arrow.But it is frozen.I believe that the Communication between the Arduino UNO R3 and the MPU6050 is working. From the ArduinoIDE I can see that the program is waiting for a character to be sent.And when I send a character from the Serial Monitor, I can read output from the MPU on the Serial Monitor. Hi everybody,I just implemented the DMP portion of the i2c dev library in a piece of Software on my Beaglebone to use the DMP of the MPU6050.
I am especially interestet in pitch and roll values. The values calculated via the function dmpGetYawPitchRoll are not very stable. A slight movement results in overshots in pos/neg. After a while of leaving the sensor static at the rached angle settles the value, but as soon as I move the sensor the values jump around again until I keep the sensor static and then they settle based on the actually reached position.
I also tried to calculate pitch and roll (and yaw) from the quaternions directly, but with the same result.pIMU-getFIFOBytes(fifoBuffer, packetSize);pIMU-dmpGetQuaternion(&q, fifoBuffer);pIMU-dmpGetGravity(&gravity, &q);pIMU-dmpGetYawPitchRoll(ypr, &q, &gravity);qroll = atan2(2.0.(q.y.q.z + q.w.q.x), q.w.q.w – q.x.q.x – q.y.q.y + q.z.q.z);qpitch = -1.0. asin(-2.0.(q.x.q.z – q.w.q.y));qyaw = atan2(2.0.(q.x.q.y + q.w.q.z), q.w.q.w + q.x.q.x – q.y.q.y – q.z.q.z);Whenever I move the sensor it is very very sensitive to changes. Move the sensor from horizontal postion slightly up to an angle of 45° pitch (3-4 seconds to reach the angle). I get overshoots to +80° and -60°. After approx 2-3 seconds the value settles to the expected 45°.Previously I used the raw acc/gyro values provided via the i2c library and applied either a kalman or complementary filter to get pitch and roll and I thought when using the DMP I get better values due to the IMU internal fusion of data, but the raw-method looks still better (even that it does not yet satisfy me for the application I am working with, where I have a moving and acclerating object and want to measure pitch and roll independent of the object acceleration).
Am I missing something in regard to the used of the DMP? I followed 1:1 the (6 axis-)demo in regard how to set up the IMU and how to read the FIFO (in a 10ms loop in my software). The sampling rate of the DMP is set to 200/(1+9)Hz = 20Hz (DMPFIFORATE = 0).I appreciate any feedback on this! Thanks a lot in advance!Regards,Tom. Hi Admin,I tried the link from your reply and the instructions in it did not work. The link is a little more than 3 years old and likely applied to an older version of processing. In processing 2.1.1 there is no such sub folder as libraries so I created one and added the toxi libraries to it.
Opened a new sketch in processing and selected the sketch tab- import libraries and toxi was not there and in import libraries-add library toxi does not show up in the library manager.So when running the MPUTeapot sketch the following error occurs:No library found for toxi.geomNo library found for toxi.processingLibraries must be installed in a folder named ‘libraries’ inside the ‘sketchbook’ folder.and I added a libraries folder containing the toxi libraries to the MPUTeapot sketch and get the same error. I created a new sketch that contained “import toxi.geom.;” only as a single line and it came back with ” No library found for toxi.geom” changing the line to “import processing.serial.;” did not create any error.
The problem has to be the inability for processing 2.1.1 to recoginize and use the toxi libraries.I also read the note and followed the instructions that came with MPUTeapot as follows:// NOTE: requires ToxicLibs to be installed in order to run properly.// 1. Download from// 2. Extract into userdir/Processing/libraries// (location may be different on Mac/Linux)// 3. Run and bask in awesomenessand was unable to “bask in the awesomeness”.I will try an older version processing (if one is available) and if not then I have spent about as much time on this example as I can endure. Hi Admin,I tried 1.5.1 and 2.03 with the same results.
I opened a blank sketch, selected sketch-import library-add library which opened Library Manager and I installed a library Ani from it. Then did a search for Ani and found it in a My documents/Processing/libraries which I had not seen before.
So the Library Manager created this folder and I unzipped toxiclibs-complete-0020 into it. Opened a new sketch an in it opened selected sketch-import library and found toxi libraries and was able to import them. Created MPUTeapot folder in this Processing folder and was able to get things to run.So for anyone having a problem with “processing” create a folder in their user directory named Processing and a sub folder in Processing named libraries and extract the toxiclibs-complete-0020.zip downloaded file to it. Then MPUTeapot should run fine (be sure to close the Arduino serial monitor after entering a character).
I am using a MEGA 2560 and when I run the code on Processing I get this:WARNING: RXTX Version mismatchJar version = RXTX-2.2pre1native lib Version = RXTX-2.2pre2I can see the plane, but as I move the GY-521 the plane stands still – it doesn’t move at all. Do you have any idea why is that?And one more question. I want to get only raw values out of the MPU6050 code without using the processing sketch, I am a newbie at Arduino and I am not sure how to change the code to get only values?.
I know about this code by Krodal, but from what I understand it doesn’t use the DMP engine which is the case with the MPU6050DMP6. I need the accuracy and stability of the values given by the MPU6050DMP6 code. I am trying to cut the Processing part of the code but I get “FIFO overflow” as the serial monitor displays values as I tilt the MPU6050. What I did was just putting this part as a comment which asks for a character to be sent by the Processing Teapot code so that the DMP would start working:“// wait for ready//Serial.println(F(“nSend any character to begin DMP programming and demo: “));//while (Serial.available && Serial.read); // empty buffer//while (!Serial.available); // wait for data//while (Serial.available && Serial.read); // empty buffer again”This is the only thing I change from the code and when I open the serial monitor it doesn’t wait to receive a character and proceeds to values generation. But when it does it gives out the following, and I am not sure if it is a problem or not:Initializing I2C devicesTesting device connectionsMPU6050 connection successfulInitializing DMPEnabling DMPEnabling interrupt detection (Arduino external interrupt 0)DMP ready! Waiting for first interruptquat1.000.01-0.02-0.00FIFO overflow!quat1.000.04-0.02-0.01FIFO overflow!quat1.000.05-0.01-0.02FIFO overflow!quat1.000.06-0.01-0.04FIFO overflow!quat1.000.07-0.01-0.05FIFO overflow!quat1.000.07-0.01-0.06FIFO overflow!quat0.990.07-0.01-0.07FIFO overflow!quat0.990.07-0.01-0.08I just want the MPU6050DMP6 code without the Processing part.