Jump to content
I2Cdevlib Forums

DMP without interrupts


Recommended Posts

  • 2 months later...

I have discovered a solution to this problem myself...

CHANGE THIS:

 

while (!mpuInterrupt && fifoCount < packetSize)

{}

 

IN THIS:

 

while (fifoCount < packetSize)

 

{

         fifoCount = mpu.getFIFOCount();

}

 

Now you can delete the line with "AttachInterrupt" in the setup and the MPU6050 should work properly.

 

Sorry for the english.

Link to comment
Share on other sites

  • 8 months later...

Hi,

I also tried to use the MP 6050 without the use of interrupts. I have some quite demanding interrupts going on in my project already and merely require the MPU data at roughly 20 Hz.

 

I basically adapted the code from the MPU6050_DMP6 example, which runs fine on my Arduino Mini Pro. However, when I run my code, the output does not change with MPU movement (Euler for example always returns 180, 0, 180). I then found out, that the fifoPacket does not contain any values by using this code (which again runs fine in the example). Did I forget something? Do I have to change some MPU settings, when using it without interrupts?

 

I would really appreciate your feedback!

#include "I2Cdev.h"

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    #include "Wire.h"
#endif

#include <MPU6050_6Axis_MotionApps20.h>

uint16_t fifoCount;
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
float euler[3];
uint8_t fifoBuffer[64]; // FIFO storage buffer

Quaternion q;

MPU6050 mpu;


void setup() {

  #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
      Wire.begin();
      TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
  #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
      Fastwire::setup(400, true);
  #endif
  
  Serial.begin(38400);

  mpu.initialize();

  mpu.setDMPEnabled(true);
  
  packetSize = mpu.dmpGetFIFOPacketSize();

}

void loop() {

  while (fifoCount < packetSize) {
    //do stuff
    Serial.println("nix");
  }
  
  fifoCount = mpu.getFIFOCount();
  
  if (fifoCount == 1024) {
    mpu.resetFIFO();
  } else {
      while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
      
      mpu.getFIFOBytes(fifoBuffer, packetSize);
      
      //fifoCount -= packetSize;
      
      //mpu.dmpGetQuaternion(&q, fifoBuffer);
      //mpu.dmpGetEuler(euler, &q);
      
      
      for (int i = 1; i < 64; i++) {
        Serial.print(fifoBuffer[i]);
        Serial.print(" ");
      }
    
  }

  Serial.print(packetSize);
  Serial.println(" ");
   
  //delay(20);

}
Link to comment
Share on other sites

Should your code be:

  while (fifoCount < packetSize) {
    //do stuff
    Serial.println("nix");
 fifoCount = mpu.getFIFOCount();

  }
  
 

As you can't escape your while loop without updating your fifoCount?

 

Also do a "mpu.resetFIFO();" to make sure the buffer is empty for the next packet to start from the beginning for the next read.

 

I'm working on the same thing. I just need ypr "p" value, i wish i could just get it from a register in the IMU instead of transferring so much data. I just started coding my sketch but hopefully 2 are better then one on this. I have much to learn on this IMU.

Link to comment
Share on other sites

Here ya go, works nice, prints "nix" while waiting for the buffer to exceed normal packet size.

/*
I2Cdev device library code is placed under the MIT license
Copyright (c) 2012 Jeff Rowberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
*/
  
 // if programming failed, don't try to do anything
    if (!dmpReady) return;

    while (fifoCount < packetSize) {
    //do stuff
    Serial.println("nix");
    fifoCount = mpu.getFIFOCount();
  }
  
  if (fifoCount == 1024) mpu.resetFIFO(); 
  
  else {
      fifoCount = mpu.getFIFOCount();
      
      mpu.getFIFOBytes(fifoBuffer, packetSize);

      mpu.resetFIFO(); 
      
      fifoCount -= packetSize;
      
      mpu.dmpGetQuaternion(&q, fifoBuffer);
      mpu.dmpGetEuler(euler, &q);
      
 /*     
      for (int i = 1; i < 64; i++) {
        Serial.print(fifoBuffer[i]);
        Serial.print(" ");
      }
   */

      Serial.print("euler\t");
      Serial.print((euler[0] * 180/M_PI));
      Serial.print("\t");
      Serial.print(euler[1] * 180/M_PI);
      Serial.print("\t");
      Serial.println(euler[2] * 180/M_PI);
 
      // blink LED to indicate activity
      blinkState = !blinkState;
      digitalWrite(LED_PIN, blinkState);
  } 
Link to comment
Share on other sites

  • 4 months later...

All the codes of this page are hanging/freezing after about 20 seconds. Does anybody knows why?

 

 

 

//Código do MPU6050.
#include "MPU6050_6Axis_MotionApps20.h"
MPU6050 mpu;
uint8_t mpuIntStatus;
uint16_t packetSize;
uint16_t fifoCount;
uint8_t fifoBuffer[64];
Quaternion q;
VectorFloat gravity;
float ypr[3];


void setup() {


  //Código do MPU6050.
    Wire.begin();
    TWBR = 24;
    mpu.initialize();
    mpu.dmpInitialize();
    mpu.setXAccelOffset(-1343);
    mpu.setYAccelOffset(-1155);
    mpu.setZAccelOffset(1033);
    mpu.setXGyroOffset(19);
    mpu.setYGyroOffset(-27);
    mpu.setZGyroOffset(16);
    mpu.setDMPEnabled(true);
    packetSize = mpu.dmpGetFIFOPacketSize();


  //Por algum motivo se utilizar "9600" aparece erro "FIFO overflow!".
    //COMENTAR_OFICIAL
    Serial.begin(115200);


}


void loop() {
  while (fifoCount < packetSize) {
    //do stuff
  
    fifoCount = mpu.getFIFOCount();
  }
  
  if (fifoCount == 1024) mpu.resetFIFO(); 
  
  else {
      fifoCount = mpu.getFIFOCount();
      
      mpu.getFIFOBytes(fifoBuffer, packetSize);


      mpu.resetFIFO(); 
      
      fifoCount -= packetSize;


        mpu.dmpGetQuaternion(&q, fifoBuffer);
        mpu.dmpGetGravity(&gravity, &q);
        mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
        
        //COMENTAR_OFICIAL
        Serial.print("ypr\t");
        Serial.print(ypr[0]*180/PI);
        Serial.print("\t");
        Serial.print(ypr[1]*180/PI);
        Serial.print("\t");
        Serial.print(ypr[2]*180/PI);
        Serial.println();
      




    
  } 


}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...