0% found this document useful (0 votes)
769 views45 pages

Gyroscopes and Accelerometers On A Chip - Geek Mom Projects

Gyroscopes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
769 views45 pages

Gyroscopes and Accelerometers On A Chip - Geek Mom Projects

Gyroscopes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

Geek Mom Projects


Techie ideas to do with (or without) kids!

Search:

About
Contact
Links

Gyroscopes and Accelerometers on a Chip


31. March 2013 183 comments Categories: Angular Momentum, Arduino, Gyroscopes, Processing

The interior of a 3-D MEMS Gyroscope Sensor


is intricate and tiny (this structure is only about
0.08 cm wide).

My last two blog entries discussed demonstrations of gyroscopes and angular momentum conservation at our schools science fair. One of the demonstrations I put
together takes a look at how really small gyroscopic sensors, such as those in many smart phones, video game remotes or quad-copters provide information about
their changing orientations. This information can be used as feedback for self-balancing (e.g. a two-wheeled scooter), navigation or as input to other applications
like video games.

I didnt want to sacrifice my smart phone for this experiment. Fortunately, chips containing gyroscopic sensors are relatively cheap. In reading up on gyroscopic
chips, I found that orientation data from gyroscope sensors is prone to drift significantly over time, so gyroscopic sensors are frequently combined with additional
sensors, such as accelerometers or magnetometers to correct for this effect. This combination of sensors is frequently referred to as an IMU, or Inertial
Measurement Unit, and it is used in airplanes, spacecraft, GPS navigators (for use when GPS signals are unavailable) and other devices. The number of of sensor
inputs in an IMU are referred to as DOF (Degrees of Freedom), so a chip with a 3-axis gyroscope and a 3-axis accelerometer would be a 6-DOF IMU.

The GY-521 breakout


board contains a 3-axis
accelerometer and a
3-axis gyroscope in the
tiny MPU-6050 chip in
the center.

The MPU-6050 is a commonly used chip that combines a MEMS gyroscope and a MEMS accelerometer and uses a standard I2C bus for data transmission. More

1 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

importantly to me, someone else has already done the hard work of reverse-engineering the MPU-6050 and provided freely available source code to use an
Arduino microcontroller to retrieve the MPU-6050 data. There are a number different breakout boards available containing the MPU-6050 chip. You can find an
overview of many of them on this page, under the heading Breakout Boards. I ordered the GY-521 module from Amazon.

There is a sophisticated library named I2Cdevlib for accessing the MPU-6050 and other I2C devices written by Jeff Rowberg. The specific code is provided in the
sub-folder MPU6050. It utilizes a hardware buffer on the chip and Digital Motion Processing capabilities of the MPU-6050 to perform data conversions between
different coordinate systems and combines data from multiple sensors to obtain greater accuracy and precision. Another useful library called FreeIMU, written by
Fabio Varesano, is specifically geared towards calculating orientation from multiple-sensor IMUs, and can perform sophisticated data processing as well. FreeIMU
makes use of the I2Cdevlib, but I found that the latest I2Cdevlib included with FreeIMU conflicted with the Rowbergs version of I2Cdevlib, so be sure to use the
correct version of I2Cdevlib if you use one of these libraries.

I was looking for a quick and dirty demo for our science fair, so I adapted the short code, by an author Krodal, at the bottom of this page to read the raw data
from the MPU-6050 and do simple (hah!) calculations of rotation angles myself. After going back to re-try my experiment with the libraries mentioned previously,
I realized that it would have been much easier and more accurate to use one of the pre-written libraries instead. I did, however, learn a great deal in the process of
converting the raw sensor data to rotation angles, so it was worthwhile to do it the hard way.

The GY-521 connected to an Arduino UNO.


Additional connections are needed if using the
I2Clib and FreeIMU libraries.

To set up the hardware, I soldered header pins to the GY-521, and connected it to an Arduino UNO via a tiny bread board. The wiring was trivial only four
jumper cables were needed. For power connect GNDGND and VCC3.3V (the GY-521 board has a voltage regulator, and can take either 5V or 3.3V). Only
two pins were needed to transmit data on the I2C bus: SDA (data)A4 and SCL (clock)A5.

Getting the raw data was easy. Krodals code worked immediately, and, generated output as shown below. A harder trick is to convert these raw numbers into
meaningful data.
InvenSense MPU-6050
June 2012
WHO_AM_I : 68, error = 0
PWR_MGMT_2 : 0, error = 0

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -276, -200, 14556
temperature: 27.141 degrees Celsius
gyro x,y,z : -5, -21, 53,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -280, -108, 14468
temperature: 27.282 degrees Celsius
gyro x,y,z : -16, 15, 73,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -296, -244, 14456
temperature: 27.282 degrees Celsius
gyro x,y,z : -5, -8, 46,

MPU-6050
Read accel, temp and gyro, error = 0
accel x,y,z: -288, -232, 14516
temperature: 27.235 degrees Celsius
gyro x,y,z : -3, -6, 49,
...

I modified Krodals code to start with a calibration routine that averages the first 10 readings to compute the default sensor offsets. The offsets get subtracted from
the raw sensor values before the values are converted to angles.

Now the task was figuring out how to compute the rotation angles. This can get quite complicated. Theres a pretty good writeup of the mathematics involved
here. For the GY-521 oriented flat as shown, the X and Y axes lie in the horizontal plane and the Z axis is vertical.

To compute orientation from the accelerometer, we rely on the fact that there is a constant gravitational pull of 1g (9.8 m/s^2) downwards. If no additional forces

2 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

are acting on the accelerometer (a risky assumption, as well see later), the magnitude of the acceleration detected will always measure 1g, and the sensors rotation
can be computed from the apparent position of the acceleration vector, as seen below. If the Z-axis is aligned along the gravitational acceleration vector, then it is
impossible to compute rotation around the Z-axis from the accelerometer.

This diagram shows calculations of tilt angles


from the measured acceleration vectors.
Diagram comes from this site. and are
defined as tilt with respect to the X- and Y-axes
respectively, while is defined with as tilt of
the Z-axis with respect to gravity. Please note
that while and are the same as pitch and
roll, is NOT the same as Yaw. Yaw cannot be
computed from the accelerometer.

According to the MPU-6050 datasheet, page 13, you can convert the raw accelerometer data from Krodals code into multiples of g (9.8 m/s^2) by dividing by a
factor of 16384. However, since the conversion to angles uses ratios of the acceleration vector components, this factor divides out. I computed rotation around the
X-axis () and Y-axis (-) using the formulas in the image to the left. Interpreting the diagram at left is a little tricky, since the tilt of the X-axis actually shows
rotation around the Y-axis, and the angling of the Y-axis shows (negative) rotation around the X-axis.

It is important to note that the accelerometer results provide accurate orientation angles as long as gravity is the only force acting on the sensor. However, when
moving and rotating the sensor, we are applying forces to it, which causes the measurements to fluctuate. The net result is that accelerometer data tends to be very
noisy, with brief but significant perturbations. If these can be averaged out, the accelerometer provides accurate results over timescales longer than the
perturbations.

Computing orientation from the gyroscope sensor is different, since the gyroscope measures angular velocity (the rate of change in orientation angle), not angular
orientation itself. To compute the orientation, we must first initialize the sensor position with a known value (possibly from the accelerometer), then measure the
angular velocity () around the X, Y and Z axes at measured intervals (t). Then t = change in angle. The new orientation angle will be the original angle
plus this change. The problem with this approach is that we are integrating - adding up many small computed intervals to find orientation. Repeatedly adding up
increments of t will result in small systematic errors becoming magnified over time. This is the cause of gyroscopic drift, and over long timescales the
gyroscope data will become increasingly inaccurate.

The MPU-6050 datasheet shows that dividing the raw gyroscope values by 131 gives angular velocity in degrees per second, which multiplied by the time between
sensor readings, gives the change in angular position. If we save the previous angular position, we simply add the computed change each time to find the new
value.

As explained above, both the accelerometer and gyroscope data are prone to systematic errors. The accelerometer provides accurate data over the long term, but is
noisy in the short term. The gyroscope provides accurate data about changing orientation in the short term, but the necessary integration causes the results to drift
over longer time scales.

The solution to these problems is to fuse the accelerometer and gyroscope data together in such a way that the errors cancel out. The standard method of
combining these two inputs is with a Kalman Filter, which is quite a complex methodology. Fortunately, there is a simpler approximation for combining these two
data types, called a Complementary Filter. Far better explanations than I could ever write are given here (AVRFreaks) and here (Shane Colton), but the
approximate formula to combine the accelerometer and gyroscope data is:

Filtered Angle = (Gyroscope Angle) + (1 ) (Accelerometer Angle) where

= /( + t) and (Gyroscope Angle) = (Last Measured Filtered Angle) + t

t = sampling rate, = time constant greater than timescale of typical accelerometer noise

I had a sampling rate of about 0.04 seconds and chose a time constant of about 1 second, giving 0.96.

So, now I had gyroscope data, accelerometer data and a filtered combination of the two. To visualize how these data all compared, I used Processing, an open
source programming language and environment (very similar to the Arduino IDE) that is particularly well suited for data visualization. I modified the Arduino
sketch to send the processed sensor and filtered data through the serial port, and wrote a Processing sketch to show the sensor and filter output as applied to three

3 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

3-D rectangles. Note that you must use the 32-bit version of Processing to get serial port access. For anyone who is interested,

here is the Arduino sketch:

GY_521_send_serial 7.90 KB
Download gy_521_send_serial (http://www.geekmomprojects.com/geekmomprojects-wp/?wpdmdl=1426)
and here is the Processing sketch (On Jan. 15, 2015, I updated the Processing sketch to fix a display bug that appeared in Processing 2.1.1):
ShowGY521Data 1.69 KB
Download ShowGY521Data (http://www.geekmomprojects.com/geekmomprojects-wp/?wpdmdl=1427)
.

The video below demonstrates the differences in the accelerometer, gyroscope and filtered data:

183 Comments

1.
Thomas
April 10, 2013 at 3:00 am

I like your blog, but am finding it difficult to use the Gy-521 to do my project. Am new to Arduino, i need this to calculate and tell me the position of a
moving ball. Am perplexed and i really need help to get me started. Please i need your help. Thanks and remain blessed

Best Regards
Emeka

Reply

2.
Emeka
April 10, 2013 at 3:18 am

As regards to my previous post, i have to add that am not using i2c or any freeIMU libraries. Will also need the code for it. Thanks

Reply

4 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

admin
April 10, 2013 at 9:40 am

Hi Emeka,
Im not sure exactly where your difficulties are, but a good place to start is with an Arduino sketch to print out the GY-521 sensor readings. I was able
to use the code by Krodal at the bottom of this page: http://playground.arduino.cc/Main/MPU-6050 without any modification to read and print out the
sensor readings. If you look carefully, this blog post provides links to the i2clib and freeIMU libraries (the terms i2clib and freeIMU are
hyperlinked to the web pages which have downloads for the libraries). I hope this is helpful. If not, perhaps you can explain where you are stuck in a
little more detail.
Debra

Reply

3. Pingback: Wii-Nunchuck Controlled Servo Motors | Geek Mom Projects

4.
robert young
May 6, 2013 at 8:36 am

Hi there.

First off this worked first time using my nano v3, thanks.

I was wondering how you would go about programming the z axes into this sketch, would this be in the processing file or the arduino file, what code would i
have to use? I do see references to the z axes the the arduino code so not sure if its just the processing file that need editing.

Also

The sensor is set to Acceleration at 2g which is i think AFS_SEL=0 (but i dont see that in the code ) so how would i set this to be at the 16g level ie
AFS_SEL=0, and would that affect anything in this sketch.

Thanks for the help and this sketch its a great help,
Ps only been playing with arduino for a week now so all new to me.

Reply

admin
May 6, 2013 at 8:51 pm

Thats a good question. Just for clarity, Im differentiating between the Gyro and Accelerometer measurements along the X, Y and Z axes, and the
computed rotation of the entire IMU board, which Ill refer to as Roll, Pitch and Yaw (rotation around the X, Y and Z axes, respectively). In the
Processing sketch, what is referred to as the X, Y and Z angles are actually the Roll, Pitch and Yaw. Youre right that you could incorporate Yaw in
Processing by simply adding a rotateZ function call after the rotateX and rotateY function calls.

The tricky part is that you cant compute Yaw from accelerometer data, because accelerometer computations rely on gravity pointing in the Z direction,
and are invariant to rotation around the Z-axis. The Arduino sketch does compute Yaw strictly from the gyroscope, and that Yaw value is sent over to
the Processing sketch. I wanted to compare the gyroscope, accelerometer and filtered data to each other, so I omitted displaying Yaw, because the
computation isnt comparable. You can definitely use the Yaw data if you want to it just doesnt incorporate data from the accelerometer.

With respect to changing the accelerometer range from 2g to 16g, the default value is 2g, and I never looked into changing it. I know that if you are
using the I2Cdevlib library there is a function call, setFullScaleAccelRange(), which modifies the value of AFS_SEL, and therefore the range. Without
using i2cdevlib, Im not actually sure how you change it.

Honestly, if you are going to use the data for more complicated calculations, you are better off using the I2Cdevlib or freeIMU libraries (links to both
are in this post). They have all kinds of additional functionality above and beyond what you can do in this sketch.

I hope this is somewhat helpful. Good luck!


Debra

Reply

5 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

robert young
May 7, 2013 at 6:26 am

Thanks you for all the help with this, i will start looking into the I2Cdevlib and freeimu libraries, once again thanks as this was the perfect place
to start,

Reply

5.
Kim
May 11, 2013 at 8:18 pm

Hi.
Why the theta is arctan((pow(Ax,2)+Pow(Ay,2))/Az),not arctan(Az/(pow(Ax,2)+Pow(Ay,2))) same phi and rho?. thank you!

Reply

admin
May 11, 2013 at 11:49 pm

These equations (and the image they are in) come from this paper at the bottom of page 4. In the paper, the picture has the following description:

In order to define the angles of the accelerometer in three dimensions the pitch, roll and theta are sensed using all three outputs of the
accelerometer. Pitch () is defined as the angle of the X-axis relative to ground. Roll () is defined as the angle of the Y-axis relative to the
ground. Theta () is the angle of the Z axis relative to gravity

Note that while rho and phi are pitch and roll, theta is NOT Yaw. Yaw is rotation AROUND the Z-axis. You cannot compute Yaw from accelerometer
data. In a system where gravity is the only force on the accelerometer, you know that
Sqrt(Ax^2 + Ay^2+ Az^2) = g
And since we have formulas for and in terms of Ax, Ay, Az, it turns out that is redundant and can be defined in terms of and . So you dont
really need .
As to why is calculated differently, according to the paper, the first two angles are defined with respect to the X-Y plane (the ground), but is
defined relative to the Z-axis, which is 90 degrees (pi/2) from the ground.

You can use the with the standard trigonometry identity:


atan(x) + atan(1/x) = pi/2
to see that if you calculated relative to the ground rather than the Z-axis, it would take a similar form to the other two angles.

I realize the picture can be a little confusing. It makes more sense in the context of the paper it comes from. I added some explanation to the picture
caption to make things clearer. I hope this helps.
Debra

Reply

6.
Kim
May 12, 2013 at 6:58 am

Thats a best answer for me.Thank you,Debra !:)

Reply

7.
Kim
May 15, 2013 at 9:59 am

hello Debra!
Can you tell me how to calibrate MPU6050 (gyro and acc) ?

6 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

I use GUI to see the angel and i find that the angel from the filter is lag than the angel from acc.You have some opinion about that? thank!

Reply

admin
May 16, 2013 at 12:03 pm

Hi Kim,
I did a very basic calibration just taking the first few readings of the sensors while keeping the IMU still, and subtracting the average values from
subsequent readings. Im sure that there are much more sophisticated calibration methods that could take into account rate of gyroscope drift, but Im
afraid I cant refer you to any sources. You might want to check the FreeIMU library for a more sophisticated calibration routine. I dont know for
sure, but it might have one.
As far as time lag in the filtered angle goes, that occurs because of the low pass filter applied to the accelerometer data in the complementary filter. To
eliminate the accelerometer noise, it is effectively averaging the data over time, which results in a delayed response. For a good visualization of how
the low pass portion of the complementary filter affects the data, check out the explanation of a low pass filter in this paper: http://web.mit.edu/scolton
/www/filter.pdf.
Hope that helps.
Debra

Reply

8.
Kim
May 17, 2013 at 9:17 am

Thank for your answer.you are nice!

Reply

9.
ArduPros
May 20, 2013 at 5:23 pm

Thank you very much for your work with the MPU-6050!
I buyed that board a couple of weeks ago too and I even thougt it was damaged because I couldnt solve the drift-problem with the FreeIMU library.

But then I found your project on Youtube and after downloading your programs I was so glad because now it is working

So thank you, you really helped me out

Reply

admin
May 20, 2013 at 7:21 pm

Im glad this post was helpful. Thank you very much for letting me know.
Debra

Reply

10.
Chris
May 21, 2013 at 11:29 am

Hi, I was wondering what made you pick a time constant of 1 second?

Reply

7 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

admin
May 21, 2013 at 10:57 pm

The time constant needs to be longer than the typical accelerometer noise, but shorter than the timescale over which the gyroscope displays significant
drift. I could see significant gyroscope drift after a couple of seconds. I didnt do any specific calculations to come up with a time constant of 1 second,
I just played around with different values of until the results looked good. Theres a nice explanation of the time constant in the complementary filter
here: http://www.instructables.com/id/Segstick/step10/A-very-flattering-filter/.
Debra

Reply

11.
Robert
June 2, 2013 at 6:37 am

Hi Admin,
Can you guide me on how can I add another GY-512 module please? I am planning to use to of them connected to the Arduino. How do I define the second
sensor module in the program?

Reply

12.
Robert
June 2, 2013 at 7:55 am

Hi Admin,
In addition to my earlier question, I would like to tell you my problem. I had difficulty in running the Processing file. I have tried with both Processing
version 1.5 and 2.0beta. When I try to run the file, an empty windows pops out and and the Processing IDE highlight this particular line, String portName =
Serial.list()[portIndex];.
May I know what is the problem? I am new to Processing, please help. Thank you.

Reply

13.
Robert
June 2, 2013 at 8:36 am

Hi Admin,
I have a third question here. How do I recalibrate the sensor module at different angle? I wish to install it vertically.

Reply

admin
June 2, 2013 at 7:29 pm

Hi Robert,
To address your three questions in order:
(1) I havent tried to add a second IMU to the i2c bus. Im sure its possible. According to a question answered here: http://www.varesano.net
/blog/fabio/how-connect-and-test-freeimu-v04-arduino-and-freeimu-library, you can change the i2c address of one of the MPU6050s on the bus, and
then access each MPU6050 with its own i2c address. I do not know how this is done, but you could try looking at the i2cdevlib library written by Jeff
Rowberg. There are many useful access functions in there. If you are trying to do anything where you modify the settings on the MPU6050, then you
should really use the i2cdevlib or freeIMU libraries.
(2) The Processing code is crashing where the program is looking for the name of the serial port attached to the Arduino. This will vary from computer
to computer. The Serial.list() method returns a list of serial port names on the computer, and it happens that my Arduino is connected to the second
port named on the list. If you know the name of the COM port your Arduino is attached to, you could just replace that line of code with portName =
COM5, or whatever the actual port name is.
(3) Turning the IMU on its side will result in no difference in the data returned by the MPU6050, you will just have to process it a little differently to

8 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

find the rotation angles. Assuming you are pointing the GY-521 straight up, the X-axis will be vertical, and the Y and Z axes will lie in the horizontal
plane. Gravity then aligns with the X axis instead of the Z axis and the accelerometer data is invariant to rotation around the X axis. You can use the
same functions as in the code to get the rotation angles, but just swap the sensor values for the X and Z axes in the computations.
In general, it is easier to use the code in the i2cdevlib library to do these computations for you, as it does most of the computations on the MPU6050
DMP. In my experience, it provides more accurate rotation angles than the complementary filter. I am working on a blog post demonstrating my
experiences with i2cdevlib, but you can see how it works with Jeff Rowbergs demo Arduino sketch MPU6050_DMP6.ino located here:
https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050/Examples/MPU6050_DMP6.
Good luck.
Debra

Reply

Robert
June 18, 2013 at 12:23 am

Dear Debra,

Thank you very much for the reply. I have browsed the varesano.net site. I have learned that the blogger, Mr Fabio has passed away. I didnt get
much help there but I am still going through the i2cdevlib hoping to get something. Do you know where can I get help on this?

As required for my project, I have placed the sensor module on my thigh and it displays a reading of at around 90 degree. As I lift my thigh up
while making the first move forward, the reading decreases to around 70 degree. I get about the same value from my another sensor on my left
thigh (still on positive quadrant). Here, I have difficulty to to differentiate the two readings. The 360 degree is divided into 2 main quadrant,
positive and negative and the maximum angle I am getting is only 90 and not 180. How do I change the settings to 180 degree?

Reply

Diogo
September 4, 2013 at 9:43 am

hello, Im using the mpu6050 the y-axis vertical. I have to change the code?

Thank you!

Reply

admin
September 5, 2013 at 2:14 pm

Yes, you will have to modify the code, because your yaw will be rotation around the vertical axis. In this code it is computed as
rotation around the Z-axis. You will have to compensate accordingly.,

Peter
September 5, 2013 at 10:02 pm

The modification of the code for the y axis vertical this?

float accel_angle_y = atan(-1*accel_x/sqrt(pow(accel_y,2) + pow(accel_z,2)))*RADIANS_TO_DEGREES;


f
float accel_angle_z = atan(sqrt(pow(accel_x,2) + pow(accel_y,2))/accel_z)*RADIANS_TO_DEGREES;

float angle_y = gyro_angle_y;

float angle_z = alpha*gyro_angle_z + (1.0 alpha)*accel_angle_z; //Accelerometer doesnt give z-angle

ok???

9 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

admin
September 6, 2013 at 9:45 am

Sorry, it was a while ago that I wrote the code, and I dont really have the time to check to see if there are any errors. You can use
this code, but what Id really recommend, especially if you want accurate yaw angle, is to use the i2cdevlib library that I wrote
about in this post: http://www.geekmomprojects.com/mpu-6050-dmp-data-from-i2cdevlib/.

Robert
June 19, 2013 at 1:24 am

Dear Ms Debra,

Millions of thanks to you. I have managed to make the two sensor modules work.

I still hope you can explain to me regarding the sensor module orientation settings.

For physical wiring,


http://forum.arduino.cc/index.php?action=profile;u=187766;sa=showPosts
http://electronics.stackexchange.com/questions/72927/how-to-add-additional-sensor-module-on-arduino

Reply

14.
Robert
June 28, 2013 at 6:50 am

Dear Ms. Debra,

I could run the Processing file by directly setting the portName.


I aware that you have used the accelerometer, gyroscope and the filtered variables reading from the Arduino program to print its data on the Processing
application. How do you link the variables from Arduino to Processing? I have noticed that you have defined,
float x_gyr;
float y_gyr;
float z_gyr;
float x_acc;
float y_acc;
float z_acc;
float x_fil;
float y_fil;
float z_fil;

However, I dont understand how did you link the variables from the Arduino program to the Processing program since the variables in the Arduino are
having different names. Can you explain on this please? I have started to feel comfortable on Arduino but just started on Processing.

Reply

15.
Ted
July 9, 2013 at 12:23 am

Hi, I am have been trying to this for a school project and have ran into some issues. This is my first Arduino project, actually first tech project, and I could
use some serious help. I am using an Arduino Uno on a freshly imaged Windows 7 32 bit computer (ran into issues running the sketch on a x64 image). I
have latest version of Java installed, I have uploaded the Arduino Sketch
and started the ShowGY521Data processing sketch. It freezes and I get this error. (screenshot) http://s18.postimg.org/9yj9rqgbt/Untitled.png
I have already tried to update RTXT http://forum.processing.org/topic/how-do-i-install-rxtx-2-2pre1-jar-on-windows-7 with no luck. Can you please help,
my project is due on Friday

Reply

10 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

Ted
July 9, 2013 at 12:24 am

The Arduino is plugged in COM 3 if it makes a difference

Reply

admin
July 9, 2013 at 1:16 am

Hi Ted,
I am on vacation and unable to get to my computer for any in-depth help, however, for this error, try setting the portIndex variable to 0 so
that it picks the first port name from the list of available ports, or you can specify the port as COM 3 directly by setting portName = COM3
(maybe COM 3, I forget offhand).
Hope this helps,
Debra

Reply

Ted
July 9, 2013 at 2:17 am

Thanks admin, setting the portIndex variable to 0 did the trick. I am not sure if this helped but I also downgraded to the last version of
Java 6. Thank you very much you are a life saver. Last question for you I would like to play around with the shapes of the animation,
do you have any tips for me ?

Reply

admin
July 9, 2013 at 9:44 am

For different shapes, you might try checking out some of the simpler examples that come with the Processing library. I adapted the
code from one of the cube examples to make the rectangles. Good luck!
Debra

16.
Chris
July 15, 2013 at 1:21 pm

Hi Debra,

I am successfully reading raw data, and trying to use the trig functions you have shown to calculate position from the accelerometers. The position in the X
and Y direction looks correct until I rotate past +-90 degrees on X or Y. Doing more research on arctan, the only possible outputs of the function are between
+-90 degrees so that makes sense to me. Have you done anything to make it so you can rotate in the X or Y direction and get readings between +-180
degrees? My application needs to know position over 360 degrees, not 180. Right now when I continue rotating past +90 degrees, the values start decreasing
back to 0 degrees (0 reached when the IMU is upside down). Does you application do that also?
Thanks so much in advance for your help, this page has really helped me a lot.

-Chris

Reply

admin

11 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

July 15, 2013 at 11:21 pm

Hi Chris,
The range of the inverse Arctangent function is (-Pi/2,Pi/2), which is why this method wont work easily for ranges greater than that. See my more
recent post on using the i2cdevlib library with the DMP (digital motion processor) in the MPU6050 which addresses this issue specifically.
Debra

Reply

17.
faith
August 15, 2013 at 3:25 am

This is awesome it clearded up most of things for me .I can use acc.But did not understant that how did yo find your dt(sampling rate) I can take value from
gyro and divide it with 131 but couldnt figure out what dt is ?.I tried to mulpt. it with 0.013 because my floop cycle is 13 ms but it is still drifftting .is it
fixed value that comes from mpu6050 conf registers or dlpcfg resgisters or it can change according to my program ?

Reply

admin
August 15, 2013 at 7:19 am

Hi. Dt is not fixed. I measured the clock time at each gyro reading and subtracted the previous time reading to find dt.

Reply

faith
August 15, 2013 at 2:58 pm

Im so glad that you answered.t was so important for me.But have 2 another question

1) f dt is not fixed by register what does DLPF_CFG for ? and sample rate for gyroscope can be 8khz or 1 khz is that change anything for gyro
?

