SOLVED: I "solved" the problem by cycling my Arduino's power and I haven't had an issue since. I would still like to figure out what was going on. I still think it's something in that MPU6050 library with getMotion. But anyway, if anyone eventually has any ideas post it up. Thanks
Original question: I'm using an MPU6050 accelerometer/gyro that controls a servo through a Mega.
QSTN: The sensor simply stops reading after an arbitrary time, usually between 2-4 minutes. I have to reinitialize the serial monitor/MPU to get it to work again which is not good. I suspect it has something to do with getMotion but I can't put my finger on it.
Any ideas? Thanks. Code is below:
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Servo.h"
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
Servo servo1;
int val;
int prevVal;
void setup()
{
Wire.begin();
Serial.begin(38400); //38400
Serial.println("Initializing MPU6050");
mpu.initialize();
Serial.println(mpu.testConnection() ? "CONNECTED" : "Connection failed");
servo1.attach(9);
}
void loop()
{
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
val = map(ay, -17000, 17000, 0, 179);
if (val != prevVal)
{
servo1.write(val);
prevVal = val;
Serial.println(val);
}
delay(75);
}