MPU6050 (Gy-521) with FreeIMU Library

I have problems with my Gy-521 Board and the FreeIMU Library (
With the FreeIMU_raw example from the library I get the raw values wich seem to be correct. But using the Quaternion example I get a mix of numbers and letters from the serial monitor instead of Quaternion values. And using the yaw_pitch_roll example I only get "Yaw: nan Pitch: nan Roll: nan" from the serial monitor.
Is it possible that there is an error in the board or does anybody know where the mistake is?

Thanks for your help

Did you run the i2c_scanner ? and perhaps the sketch for raw values ?

Problem solved by reinstalling all libraries.
Thanks for your answer.


hmmm, I have the same problem. But sadly, reinstalling didn't do the trick for me. :frowning:

I tried with an Arduino Uno and an Arduino Nano. But always the same with the Yaw_Pitch_Roll example. All the values are nan.

I did quite a bit of testing and found out some very peculiar behavior. I am an absolute code-noob, so it doesn't make any sense to me. But maybe some of you Arduino-Masters understand where the problem lies. So here are my observations:

  • When I reduce the number of Serial.print() operations within the loop() to just three, it works and the values from the my3IMU.getYawPitchRoll() function are being displayd.
  • But as soon as I introduce a fourth Serial.print() all the values turn to nan
  • The same goes for global variables, not for local variables though. So I can define as many float or int variables within the loop() as I want, but as soon as I set more than three global variables, the yaw-pitch-roll values are "nan"
  • Serial.print() and setting global variables behave similarly. So as soon as I have more than three of them (for example 3 global variables and 1 Serial.print() or 2 global variables and 2 Serial.print() ) I loose the yaw-pitch-roll values
  • I can set the value for global variables as often as I want within the loop(), as long as there are no more than three

Does that make any sense to you?
It sure doesn't to me. So any help would appreciated!


Perhaps you have run out of memory on your arduino. Can you post the actual code you are using.

Sure, the code below is the one I am using. Like that it is working fine.
But as soon as you include the fourth Serial.print() that is currently commented out, you get "nan" as a value

#include <ADXL345.h>
#include <bma180.h>
#include <HMC58X3.h>
#include <ITG3200.h>
#include <MS561101BA.h>
#include <I2Cdev.h>
#include <MPU60X0.h>
#include <EEPROM.h>

//#define DEBUG
#include "DebugUtils.h"
#include "CommunicationUtils.h"
#include "FreeIMU.h"
#include <Wire.h>
#include <SPI.h>

float ypr[3]; 

FreeIMU my3IMU = FreeIMU();

void setup() { 

void loop() { 

  Serial.print(ypr[0]);  //Print the first of the tree yaw-pitch-roll values

  //Serial.print("   ");
  Serial.print("   ");
  Serial.println("   ");


There is nothing obviously wrong with you program. You maybe ran out of memory. Do you really need all that stuff you included ?

Do you really need all that stuff you included ?

You tell me :~

But honestly, I have no idea. I am quite new to programming. And I just used the available example. But I will test if I can lose some of these libraries by trial and error...

well, in the console at the bottom it says: Binary Sketch Size is 20.002 Bytes (of a maximum of 30.720 Bytes).

And running out of memory wouldn't explain why I can define as many local variables within the loop() function as I want but not more than three global ones. Or would it?

confusing!!! :astonished:

If your symptoms really are as you describe them, then running out of memory would seem to be the only plausible explanation.

On the other hand, it is possible that you have misinterpreted the symptoms, somehow.

hmmm, I just checked with MemoryFree.h and there seems to be enough memory left (around 1300). :roll_eyes: