1

I'm using an MPU-6050 chip in order to calculate orientation. It is connected to an Arduino Pro Mini. I am using code written by Jeff Rowberg that uses the internal DMP. The 57600 baud rate crashes the sketch after a minute, so I changed it to 9600. Setting TWBR to 14 did nothing. I also modified the MPU6050_6Axis_MotionApps20.h file in order to decrease the FIFO rate. It didn't really help. Here's some sample output when the sensor is lying stationary on a desk:

0.80:-4.15:64.50
0.80:-4.15:64.51
0.80:-4.15:64.51
0.80:-4.15:64.51
0.80:-4.15:64.51
0.80:-4.15:64.51
0.80:-4.15:64.51
0.80:-4.15:64.51
0.80:-4.15:64.51
0.80:-4.15:64.50
0.80:-4.15:64.50
FIFO overflow!
0.81:-4.15:64.50
0.81:-4.15:64.50

I suppose that FIFO overflow doesn't bother me that much, but in my opinion, it's inefficient. I'm not sure what I'm doing wrong that causes the FIFO overflow. Any ideas?

Edit 1: Code

#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
MPU6050 mpu;
bool dmpReady = false;
uint8_t mpuIntStatus, devStatus;
uint16_t packetSize, fifoCount;
uint8_t fifoBuffer[64];
Quaternion q;
VectorFloat gravity;
float euler[3], ypr[3], py, pp, pr;
unsigned long last_read_time;
int16_t ax, ay, az, gx, gy, gz;
char dataOut[256];
volatile bool mpuInterrupt = false;
void dmpDataReady() {
  mpuInterrupt = true;
}
void setup() {
  Wire.begin();
  //TWBR = 12;
  Serial.begin(9600);
  mpu.initialize();
  mpu.testConnection();
  mpu.dmpInitialize();
  mpu.setDMPEnabled(true);
  attachInterrupt(0, dmpDataReady, RISING);
  mpuIntStatus = mpu.getIntStatus();
  dmpReady = true;
  packetSize = mpu.dmpGetFIFOPacketSize();
}
void loop() {
  const float RADIANS_TO_DEGREES = 57.2958;
  if (!dmpReady) return;
  unsigned long t_now = millis();
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
  while (!mpuInterrupt && fifoCount < packetSize) {
    mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    unsigned long t_now = millis();
  }
  mpuInterrupt = false;
  mpuIntStatus = mpu.getIntStatus();
  fifoCount = mpu.getFIFOCount();
  if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
    mpu.resetFIFO();
    Serial.println(F("FIFO overflow!"));
  } else if (mpuIntStatus & 0x02) {
    while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
    mpu.getFIFOBytes(fifoBuffer, packetSize);
    fifoCount -= packetSize;
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
    Serial.print(ypr[2]*RADIANS_TO_DEGREES, 2);
    Serial.print(":");
    Serial.print(ypr[1]*RADIANS_TO_DEGREES, 2);
    Serial.print(":");
    Serial.println(ypr[0]*RADIANS_TO_DEGREES, 2);
  }
}

SDA is wired to A4

SCL is wired to A5

INT is connected to Pin 2

The data is usually surprisingly stabile, only differing by 0.01 degrees per reading. However, sometimes, there'll be one reading that is unlike all previous and following readings. Notice the reading: "31.09:-15.07:-111.05. The sensor was stationary the entire time. I have o idea where these strange readings come from.

  • 2
    The problem is either in the code or the wiring. Your description of those is insufficient to even take a guess. – Jasmine Dec 29 '14 at 23:29
  • In addition, sometimes, it'll throw out random data that is totally wrong (order of magnitude sometimes). I'm baffled. Would you like me to post my code? – faeophyta Dec 29 '14 at 23:32
  • 2
    Yes please include some code and a photo or diagram of the wiring, or a sufficient description of what pins are hooked to what. We can "assume" that you wired it "the right way" but that's a bit of a stretch since there's multiple ways to use that thing. I have used it and when it's working right, the numbers you get are all "reasonable" never crazy. But it is noisy, even sitting on a desk. – Jasmine Dec 29 '14 at 23:38
  • @Jasmine, added code, a screenshot, and which pins are where. – faeophyta Dec 30 '14 at 0:12
  • could you please try again, but this time without quaternions and other calculations. Try to write a minimal code to get the reading from the device. Only that. – Dave Dec 30 '14 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.