Jump to content
I2Cdevlib Forums
ESPuser

Periodically noise spikes on the MPU-6050. What causes this?

Recommended Posts

Hi!

I'm working on a project where I'm using the MPU6050s roll axis. The MPU is connected to an ESP8266 running Arduino code. The sensor itself is working great, but some times (about every minute) the MPU outputs huge noise spikes even when it's laying flat on the table. This mess up the whole readings. Here's the ESP8266 code:

//#define DEBUG
#include <I2Cdev.h>
#include <MPU6050_6Axis_MotionApps20.h>
#include <Wire.h>
#include <Ticker.h>


Ticker TickerMPU1;


MPU6050 mpu(0x68);
//MPU6050 mpu(0x69); // <-- use for AD0 high




void setup() {
  // initialize serial communication
  Serial.begin(250000);
  pinMode(0, OUTPUT);
  digitalWrite(0, LOW);
  delay(1000);
  // join I2C bus (I2Cdev library doesn't do this automatically)
  Wire.begin(4, 12); // (SDA, SCL)
  Wire.setClock(400000);
  mpuInit(mpu);
  delay(15000);
  TickerMPU1.attach_ms(20, accelerometer1);
}

void accelerometer1()
{
  mpuGetValues(mpu);
}

void loop() 
{
  yield(); // = delay(0); Needed to prevent Watchdog reset
}


void mpuInit(MPU6050 &MpuObject)
{
  uint8_t devStatus;

  // initialize serial communication

  do
  {

    // initialize device
    MpuObject.initialize();
    // verify connection
      Serial.println(MpuObject.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

    // load and configure the DMP
    devStatus = MpuObject.dmpInitialize();

    // supply your own gyro offsets here, scaled for min sensitivity
    MpuObject.setXGyroOffset(220);
    MpuObject.setYGyroOffset(76);
    MpuObject.setZGyroOffset(-85);
    MpuObject.setZAccelOffset(1788); // 1688 factory default for my test chip

    // make sure it worked (returns 0 if so)
    if (devStatus == 0)
    {
      // turn on the DMP, now that it's ready
      Serial.println("devStatus = 0");
      MpuObject.setDMPEnabled(true);

    }
    else
    {
      Serial.println("\n\n\n\n\nFault\n\n\n\n\n\n");
      digitalWrite(0, HIGH);
      delay(200);
      digitalWrite(0, LOW);
    }
  } while (devStatus != 0);

  /* Serial.println("MPU6050 delay started (15 sec)");
  delay(15000); // Needed for stabilisation
  Serial.println("initialization finished"); */
}


void mpuGetValues(MPU6050 &MpuObject)
{
  Quaternion q;           // [w, x, y, z] quaternion container
  VectorFloat gravity;    // [x, y, z]    gravity vector

  float ypr[3];           // [yaw, pitch, roll]   yaw/pitch/roll container and gravity vector
  uint8_t fifoBuffer[64]; // FIFO storage buffer
  uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
  uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
  uint16_t fifoCount;     // count of all bytes currently in FIFO


  // get expected DMP packet size for later comparison
  packetSize = mpu.dmpGetFIFOPacketSize();

  // get INT_STATUS byte
  mpuIntStatus = mpu.getIntStatus();

  // get current FIFO count
  fifoCount = mpu.getFIFOCount();

  // check for overflow (this should never happen unless our code is too inefficient)
  if ((mpuIntStatus & 0x10) || fifoCount == 1024)
  {
    // reset so we can continue cleanly
    mpu.resetFIFO();
    // Serial.println(F("FIFO overflow!"));

    // otherwise, check for DMP data ready interrupt (this should happen frequently)
  }
  else if (mpuIntStatus & 0x02)
  {
    // wait for correct available data length, should be a VERY short wait
    while (fifoCount < packetSize)
      fifoCount = mpu.getFIFOCount();

    // read a packet from FIFO
    mpu.getFIFOBytes(fifoBuffer, packetSize);

    // display Euler angles in degrees
    mpu.dmpGetQuaternion(&q, fifoBuffer);
    mpu.dmpGetGravity(&gravity, &q);
    mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);

    Serial.println(ypr[2] * 360/M_PI + 180);

  }
}


I've copied all the readings into MS Excel, and plotted it. A reading was done every 20 millisecond. I'm not using the interrupt pin. Here's what the noise looks like:

VgZoawY.png

 

What's wrong and how can I fix this? Thanks :)

Share this post


Link to post
Share on other sites

Hi, I have similar problem. I'm capturing data using fscanf in Matlab from arduino UNO and MPU6050 and I'm saving data during several hours and get a lot of spikes. You can see the images attached. (Axis X is in seconds)

 

some lines in my arduino code :

 

#include "I2Cdev.h"
#include "MPU6050.h"
 
....
 
void setup() {
  
....
 
    #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
        Wire.begin();
    #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
        Fastwire::setup(400, true);
    #endif
    Serial.begin(115200); 
 
....
//config MPU6050
writeByte(MPU6050_ADDRESS, PWR_MGMT_1, 0x00);
writeByte(MPU6050_ADDRESS, CONFIG, 0x01);  // Set Low Pass Filter to 188 Hz (1 KHz)
writeByte(MPU6050_ADDRESS, SMPLRT_DIV, 0x09);
 
 
void loop() {
   
 
uint32_t deltat = millis() - count;
 
if(deltat >0.01) {
 
 getdataIMU();
Serial.print(ax,8);
//Serial.print(millis());
Serial.print("\t"); // Use this character in MATLAB
Serial.print(ay,8);
Serial.print("\t"); // Use this character in MATLAB
Serial.print(az,8);
Serial.print("\t"); // Use this character in MATLAB
Serial.print(gx,8);
Serial.print("\t"); // Use this character in MATLAB
Serial.print(gy,8);
Serial.print("\t"); // Use this character in MATLAB
Serial.print(gz,8);
Serial.print("\t"); // Use this character in MATLAB
Serial.println(temperature,8);
 
count = millis();
 
}
 
 
Matlab code:
 
 s = serial('COM4'); 
    set(s, 'InputBufferSize', 16384);
    set(s, 'FlowControl', 'none');
    set(s, 'BaudRate', 115200);
    set(s, 'Parity', 'none');
    set(s, 'DataBits', 8);
    set(s, 'StopBit', 1);
    %set(s, 'Timeout',4);   
    fopen(s);  
    s.ReadAsyncMode = 'continuous';
    readasync(s);    
 
....
 
 sSerialData = fscanf(s); %read sensor                   
 t = strsplit(sSerialData,'\t'); % same character as the Arduino code
mData(i,1) = str2double(t(1));
....
 
 
Why this occurs? some idea?
 
 
Thank you very much!
 
 
 
 
 
 
 
 
 

post-4031-0-47208300-1462281298_thumb.jpg

post-4031-0-81767800-1462281299_thumb.jpg

Share this post


Link to post
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...