2) tried data ready interrupt and couldnT really control it did you try to do it when do it cycles between interrupts was like 0.8 ms how am
supposed define dt while it is like that fast ?
y

Reply

admin
August 16, 2013 at 10:32 am

The data sampling rate is fixed, but I didnt use that value. If you look at the sample code I provide (gy_521_send_serial), every time I do
a reading of the GY-521 sensors using the function call, read_gyro_accel_vals, it is immediately followed by a call to the arduino
function millis, which measures the current time in milliseconds. Subtracting the previous value of the call to millis gives the elapsed
time since the last reading, which defines dt.
Debra

Reply

18.
Rodrigo Zanatta Silva
August 22, 2013 at 9:39 am

Hi. The code you post is not exactly the same you use in the video. Both works, but I dont know how you calculate the filtered data. I will need to rewrite
it Can you send the exact code you did? This will make easier test it.

12 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

Reply

admin
August 23, 2013 at 5:30 pm

As far as the motion of the three rectangles goes, I believe that the video and code are the same. What differences are you noticing? I dont have
another version.

Reply

Rodrigo Zanatta Silva


August 23, 2013 at 8:23 pm

Hi. Thanks for reply. The fist thing: The data that Arduino send to Serial Port is different from the data that Processing read. You need to rewrite
this part of code. I am newbie in Arduino and it take a long time to discovery

I didnt find where you calculate the filtered data. (But I need to read more). Anyway this is not an easy thing.

But two of tree data worked and for me was a good way to start. But if you can find the exactly code you did, it will be easier to me.

Reply

admin
August 25, 2013 at 11:22 am

I havent had the problems you mention with different data leaving the Arduino and being received by the Processing code. I think you
might want to check your setup again. I have not heard about these problems from anyone else, but when I find the time, Ill go back and
check for errors. And the code is commented, so if you take the time to read it, you should be able to find where the filtered data is
computed. All the code I added to Krodals existing program is towards the bottom of the file. Start by looking there and reading the
comments. It may help you.

Reply

19.
Diogo
September 4, 2013 at 9:14 am

Hi. why do not you apply the filter angle Z?

Reply

admin
September 5, 2013 at 2:13 pm

If you read previous comments (its also mentioned in the article), youll see that you cant compute the yaw (Z axis rotation) from accelerometer
values. So while we have values for pitch and roll from both the accelerometer and gyroscope, we only have values for yaw from the gyroscope.
Therefore we cant apply the complementary filter to yaw.

Reply

20.
Diogo
September 4, 2013 at 2:52 pm

13 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

have problems if I calculate the filter complement of the angle Z? calculating the acceleration as pictured.

Reply

admin
September 5, 2013 at 2:14 pm

See reply to your previous comment.

Reply

21.
Peter
September 5, 2013 at 8:53 pm

How to find out then the rotation angle z?

Reply

Svein
November 6, 2013 at 3:48 am

The variable angle_y in the loop contains the filtered rotation angle z.

Reply

22.
Ira Hart
September 6, 2013 at 7:49 am

Thank you for posting this! Great work. Visualizing this in Processing is wonderful.

Reply

23.
Ari Romero
September 11, 2013 at 8:12 am

Great Job!! and thank you for sharing all this stuff. Im new to all of this and its been a great help.

Reply

24.
Tony
September 20, 2013 at 10:10 am

hi Debra,
I tried your code but it produces very jittery orientation & acceleration. However, when i tried Rowbergs code, it works perfectly. But, the drawback is his
code is so complicated to read. Your code or more accurately, Krodals code, is much simpler to understand.

Krodals code produces raw data, where do you process those signals and filters them because i dont find it in the code that you provide here at the bottom
of your page.

thanks

Reply

14 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

