Hi,
We have A problem with our gyro,
When we press the "Serial monitor", we're getting unstable values (descending/ascending).
here's some pictures to demonstrate our problem.
our gyro program:
int gyroPin = 2; //Gyro is connected to analog pin 0
float gyroVoltage = 5; //Gyro is running at 5V
float gyroZeroVoltage = 2.5; //Gyro is zeroed at 2.5V
float gyroSensitivity = .007; //Our example gyro is 7mV/deg/sec
float rotationThreshold = 1; //Minimum deg/sec to keep track of - helps with gyro drifting
float currentAngle = 0; //Keep track of our current angle
void setup() {
Serial.begin (9600);
}
void loop()
{
static unsigned long lastTime = 0;
float gyroRate = ((analogRead(gyroPin) * gyroVoltage) / 1023)+0.002;
gyroRate -= gyroZeroVoltage;
gyroRate /= gyroSensitivity;
unsigned long currentTime = millis();
unsigned long deltaTime = currentTime - lastTime;
if (gyroRate >= rotationThreshold || gyroRate <= -rotationThreshold) {
gyroRate = (gyroRate*deltaTime)/1000;
lastTime = currentTime;
currentAngle += gyroRate;
}
if (currentAngle < 0)
currentAngle += 360;
else if (currentAngle > 359)
currentAngle -= 360;
//DEBUG
Serial.println(currentAngle);
}