ESPuser Posted April 22, 2016 Report Share Posted April 22, 2016 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: What's wrong and how can I fix this? Thanks lapedNok 1 Quote Link to comment Share on other sites More sharing options...
pacomillet Posted May 3, 2016 Report Share Posted May 3, 2016 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! Quote Link to comment Share on other sites More sharing options...
ESPuser Posted May 7, 2016 Author Report Share Posted May 7, 2016 I figured it out. I needed to change the update interval to a much faster one! 4ms works fine Quote Link to comment Share on other sites More sharing options...
vivekvarma98 Posted June 2, 2019 Report Share Posted June 2, 2019 I didn't understand what you meant by update interval. Where and how do you change that? Quote Link to comment Share on other sites More sharing options...
i3130002 Posted August 26, 2019 Report Share Posted August 26, 2019 On 5/7/2016 at 9:02 PM, ESPuser said: I figured it out. I needed to change the update interval to a much faster one! 4ms works fine I don't get why this might make a difference ! Can you please explain ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.