25.
Tony
September 20, 2013 at 10:30 am

hi Debra,
I finally get it working sorry mixed up code here:)

Reply

26.
ricardo
September 28, 2013 at 2:58 pm

Thank you so much! Thanks to your great job i was able to make it work in an hour. It would have probably taking me days otherwise.

Thank you again,


Ricardo

Reply

27. Pingback: Plotten & preprocessen | Het Klaslokaal van de Toekomst

28.
Muralidharan
October 24, 2013 at 6:41 pm

Sir ,
I m building a self balancing bot,and im in the stage of tuning PID parameters,I really need to know the sampling period of the sensor you used in your
arduino program.As the loop time needs to be matched with the sampling rate!!

Reply

29.
Muralidharan
October 27, 2013 at 5:01 am

Also how was alpha set to 0.96 ??

Reply

30.
Svein
November 6, 2013 at 3:27 am

Thank you so much. I am very grateful for your blog. This put an end to hours and hours of trouble shooting how to grab the value from the gyro in a form
that can be use further the sketch and not just in a form that can only be displayed on a LCD display or the serial monitor.

Reply

31.
emerjer
November 18, 2013 at 8:28 pm

Hello,

I see all of the helpful information here and I have having issues with my MPU 6050 for several weeks now and have yet to find any answers yet. So I
thought Id give this a shot.

I wired everything as shown above as well as what is posted by Jeff R. and uploaded the sample programs. When I check the serial monitor I get the

15 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

following:

InvenSense MPU-6050
June 2012
WHO_AM_I : 11, error = 2
PWR_MGMT_2 : 11, error = 2

MPU-6050
Read accel, temp and gyro, error = 2
accel x,y,z: -5374, 2, 305
temperature: 37.212 degrees Celsius
gyro x,y,z : 2050, -13039, -29695,

MPU-6050
Read accel, temp and gyro, error = 2
accel x,y,z: 747, 512, 12545
temperature: 24.459 degrees Celsius
gyro x,y,z : 520, 4557, 396,

I havent found anything about what the error means or how I can resolve this. Have you seen this or know how I can get rid of the error?

Any help would be awesomely appreciated. Thank you, emerjer

Reply

admin
November 21, 2013 at 9:45 am

Im afraid I have no experience with the MPU-6050 error codes. I found a post that discusses them here: http://forum.arduino.cc/index.php
/topic,139378.0.html, but cant offer more help than that. Sorry.

Reply

emerjer
December 2, 2013 at 7:51 pm

So Ive done some research and found that the error = 2 is because of insufficient power to the GY 521. Once I soldered the pins to the board
and secured it to a wired bread board everything worked fine.

Now off to troubleshooting my Processing complications.

Thanks!!!!!

Reply

32.
Vincius Oliveira
November 26, 2013 at 6:48 am

Hi there.

First of all thank you, this post was really helpful.

But I have a problem with it.

When I run the code it shows me something like that:

M*Zi@8
HN)JLM*L@8JHNu)JLM*ZL@8
HN)JLM*ZH@8HHN)JLM*ZLp8HN)JM*ZH@8HNJLM*ZL@8JHvN!JLM*ZH@8NHN!
J,M*ZH@HN!JLM*ZL@8HHN!JMZH@8H!JlM*ZL@8
,HN!JM*ZH@8
HN!LJLM*Zh@8HHN!LJLM*L@8LHNu!LJLM*ZH@8HN!LJLM*ZH@8

16 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

