Hi,
I recently purchased the LISY300 gyro sensor from Sparkfun.com. I have a project where I need the angle data from the gyro. I have already found out how to get the rotational rate from this tutorial:
http://wiring.org.co/learning/basics/gyrolisy300al.html I have tried to get the gyro's angle data through my own programming, but I am not that good. I will post the code that I tried to use to get the angle data from the gyro. The code is a combination of a few different sources:
http://arduino.cc/playground/Main/Gyrohttp://wiring.org.co/learning/basics/gyrolisy300al.htmlIf you could please help me interface the LISY300 gyro with Arduino to get the angular data... THANKS
int gyroPin = 0; //Gyro is connected to analog pin 0
float gyroVoltage = 3.3; //Gyro is running at 3.3V
float gyroZeroVoltage = 1.65; //Gyro is zeroed at 1.65V
float gyroSensitivity = .0033; //Our example gyro is mV/deg/sec
float rotationThreshold = 1; //Minimum deg/sec to keep track of - helps with gyro drifting
int pinPowerDown = 2; // digital pin for Power Down mode
// LOW = Normal, HIGH = Power down
float currentAngle = 0; //Keep track of our current angle
void setup() {
pinMode(pinPowerDown, OUTPUT);
digitalWrite(pinPowerDown, LOW); // set gyroscope to Normal
Serial.begin (9600);
}
void loop() {
//This line converts the 0-1023 signal to 0-5V
float gyroRate = (analogRead(gyroPin) * gyroVoltage) / 1023;
//This line finds the voltage offset from sitting still
gyroRate -= gyroZeroVoltage;
//This line divides the voltage we found by the gyro's sensitivity
gyroRate /= gyroSensitivity;
//Ignore the gyro if our angular velocity does not meet our threshold
if (gyroRate >= rotationThreshold || gyroRate <= -rotationThreshold) {
//This line divides the value by 100 since we are running in a 10ms loop (1000ms/10ms)
gyroRate /= 10;
currentAngle += gyroRate;
}
//Keep our angle between 0-359 degrees
if (currentAngle < 0)
currentAngle += 360;
else if (currentAngle > 359)
currentAngle -= 360;
//
Serial.println(currentAngle, DEC);
delay(10);
}