HNLJLLM*ZH`8

Do you know how do I fix that?

Regards,
Vincius Oliveira

Reply

admin
November 26, 2013 at 7:44 am

Have you checked to make sure the baud rate is the same for the Arduino IDE and Processing?

Reply

33.
nikko
November 29, 2013 at 1:10 am

Hi Debra,
First of all, thank you very much for such an effort. Ive problem on processing tool and couldnt find any clear comment either here or in forum of
processing.org.
I followed your steps and it seems everything is ok. But when I try to play the processing sketch, I will face with 2 problems:
1) There is not any cubes like 3D objects. I can see only lines.
2) There is only 2 simple lines one is yellow for Gyro and the other one is green for filtered data. There is not appeared any blue line for accelerometer.
Eventhough, when I moved the MPU6050, those lines are also moving. So it means I can receive information but I have some 3D processing problems. Have
you faced any problem like that?
*My computer is very new, it has 4GBytes ram with 2.7GHz microprocessor. It is 64bit but I used 32bit version of processing as you mentioned. (Also tried
54 version). Please share your comments, thanks a lot again.

Reply

34.
admin
November 29, 2013 at 9:04 pm

Hi Nikko,

Im afraid I havent experienced any problems like you describe in Processing. The only thing I could suggest is running some of the demos that come with
Processing to see if they look correct. That could at least tell you if theres something odd about the way this specific program runs on your computer or if
your entire Processing set-up is funny.

The hardest part of the Processing code is unpacking the information from the IDE, which you said appears to be working. Maybe you can try re-writing the
code for drawing the rectangles by copying the code a simple shape from one of the Processing demos and rotating that object instead of the rectangular
shape.

Sorry I cant offer more concrete help. Good luck.


Debra

Reply

35. Pingback: MPU-6050 Accelerometer + Gyro

36.
nikko
December 2, 2013 at 7:27 am

Thank you for reply. By the way Ive solved the problem with using old version of processing.
(v2.0.3 instead of v2.1)

Reply

17 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

37.
emerjer
December 2, 2013 at 8:35 pm

So I was able to get the Example Ardruino Sketch to work as shown above once I had a good power connection. But lately I have been having trouble with
the example ShowGY521 Processing Sketch.

I have tried running the program and after changing the portIndex = 0; instead of the default 1 in the example the window pops up with all three Gyroscope,
Accel., and Combo titles come up but show (0,0) in all three. The rectangle shapes are there. But neither the rectangles or the (0,0) changes with
motion/rotation of the GY521.

Any thoughts on this?

Thank you very much for all of your help. This is a great resource for those with GY521.

Reply

38.
Vincius Oliveira
December 3, 2013 at 7:05 am

Now it works just fine.

Thank you!

Reply

39.
marcferier
December 10, 2013 at 9:44 am

Hi guy , I have had ths same problem few week ago. Its works now


// Default I2C address for the MPU-6050 is 0x68.
// But only if the AD0 pin is low.
// Some sensor boards have AD0 high, and the
// I2C address thus becomes 0x69.
#define MPU6050_I2C_ADDRESS 0x69

before : 0x68
after : 0x69.
Its works good,
let me know.
by the way,
what is your project?
Im trying to build a quadcoptere (4 brusless motor) with an arduino and a mpu6050.
Im not successul yet, that why Im read this topic but i now have trouble with processing
Bye

Reply

40.
marcferier
December 10, 2013 at 9:45 am

I let you a answer , at the bottom of this page..

Reply

18 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

41.
Alex
December 16, 2013 at 11:43 am

Hi. I have a problem with the Processing sketch. It is unbelievably laggy. I have to wait a few seconds after rotating the board for the rectangles to update.
Also theyre not 3D:
https://dl.dropboxusercontent.com/u/41928260/Screenshot%202013-12-16%2021.17.37.png

I have never used Processing and have no clue what could be wrong.

Windows 8.1 64bit, recent install, didnt even have java installed, thaught thats the problem, installed 7.45, didnt help.
Tired Processing 2.0.3 and 2.1 64bit, Arduino Duemilanove, Nano and Pro mini, all with ATmega328s.

Would appreciate any help!

Reply

42.
Mauro
December 26, 2013 at 3:44 am

Hi Debra !
congratulations for your work. I approached the environment Processing 2.1 just to try a project quite similar to yours.
My microcontroller board is working properly (even though it has yet to be completely developed), and provides the correct data to the PC, in fact I can view
them with a simple terminal program.
I would like to use the sketch that youve written to see those simple rectangular and give a visual aspect to the data transmitted from the microcontroller
plate.
The problem is that Processing 2.1 doesnt run the code youve shown on this page, it simply displays the error that you can see below.
I dont want to shift the focus of my project to the study of Processing 2.1 and certainly Im not an expert in computer graphics (it could take me a lot of
time).
I know thats not so polite, but I would like to ask you a little help interpreting the error.
Would you ?

thanks

The issue:
Framebuffer error (framebuffer unsupported), rendering will probably not work as expected Read http://wiki.processing.org/w/OpenGL_Issues for help.
OpenGL error 1280 at bot beginDraw(): invalid enumerant
java.lang.NullPointerException
at processing.mode.java.runner.Runner.findException(Runner.java:926)
at processing.mode.java.runner.Runner.reportException(Runner.java:871)
at processing.mode.java.runner.Runner.exceptionEvent(Runner.java:797)
at processing.mode.java.runner.Runner$2.run(Runner.java:686)

Reply

43.
Mauro
December 26, 2013 at 2:03 pm

Hi ! Sorry for the request, Ive solved the problem.


Simply use not the last one but one of the previous releases of Processing, i.e. the 1.5.1, it works fine !

Reply

44.
mahdi
January 24, 2014 at 11:24 pm

Hi,
first, could you please let me know what is that graphic program you are using?
is it possible to get its code?

19 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

Also, do you have any exprience with using external magnetometers or MPU9150.
I mean how we can covert raw data to angle when we have 9 DOF?
Tnx

Reply

admin
January 27, 2014 at 9:37 pm

The graphics are generated using the Processing software (available for free), and the processing code is available from a link in the article. Note that a
previous user had trouble getting the Processing code working with the current version of Processing, and had to revert to an earlier version to get it to
work.
Im afraid I have no experience with magenetometers, so Im afraid I cant be very helpful there.
Debra

Reply

45.
Anibal
January 27, 2014 at 12:36 pm

Amigo este problema sucede por que no tienes bien conectada tu mpu6050 verifica bien los pines, tenia el mismo problema

Reply

46.
Jonas
February 1, 2014 at 5:20 am

In Processing it says:
I dont know, what to do

Exception in thread AWT-EventQueue-0 java.lang.ArrayIndexOutOfBoundsException: 1


at ShowGY521Data.setup(ShowGY521Data.java:57)
at processing.core.PApplet.handleDraw(PApplet.java:2281)
at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:652)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:636)
at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1284)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1106)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:981)
at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1295)
at javax.media.opengl.Threading.invoke(Threading.java:193)
at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
at javax.media.opengl.awt.GLCanvas.paint(GLCanvas.java:595)
at sun.awt.RepaintArea.paintComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)

20 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
java.lang.NullPointerException
at processing.mode.java.runner.Runner.findException(Runner.java:926)
at processing.mode.java.runner.Runner.reportException(Runner.java:871)
at processing.mode.java.runner.Runner.exceptionEvent(Runner.java:797)
at processing.mode.java.runner.Runner$2.run(Runner.java:686)
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help ? Troubleshooting.

Reply

admin
February 1, 2014 at 6:09 am

Its probably a mistake in the part of the code that looks for the serial port to communicate with Arduino. On my computer that was the second serial
port in the list. I dont have the code in front of me, but try changing the serial port index variable from 1 to 0.

Reply

47.
Angel
February 1, 2014 at 11:57 am

Thank you for sharing this modification of Krodals code. When I run the code (without visualising it through Processing) and switch on the Serial Monitor
to see the raw values (like in Krodals code) I get this on the serial monitor:

JL
LM*H@8NLJ
HJJLLNM*H@8NJ
HNJJLHLNM*H@8NLNJ
HNJJLLNM*H@8LJ
HJJ
LNM*H@8LNJ
HJJJLNM*H@8LJ
NH
J
JLNM*H@8LJ
H
JLNM*H@8NLJ
HJJHLNM*H@8LNJ
HJ
LNM*H@8NLJ
HJH
LM*H@8LJ
HNJJHL
.
.
.

Do you have any idea how I can fix this in order to display normal letters and numbers. I am a newbie with Arduino so I would appreciate an easy to digest
solution, please. Cheers.

Reply

admin
February 1, 2014 at 12:35 pm

21 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

It looks like the baud rate of the serial port (set in the Arduino sketch) doesnt match that of your terminal window. Try changing the rate displayed in
the window and see if that helps.

Reply

48.
Angel
February 1, 2014 at 2:55 pm

If this is what I am suppose to see then its fixed:

DEL:0.0020000002#ACC:0.76,-4.29,0.00#GYR:-0.00,-0.00,-0.00#FIL:0.03,-0.17,-0.00
DEL:0.5109999656#ACC:1.01,-4.35,0.00#GYR:0.01,0.03,0.06#FIL:0.08,-0.31,0.06
DEL:0.5090000152#ACC:0.87,-4.11,0.00#GYR:-0.05,0.04,0.09#FIL:0.06,-0.45,0.09

Thank you very much for the support and quick reply !

Reply

49.
Federico
February 12, 2014 at 4:04 pm

hello! congratulations, youre really a myth! very good! and thank you very much!

Sorry, but I have a problem with processing, it is the first time I use it and I could not understand why he says: OpenGL error 1282 at bot endDraw ():
invalid operation
and do not open the drawing animated in 3D.

Can you help me please?


thanks and congratulations again!

Reply

Mauro
February 13, 2014 at 9:45 am

Hi Federico, what release of Processing are you using ?


Take a look to my message above. I solved my issues using a previous release of the environment.

Reply

50.
Federico
February 16, 2014 at 3:59 pm

Hi, thanks for your time, I had read that it was better to use version 1.5.1 for windows and Im using this.

My procedure:
Load the sketch on Arduino, connected to the sensor, and data are visibles on the serial monitor Perfect
Then I use processing, with his sketch, and I click on Run.

and window opens with the three parallelograms, but each parenthesis shows the value 0 and the figures remain motionless.

thanks

Reply

51.
Mauro

22 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

February 17, 2014 at 10:24 am

Hi Federico, Im wondering if everything is working well on the USB/com communication (maybe not), if I was in your shoes I would check the USB in
the Systems devices properties of windows.

Reply

52.
Federico
February 18, 2014 at 2:32 am

Hi Mauro;
it is ok; Arduino Uno is on COM11; and it communicate correctly, because the values are correctly printed in the Serial Monitor.

Reply

53.
Zain
February 21, 2014 at 7:08 am

I need to trace the trajectory of swing of a bat in matlab using this IMU. Could you plz guide me..

Reply

54.
Azmyin
February 26, 2014 at 7:42 am

Hello
Thanks a lot for uploading the Processing Sketch. It really helped me to clear some concepts. I have been trying to write a quadcopter stabilization code for
sometime now but after reading a lot of articles blogs and finally seeing your processing sketch in action I now know that I need 10DOF IMU instead of the
6DOF that I currently posses.
One thing that I saw is that you have used complementary angle to do the final calculation. If you got time why dont you use the Kalman Linear Quadratic
Equation or Kalman filter. You can get a lot more accuracy and will be able to correct the drifting that the gyro experiences. It was clearly seen that after a
minute or two the raw gyro values became biased in one direction.

Thanks again for the great upload and the very informative posts

Reply

55.
Varundev
March 3, 2014 at 7:14 am

Hi.

Great blog.

I downloaded the sketch onto the arduino, and I was able to run the processing code as well.

But, after the code was loaded, the 3D objects on the screen were not stable. Also, the blue box for the accelerometer was not visible.

What could I have done wrong?

Reply

admin
March 3, 2014 at 10:38 am

Can you check to see that the data from the Arduino is making it into the processing sketch?

23 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

Reply

56.
Narangerel
March 5, 2014 at 8:55 pm

Thank you
How to write a GY -521 programm

Reply

57.
Chris
March 16, 2014 at 2:23 am

Thanks so much for making this available. I never expected to progress from a blinking LED, to making a simple gimbal with a couple of servos, in just a
few hours after unboxing my first arduino!!

Reply

58.
Sam Horner
March 29, 2014 at 5:22 pm

Just wanted to let you know that Ive been pouring over this page for about a week and Ive been angry/confused/sad/crazy trying to work this all out. i just
finally got my prototype working for a product Im designing. THANK YOU SO MUCH!!!

Reply

59. Pingback: MPU-6050 : Acelermetro + Giroscpio | Harduino

60.
Andrew Bishop
April 8, 2014 at 4:31 pm

Thank you so much for posting this code! It helped me a lot with a project. Im having some problems with the processing sketch. Whenever I run the sketch,
it tells me that the port is busy. I already have the arduino sketch running and outputing data to the serial monitor. Here is the error message:
java.lang.RuntimeException: java.lang.RuntimeException: Error opening serial port /dev/tty.usbmodem411: Port busy

Reply

admin
April 10, 2014 at 9:42 am

I dont know what specifically is causing the error. Im running under Windows 7 and found that sometimes when Id quit the Arduino sketch, it
wouldnt always free up the port, and Id have to reboot the computer. You should also check to make sure that its trying to access the correct port.
The code opens the second port in the list of ports, however that may not be the port youre using on your computer.

Reply

61.
Francisco
April 11, 2014 at 11:25 am

Hi! first of all thanks for sharing article! very helpful!


In arduino the code is working great, but when i try to run on processing this error appears and on my viewport the cube doesnt move.
The error:

24 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

Error, disabling serialEvent() for COM4


null

Im using an arduino leonardo board with gy-521


Thanks in advance!

Reply

62.
mettledrum
April 14, 2014 at 11:18 am

Thanks for the blog!

Reply

63.
nathan
April 21, 2014 at 2:19 pm

Hi Francisco
Im getting the same issue, did you ever find a resolution?

Reply

64.
Nelson
April 28, 2014 at 3:04 pm

Hi Debra,
It is the first time i am using this chip. I am controlling two wheeled mobile robot, i.e position control using arduino. The idea i have is to use this chip to
determine the position of the mobile robot which i will then feed back to the reference position for comparision. Can i use the quaterion values (w x y z) as
my measured position or i need to integrate the x,y,z acceleration to determine them? Please tell me how i can determine xy position of my mobile robot
using this chip.
Thanks in advance and looking forward to hearing from you.

Reply

admin
April 28, 2014 at 4:09 pm

If you use the IMU values from the Digital Motion Processor, aka the DMP (for more info, see the post http://www.geekmomprojects.com
/mpu-6050-dmp-data-from-i2cdevlib/), the DMP takes care of the integration and calibration of the MPU6050 chip for you. Otherwise, if you are
going to compute the quaternions yourself, you will have to do the angle integration yourself as well. Im not sure what you mean by xy position of the
robot. The IMU will help you determine angular orientation of your two wheeled robot, but it is very difficult to use it to get an accurate position. For a
two-wheeled robot, you should really only have one degree of freedom anyhow, as it will only tip forwards or backwards. And since your robot cant
presumably tip more than 90 degrees in either direction, using quaternions may be overkill for your application. A complementary (or Kalman if you
feel like a challenge) filter should work just fine. Im actually working on a two-wheeled self-balancing scooter myself right now, and the
complementary filter is doing an ok job.
Edit: I just realized that you may want to use the IMU to measure rotation about the vertical axis for turning purposes, as well as using it to balance the
robot. If thats what you mean, its very hard to get accurate rotation about a vertical axis using a complementary filter, since the accelerometer does
not give rotation information about the Z(vertical)-axis. In this case you should definitely check out the article I linked to above for using the DMP to
compute rotation about all 3 axis, as whatever (unknown) algorithm the MPU6050 uses to compute angular rotation appears to handle the Z-axis
rotation resasonably well.

Reply

Nelson

25 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

April 28, 2014 at 4:34 pm

Thanks admin for your quick reply. The reason i need xy position measurement is because am doing trajectory control where i need to feedback
x, y, theta in order to track the position of my my mobile robot. Theta being the angle of rotation or heading angle. Hence i need these three
parameter s but as mentioned earlier i dont know which values from the dmp to use. Otherwise again thanks and am taking a look at the link.
You are highly welcome to elighten me more if you understand my problem

Reply

admin
April 28, 2014 at 7:32 pm

The MPU6050 will give you angular velocity and angular orientation data but not position data. Even with a 6DOF IMU, its not so easy
to get accurate information about rotation around the vertical axis (what I assume you mean by theta). The complementary filter wont
work for theta. You will need to use the data from the DMP to get that. An IMU isnt really the right tool to use to get position data. Its
theoretically possible, but youd have to take the accelerometer data directly, and integrate twice to get position. Errors will accumulate
very rapidly. If your robot wont be slipping, youre probably better off using encoders on the wheels to give you distance travelled
combined with theta to get the overall position.

Reply

65.
okdshin
April 29, 2014 at 6:42 am

Hello. Thanks for the cool article.


I want to use your source code for my project,
so can I use your source code freely?(modification, redistribution or commercial etc)

Reply

admin
April 29, 2014 at 6:51 am

Thank you for asking. Absolutely. Of course this code is heavily based on the code from Krodal at this link: http://playground.arduino.cc
/Main/MPU-6050, which is public domain, so there should be no problem in using it. Good luck.

Reply

66.
Ardi
May 7, 2014 at 1:12 am

Hello, Thanks for your great article.


How I can change the pin position?

Reply

admin
May 7, 2014 at 12:46 pm

Hi, Im sorry I dont fully understand the question. The Arduino pin assignments are set in the code. If Im not understanding, please clarify the
question.

Reply

26 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

67.
Ardi
May 7, 2014 at 1:35 pm

Admin,
In this article you connect:
VCC -> 3.3V
GND -> GND
SCL -> A0
SDA -> A1

So I wanna change:
SCL -> A2
SDA -> A1

How I can do that?


Im new at this and couldnt find anything but everything is working perfect and I just want to change SCL and SDA pin number.

Thank you so much

Reply

admin
May 7, 2014 at 1:47 pm

Actually youre correct, theyre not set in the code, however A4 and A5 are the default pins for the i2c bus, which is the communication protocol used
to send data back and forth between Arduino and the GY-521. The pins are set in the Arduino wire library. You can attach multiple devices in
parallel to the i2c bus, so you shouldnt have to free up those pins if you want to add another device. If you really want to swap in different pins, you
could try this link to todbots blog, where hes rewritten the wire library to use different pins: http://todbot.com/blog/2010/09/25/softi2cmaster-add-i2c-
to-any-arduino-pins/. Ive never tried it, though.

Reply

68.
rootScript
May 7, 2014 at 7:09 pm

Try changing portIndex variable to a different number.


mine worked on:
short portIndex = 5;

Reply

69.
arduinoAndMore
May 7, 2014 at 7:22 pm

I have the same problem. Reply if you ever get this fixed please?

Reply

70.
Ricardo
May 8, 2014 at 8:10 am

Congratulations for the blog, it clarified a lot about how to use a gyroscope and accelerometer in microcontrollers! Thank you!!

Reply

27 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

71.
Ardi
May 8, 2014 at 9:37 am

Thanks

Reply

72.
ebrahim
May 12, 2014 at 1:09 pm

Mr admin.
the codes on ardiuno and processing are running fine. but i dont see any data. the rectangles dont move and the accelerometer rectangle doesnt even show.
how can i see weather the data is making it to processing? the ardiuno is connected to com9 if it helps. Id be very glad if you could help

Reply

admin
May 15, 2014 at 8:43 pm

Hi Ebrahim,
I know others have had a similar problem. Im afraid I dont know what causes it. Are you sure that processing sketch is finding the correct port? The
sketch I wrote just pulls the 2nd port from the list of ports, but that might not be the correct port to connect to on your computer. I think a few other
people had better luck using an earlier version of Processing. You might also check to make sure youre using the 32 bit version of Processing, as thats
the only one that works with Serial Port access. Good luck, and sorry I cant offer more help.
Debra

Reply

ebrahim
May 20, 2014 at 2:32 am

Thanks for the reply Debra. I got it to work by changing portIndex from 1 to 3, and the bits per second to 9600.

Reply

73.
alan
May 30, 2014 at 8:55 am

Hi Debra
Thanks for a wonderful article on displaying the output from an IMU. I am having a problem with the processing sketch same as Andrew Bishop where the
com port is busy. The arduino sketch is working perfectly and sensor data is being transmitted to the serial monitor. I am running win 7 and downloaded
processing win 32 bit. I then tried the very early version of processing 1.5.1. The 2.2.1 version of processing gives the port busy error. The 1.5.1 version
gives error inside serial.
I then tries using a different arduino board. First board is the UNO. Second board is the duemilanovue. UNO uses com7, Due uses com8.
I would really like to get the graphics working, but am having no luck. Any suggestions would be welcome.
Does it matter what sequence you start up the processing software? Should you start the arduino first and then run the processing or vice verse?

Reply

admin
June 4, 2014 at 8:28 pm

28 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

Im afraid Im not sure what the source of those errors is. Ive only run this program with Processing 1.5.1, which worked well for me. In that version
of Processing, serial communication only works in the 32 bit version, not the 64 bit version. Are you using the 32 bit version of Processing 1.5.1?
Thats the only thought I have right now. It shouldnt matter what order you run the Arduino or Processing sketches in.

Reply

74.
Jason
June 3, 2014 at 1:15 pm

Hi~
I need your help

It was good at using program in my computer but happened error in another computer.
although same source file..

I dont know what to do

Exception in thread AWT-EventQueue-0 java.lang.ArrayIndexOutOfBoundsException: 1


at ShowGY521Data.setup(ShowGY521Data.java:47)
at processing.core.PApplet.handleDraw(PApplet.java:2361)
at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1289)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1300)
at javax.media.opengl.Threading.invoke(Threading.java:193)
at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
at javax.media.opengl.awt.GLCanvas.paint(GLCanvas.java:595)
at sun.awt.RepaintArea.paintComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 1
at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206)
at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
at javax.media.opengl.Threading.invoke(Threading.java:191)
at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
at processing.opengl.PJOGL.requestDraw(PJOGL.java:688)
at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1651)
at processing.core.PApplet.run(PApplet.java:2256)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at ShowGY521Data.setup(ShowGY521Data.java:47)

29 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

at processing.core.PApplet.handleDraw(PApplet.java:2361)
at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1289)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1300)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Could not run the sketch (Target VM failed to initialize).
For more information, read revisions.txt and Help Troubleshooting.

Help me~

Reply

admin
June 4, 2014 at 8:23 pm

Hi Jason,
It looks like your processing sketch is not connecting to the correct serial port to get the Arduino data. The Processing sketch I wrote defaults to
picking the second value from a list of serial ports on the host computer. You may only have one serial port in the list, so trying to access the second
element is giving you an out of bounds exception. Try changing the index into the array to [0] instead of [1] and see if that helps. Offhand, I believe the
variable you need to change is called portIndex. The value of the serial port you need to run the Processing sketch depends on the setup of the
computer you are using. Hope this helps.
Debra

Reply

75.
rihab
June 10, 2014 at 8:08 am

Salut ,
je rencontre le meme problme que Fiderico fentre souvre avec les trois paralllogrammes, mais chaque parenthse indique la valeur 0 et les chiffres
restent immobiles.
sil vous aidez moi cest trs urgent !! et merci davance .

Reply

Mauro
June 10, 2014 at 12:52 pm

Think its better you write in English, if your issue is really urgent, as well as this site is written in English

Reply

30 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

admin
June 10, 2014 at 2:07 pm

It sounds like the data is not getting across the serial port from the Arduino to the Processing sketch. Other people have had difficulties with this.
When I wrote this sketch, only the 32 bit version of Processing supported serial data. That may be something to check. Also make sure the serial baud
rate is the same between Arduino and Processing, and that your Processing sketch is accessing the same port number that your Arduino is writing to. If
none of that helps, you might try using an earlier version of Processing some people in earlier comments found that helpful.

Reply

76.
Jo
June 12, 2014 at 12:49 am

Hey, i just wanted to thank you for sharing your projects!

After hours and hours using 2 different arduinos on 4 different pcs with 3 different OSes (and destroying some MOSFETs) I finally got to work what i
wanted and I learned a lot

Without your post (and the one about i2cdevlib) it would have taken a lot more longer!

Initially I wanted to build some 20 gramm micro quadrocopter. Im just not sure if i manage to build the motor control pcb that easy because smd soldering
and bad eyes/uncalm hand are not the best combination. But when i finish I will open up some blog and share it.

Reply

77. Pingback: The Halfway A Self-Balancing Scooter | Geek Mom Projects

78.
rihab
June 17, 2014 at 4:16 pm

hi,
Is that we can calculate the position from MPU6050??
normally when we have a linear acceleration we can deduce the position but in our case is the angular acceleration so what is the solution?

Reply

admin
June 18, 2014 at 3:20 pm

If you want to know the physical position in space of your object, you could theoretically integrate the data from the accelerometer in the MPU-6050
twice to get position, however it wouldnt be very accurate for two reasons. First, you would gain a lot of noise in the integration process, and
secondly, the accelerometer readings themselves are very noisy, which is why we combine them with the gyroscope readings in the complementary
filter.

Reply

79.
shiong
June 20, 2014 at 12:13 am

Hi admin,
may i know why my gyro cant work?i get zero for my result

Reply

31 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

admin
June 20, 2014 at 11:47 am

Sorry, that question is a little to vague for me to know what the problem is. I recommend reading previous comments where people had problems to
see if any of their problems were the same as yours.

Reply

80.
shiong
June 20, 2014 at 5:37 am

may i know, is this work if i use intel galileo?

Reply

admin
June 20, 2014 at 11:49 am

It probably wouldnt work directly. Youd have to adapt it. The wire library that the I2C communication depends on was developed for the Arduino
architecture.

Reply

81.
Sri
June 20, 2014 at 9:35 am

What were the accuracy levels achieved for roll and pitch angles?

Reply

admin
June 20, 2014 at 11:49 am

Im afraid I never got around to quantitatively comparing the data to another source, so I dont have an answer for that.

Reply

82.
shiong
June 20, 2014 at 7:55 pm

but galileo got wire library as well, it works for accelerometer but cant work for gyroscope, i got a zero for my gyroscope result

Reply

83.
Bin
June 21, 2014 at 7:25 am

Hi,
Thanks for the wonderful tutorial.

32 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

However, I have a question to ask. I found that the serial communication seems to get slower and slower over time, if the board is connected and the code is
running for a long time. It is smooth at first, but tends to start lagging in around 1 minute. This happens for both Arduino serial monitor and Processing
sketch. Is this normal? If not, what could be the cause? Is it caused by the code or the board itself?
Thanks

Reply

admin
June 21, 2014 at 8:06 am

Sorry, Ive never noticed that effect, and Ive let the sketches run for long periods of time in a demonstration. Have you tried setting the baud rate
higher in both the Arduino and Processing sketches?

Reply

84.
Bin
June 21, 2014 at 8:04 pm

It seems like changing the baud rate doesnt help. Serial communication still getting slower and slower over time, and there is no difference between
different baud rate.
One thing to mention, I am using Galileo board. Is it possible that it is due to the incompatibility of libraries?

Reply

85.
shiong
June 22, 2014 at 6:11 am

May i know your gyro, when you turn about x-axis, the value is it limited to only 90 degree?do yours face this problem?

Reply

admin
June 24, 2014 at 8:52 am

The range of the inverse Arctangent function is (-Pi/2,Pi/2), which is why this method wont work easily for ranges greater than that. See my more
recent post on using the i2cdevlib library with the DMP (digital motion processor) in the MPU6050 which addresses this issue specifically.

Reply

86.
Ansh
June 24, 2014 at 2:42 am

How did you decide upon the time constant ??

Reply

admin
June 24, 2014 at 8:53 am

The time constant needs to be longer than the typical accelerometer noise, but shorter than the timescale over which the gyroscope displays significant
drift. I could see significant gyroscope drift after a couple of seconds. I didnt do any specific calculations to come up with a time constant of 1 second,
I just played around with different values of until the results looked good. Theres a nice explanation of the time constant in the complementary filter

33 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

here: http://www.instructables.com/id/Segstick/step10/A-very-flattering-filter/.
Debra

Reply

87.
Ansh
June 24, 2014 at 8:00 am

Hi Admin,
I have tried using your both the sketches.I am having some issues related to processing.When I run the processing sketch I see all the three rectangles.But on
moving the MPU6050 the rectangles wont rotate.Seeing the above posts I used Processing 1.5 instead of higher versions and changed the portIndex no to 0
also.Still it doesnt work.Is it that no data is being received???

Reply

admin
June 24, 2014 at 8:51 am

It sounds like the data isnt getting across to the processing sketch. Make sure your baud rates match in Arduino and Processing, and it might help to
put a few print statements in the Processing sketch to see what kind of data you are receiving, if any. Also, depending on your computers
configuration, your portIndex value is whatever index into the list of ports matches the serial port that the Arduino is connected to.

Reply

88.
Kurtis Saiyo
July 8, 2014 at 10:23 am

It might be possible to build a calibration curve. But I see you are more concerened with calibration at start-up, so that the program has a reference point.

Reply

89.
Adam
August 4, 2014 at 7:24 pm

Your link to the MIT paper is broken.

Reply

admin
August 4, 2014 at 9:18 pm

Thanks, it must have gotten moved. I fixed the link to point here: http://web.mit.edu/~jinstone/Public/filter.pdf. Its a terrific paper by far the best
explanation of a complementary filter Ive seen.

Reply

90.
deepak
September 23, 2014 at 4:58 am

help me to move mouse pointer using mpu 6050 pls help me

Reply

34 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

91.
sravan
October 7, 2014 at 6:06 am

how to detect the SHAKE using mpu 6050

Reply

92.
Omar
November 12, 2014 at 1:27 pm

Thanks so much to post this.


My arduino is running (COM 15) and the sketch in processing tell me:

java.lang.RuntimeException: Error opening serial port COM 15: Port busy.

I change this line:


short portIndex = 2;
Please help me

Reply

93.
Cheong
November 16, 2014 at 8:47 pm

Hi, just wanna show my appreciation on your blog, helped my project a lot. Thank you

keep up the good work (Y)

Reply

94.
rihab
November 30, 2014 at 5:12 am

I use MPU6050 to command my robot for different direction so its work normally but one problem that paused its stop working (blocked ) I dont know
were is exactly the problem .
please help me

Reply

95. Pingback: MPU-6050: DMP Data from i2cdevlib | Geek Mom Projects

96. Pingback: MPU-6050 Redux: DMP Data Fusion vs. Complementary Filter | Geek Mom Projects

97.
Aldo
December 8, 2014 at 3:56 am

Hi, please can you put a code using just l2cdevlib and arduino?
I am really fashinating by your work but I really apreciate if you can put a code showing XYZ angle without using of external processing but just using
arduino serial monitor.
this could be really useful for who, like me, is in a very low knowledge level.

Thank you in advance!

Reply

35 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

98.
ben
December 31, 2014 at 10:41 pm

When you say someone has already reverse-engineered the MPU-6050, isnt the datasheet / product spec freely available?

I understand you opted to start with Krodals driver, but can you elaborate the conflict you found between the latest FreeIMU (Fabio Varesano) build and
I2Cdevlib (Rowberg) ?

Not sure how a magnetometer fits in all this, but if a given accelerometer can measure 10khz max movements, would a gyro even be needed? Or is it noisy
even if used under its rated capacity?

Finally, regarding the 32-bit Processing2.0b8 sketch (ShowGY521Data) is it possible to rotate an actual 3d representation of the board? Or even a 3d object
from grabcad, yobi3d, tf3dm, etc?

Reply

admin
January 1, 2015 at 10:59 am

Hi Ben,
* At the time I wrote this, the firmware function calls had not been released to the general public by Invensense. I believe they have since been made
available.
* When I wrote this I found that the version of I2Cdevlib which was used by FreeIMU was older than the current version of I2Cdevlib. I2Cdevlib has
been updated much more recently than FreeIMU
* Without gyroscope or other complementary data, the accelerometer noise cannot be reduced by a higher sampling rate, only by averaging the
accelerometer readings over timescales longer than the noise spikes. The longer the time period you average over, the greater lag you get in
responsiveness of your data to the actual orientation of the IMU, which is generally undesirable. Also a longer averaging period may end up smoothing
out some of the shorter timescale features of your data. Even the complementary filter has a slight time lag which you can see if you read my post
titled MPU6050 Redux
* You can rotate any shape you want in the Processing sketch instead of drawing the rectangles, draw any shape you want and apply the appropriate
rotation computed by the IMU to your coordinate system.
Id recommend you look into retrieving MPU-6050 data directly from the DMP. It seems to be more responsive and accurate (as well as easier to
implement, as long as you avoid buffer overflow) than any other method Ive seen.
Debra

Reply

99.
Steve
January 1, 2015 at 3:10 am

Hi Debra, why the shapes in processing look like broken. not smooth,and just has the top and bottom surface?

Reply

admin
January 1, 2015 at 10:49 am

I think it has to do with the version of Processing you are using. I wrote the code with an older version, and have never gotten around to upgrading it. I
believe that one or more of the function calls does not work correctly in the latest version.

Reply

100.
Janaka
January 1, 2015 at 9:50 am

36 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

Hi Debra,
Thanks for sharing your project work online. Ive found it useful as I work on my own projects. Your kids are lucky to have a geek mum

May I suggest you use Git to version control your code and push it up to Github.com. This will allow others to add and improve the code while maintaining a
reference to each other as it evolves.

Thanks again.

Cheers,
Janaka

Reply

admin
January 1, 2015 at 11:00 am

Hi Janaka,
Thank you for the suggestion. You are right, of course, about using version control to maintain the code. I admit I havent been that organized about it,
but will look into it. It is a good idea.
Debra

Reply

101.
ed
January 9, 2015 at 8:46 am

Hi, I have a problem, Im a beginner with arduino. I would like to do something like this https://www.youtube.com/watch?v=S_URqUmaBUw
https://www.youtube.com/watch?v=7GVXqNLLH7Q I have Arduino uno r3, sensor shield V5, mpu6050 and 3 servos. I searched the internet but I cant
find. Please help me..

Reply

admin
January 10, 2015 at 11:53 am

Cool video. It shouldnt be too difficult to retrieve the rotation angles directly from the MPU6050 DMP (see http://www.geekmomprojects.com
/mpu-6050-dmp-data-from-i2cdevlib/) and use them to control the angles of three servos (see http://arduino.cc/en/Tutorial/sweep for an example of
controlling servos with Arduino). You will have to invest some time in learning Arduino programming. Good luck.

Reply

102.
lifelearner
January 11, 2015 at 12:24 pm

Hi,

I copied the code but the rectangle doesnt appear solid.. Only the top/bottom are shown, with the thickness planes not drawn, Any idea what could cause
this?

http://imgur.com/ABWpCI9

I dont see any errors in the Processing 2.2.1 panel, and the video card is good, so not sure what it could be.

Reply

admin

37 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

January 12, 2015 at 8:25 am

Hi,
Yes, that problem appeared when Processing moved to version 2.1.1. In the setup() function of the Processing sketch, theres a line:
stroke(0,0,0);
Try changing it to:
noStroke();
and see if that fixes your problem. Im taking a closer look at the issue, and will hopefully post an updated (fixed) version of the Processing code
within the next few days.
Debra

Reply

admin
January 12, 2015 at 8:36 am

Also, in the draw(), function, just under the statement:


background(0);
add the line:
lights();
That fixes it. Im uploading a fixed version of the Processing code now.

Reply

103.
Jarrod Roberson
January 11, 2015 at 2:06 pm

Which functions, I would be happy to fix it up and make a pull request, I need to get the accelerometer working.

Reply

104.
Ryan
January 11, 2015 at 3:00 pm

Could you please help me get your Processing sketch working?

Ive downloaded Processing 2.0 (for a Mac) and when I try running your code, I get errors. Ive downloaded the toxiclibs library as I saw was necessary
based off of another YouTube video.

Any help would be greatly appreciated!

Reply

admin
January 12, 2015 at 8:45 am

Im not sure what kind of errors youre seeing. Ive just fixed an error in the Processing code that showed up in Processing 2.1.1, which made the
rectangles display funny. You can see if that helps. Otherwise, Id need to know more specifics.

Reply

105.
Ryan
January 12, 2015 at 9:56 am

Sorry I didnt include my errors initially. I downloaded Processing 2.2.1, but am still getting the following error when I upload the Arduino sketch and run

38 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

the Processing sketch:


java.lang.RuntimeException: java.lang.RuntimeException: Error opening serial port /dev/cu.Bluetooth-Modem: Port busy

Please let me know if you have any ideas how to fix this.

Reply

admin
January 12, 2015 at 11:01 am

Sounds like a problem a with port access. Make sure you are accessing the correct port from the Processing sketch. The sketch uses an index into the
list of ports to access the serial port. On my computer the serial port is second in the list, so I set portIndex = 1. This can vary by computer, so you
might try a different value for portIndex, or you can try specifiying the name of the port explicitly (e.g. COM24). If you modify the Processing
sketch to print out the names of the ports, that may be helpful.

Reply

106.
Dmitriq
January 13, 2015 at 12:40 pm

Welcome colleagues. I use the library Jeff Rovberg angle Z yaw (ypr [0] = atan2 (2 * q [1] * q [2] 2 * q [0] * q [3], 2 * q [0] * q [0] + 2 * q [1] * q [1] 1))
will change from the influence of the slopes along the axes X Y, how to avoid it? Requires that the course was not dependent on the slopes, it is possible.
Sorry for my english, Im from Russia.

Reply

107.
Ryan
January 14, 2015 at 12:18 pm

I changed my portIndex to equal 0, and Im no longer getting the Port busy error. However, all of my rectangles are stationary and dont react when I move
my GY-521. Just to be sure, I need to have the Arduino sketch uploaded when I press Run in the Processing sketch, correct?

Reply

admin
January 14, 2015 at 1:34 pm

It shouldnt matter which sketch starts first. It sounds like the data is either not getting through to the Processing sketch or not getting through in a
readable format. You should make sure the serial baud rates match in Arduino and Processing, and add some print statements to the Processing
sketch to see if anything is coming through.

Reply

108.
HAKAN AYDIN
January 16, 2015 at 6:53 am

Hi admin.

I have a question about time constant of about 1seconds. in advance I apologize for my english. It is not good but i can do my best in order to tell my
question. So, How do you decide the time constant as 1 seconds and t ? Could you please tell me ?

Reply

39 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

admin
January 18, 2015 at 9:04 pm

Hi Hakan,
t was my approximate sampling rate I was getting updated angle data just about every 0.04 seconds. I know this because I printed out a time stamp
with each data set, and viewed it in the Arduino serial window. The time constant of 1 second was more or less eyeballing the fluctuations in the
acceleration to see how long they lasted, and picking a reasonable timescale just longer than that. I also saw that most other people who had used the
complementary filter has values of = /( + t) of 0.96 or 0.98, and worked backwards somewhat. is a measure of the relative importance of the
contribution of the gyroscope to the accelerometer. Shane Colton does a very good job in his paper (http://web.mit.edu/~jinstone/Public/filter.pdf) of
explaining how the complementary filter is really a high pass filter on the gyroscope data plus a low-pass filter on the accelerometer data. You should
probably look there for more detail.
Debra

Reply

109.
lifelearner
January 16, 2015 at 8:42 pm

Thanks, that works perfectly!

The noStroke() added the coloring to the other sides, and the lights() made the shading look right!

Reply

110.
ben
January 20, 2015 at 3:28 pm

Thanks, so is the basic idea of the dmp,


http://www.geekmomprojects.com/mpu-6050-dmp-data-from-i2cdevlib/

that it outputs data in quaternions format, which doesnt suffer from gimbal lock.. with the potential downside that the data isnt in a as readily usable
format, like angle x,y,z?

Interestingly, the Processing code for this non-dmp version, doesnt have any (atan) math in it it uses the angles directly from the Krodal code that sends it.
But looking a the Krodal code its not there either! Is the chip in a non-quaternions mode that sends angles directly? And is therefore susceptible to Gimbal
Lock?

Also, the processing code has a comment It gives the z-orientation data as given by the gyroscope, but I dont see z_gyr used anywhere. Is the z-axis angle
computed using the gyro data?

Reply

admin
January 22, 2015 at 8:28 pm

The DMP does the rotation angle calculations for you, which can save your program from having to do them. It is able to compute rotations of more
than 180 degrees, and can return the rotation angle information in many different formats, including quaternions, euler angles and yaw-pitch-roll
among others. You can use the functions in the I2CDevLib library to access the angles in all these different formats. Since orientation angles come
from the DMP which presumably uses quaternions or something similar in its calculations, you dont have to worry about gimbal-lock. You can look at
the examples in the I2CDevLib library to see how to call these functions.

With respect to Z-axis rotation (yaw) it is not shown in the comparison of gyroscope, accelerometer and complimentary filter data. Only pitch and
roll are shown in this example.

Reply

40 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

111.
Christian
January 22, 2015 at 11:48 am

In regards to converting the raw accelerometer and gyroscope data into units of [g] and [deg/sec], the data sheet says to divide by 16384 and 131 (as you
mentioned). Do you have any idea why these are the numbers were supposed to use to convert everything to meaningful data? For instance, why arent the
numbers 37 and 1000, or 4 and 598349?

Reply

admin
January 22, 2015 at 8:32 pm

The factors used to convert gyroscope and accelerometer data from the MPU-6050 are determined by the factors FS_SEL (gyroscope) and AFS_SEL
(accelerometer) which set the sensitivity and range of angles which can be detected by these sensors. The defaults for both FS_SEL and AFS_SEL are
0, which results in conversion factors of 131 and 16384, however setting different values of FS_SEL and AFS_SEL will require different conversion
factors. These are listed in the datasheet here: http://www.invensense.com/mems/gyro/documents/PS-MPU-6000A-00v3.4.pdf, on pages 12 and 13.

Reply

112.
Samuel
February 5, 2015 at 2:29 pm

Hi Debra, I found your blog very fun and useful! I am working on this project and I have followed all the steps required. However, each time I press the play
button on processing, the showgy521data always freezes and does not display anything for me.

Please advice

Reply

admin
February 5, 2015 at 2:39 pm

Are you running the Arduino sketch at the same time?

Reply

113.
Yahya Gilany
February 7, 2015 at 4:27 am

Hi Debra, Thanks a lot for your blog , the whole blog :))
I only have one question, shouldnt the sampling rate be calculated by the equation provided in the data sheet
Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)
where Gyroscope Output Rate = 8kHz when the DLPF is disabled (DLPF_CFG = 0 or 7), and 1kHz
when the DLPF is enabled
how can that get the 0.96 which youve explained to be an empirical number that you got by serial printing the time before and after every sample how is
that ?

Reply

admin
February 7, 2015 at 2:23 pm

41 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

Youre mixing up t = sampling rate and = time constant greater than timescale of typical accelerometer noise. It is that is used in the computation
of the complementary filter parameter. See page 13 of Shane Coltons writeup at http://web.mit.edu/~jinstone/Public/filter.pdf for the meaning of
used for the complementary filter computation.

Reply

114.
RI92F4
February 9, 2015 at 6:47 am

Hi there, I just want to say thank you very much for your thorough explanation and awesome job on the coding. I am doing my Final Year Project and your
posting help me a LOT!!!! Thanks!!!! Cant be more grateful ^^

Reply

115.
Ben Bryant
February 14, 2015 at 12:24 pm

Hi there,
Ive used your arduino code and dowloaded 32 bit processing, when trying to access the 3D rectangle blocks it throws up error codes, any idea why?

Im using a arduino uno & MPU 6050

many thanks

Ben

Reply

admin
February 14, 2015 at 12:29 pm

Not really enough information there, but it sounds like youre having an error on the Processing side not the Arduino side. Did you download the
toxiclibs for Processing?

Reply

admin
February 14, 2015 at 12:39 pm

Its an array out of bounds error at line 58 of the Processing code. I cant see the code where I am right now, but Im guessing its in the serial port
access where the program obtains a list of serial ports, and indexes into the list with variable portIndex. Try setting portIndex = 0 (instead of 1). If
thats not correct look for whatever array is referenced at line 58 of the code.

Reply

116.
Ben Bryant
February 14, 2015 at 12:31 pm

Its comes up with could not run sketch, arduino side is processing data as can see it withing the sketch monitor.

error code from processing is,

Exception in thread AWT-EventQueue-0 java.lang.ArrayIndexOutOfBoundsException: 1


at ShowGY521Data.setup(ShowGY521Data.java:58)
at processing.core.PApplet.handleDraw(PApplet.java:2361)
at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862)

42 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1289)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1300)
at javax.media.opengl.Threading.invoke(Threading.java:193)
at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
at javax.media.opengl.awt.GLCanvas.paint(GLCanvas.java:595)
at sun.awt.RepaintArea.paintComponent(Unknown Source)
at sun.awt.RepaintArea.paint(Unknown Source)
at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 1
at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206)
at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
at javax.media.opengl.Threading.invoke(Threading.java:191)
at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
at processing.opengl.PJOGL.requestDraw(PJOGL.java:688)
at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1651)
at processing.core.PApplet.run(PApplet.java:2256)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at ShowGY521Data.setup(ShowGY521Data.java:58)
at processing.core.PApplet.handleDraw(PApplet.java:2361)
at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1289)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1300)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Could not run the sketch (Target VM failed to initialize).

43 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

For more information, read revisions.txt and Help ? Troubleshooting.

thanks again

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *

Email *

Website

Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code>
<del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Confirm you are NOT a spammer

Notify me of follow-up comments by email.

Notify me of new posts by email.

Search:

Top Posts & Pages

Gyroscopes and Accelerometers on a Chip


MPU-6050: DMP Data from i2cdevlib
MPU-6050 Redux: DMP Data Fusion vs. Complementary Filter
The "Halfway" - A Self-Balancing Scooter

Recent Posts

Building PlotClock
Halloween Photoresistor Circuit
MPU-6050 Redux: DMP Data Fusion vs. Complementary Filter
The Halfway A Self-Balancing Scooter

Archives

December 2014 (1)


November 2014 (1)
June 2014 (2)
April 2014 (1)
February 2014 (2)
October 2013 (1)
September 2013 (2)
August 2013 (1)
June 2013 (2)
May 2013 (1)
April 2013 (3)
March 2013 (3)
February 2013 (4)
January 2013 (4)
December 2012 (1)

44 de 45 03/03/2015 11:22
Gyroscopes and Accelerometers on a Chip | Geek Mom Projects http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-...

Categories

3D Printing (3)
Angular Momentum (3)
Arduino (11)
CAD (1)
Circuits (3)
e-Textiles (3)
Fritzing (1)
Gyroscopes (6)
Jr. FLL (2)
LEGO (4)
Lilypad (3)
Mindstorms (2)
Printrbot (3)
Processing (3)
Raspberry Pi (3)
Robots (1)
Scratch (2)
Segway (1)
Squishy Circuits (1)
Uncategorized (1)
WiiChuck (2)
Wordpress (1)

2015 Geek Mom Projects. All rights reserved.


Design by picomol. Powered by WordPress.

45 de 45 03/03/2015 11:22

You might also like