Go Down

Topic: gyro LPR530al (Read 1 time) previous topic - next topic

Hi i'am trying connect this gyro with arduino and not mutch luck  =(
Pls has anybody sample code how to get data from gyro?

AWOL

#1
Jun 14, 2012, 03:23 pm Last Edit: Jun 14, 2012, 03:52 pm by AWOL Reason: 1
What have you got, and what doesn't it do that you want it to?
(or, what does it do that you don't want it to?)

What experience have you got with gyros?

Code: [Select]
int x = analogRead (X_AXIS) - x_null;
Where "x_null" is the average stationary reading.
If you leave it at zero, it'll just return the raw value from the device.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Hi i've got zero experience with gyro ;-) but i can undestand teory of mems gyroskopes;-)
this is my arduino code:

int x,y;
float cas, hodnota_x, hodnota_y;
void setup(){
  Serial.begin(9600);
  }
void loop(){
  x = analogRead(2);
  y = analogRead(3);
  cas = millis();
  //hodnota_x =  (x/1.0323)*cas/1000;
  //hodnota_y =  (y/1.0323)*cas/1000;
  Serial.print("osa x = ");
  Serial.print(x);
  Serial.print("  ");
  Serial.print("osa y = ");
  Serial.println(y);
  delay(500);
}
 


--------
i think i connected the gyro with arduino corectly.
i get data from sezor but i need convert it to degrees per seconds °/s :) can you know how i make it???

AWOL

The data sheet will specify the sensitivity of the device in millivolts per degree (or radians) per second.
You know what voltage you're reading, so just do the arithmetic.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


The data sheet will specify the sensitivity of the device in millivolts per degree (or radians) per second.
You know what voltage you're reading, so just do the arithmetic.


can you write me aritmethic equation ? i don't know how  :smiley-slim:



The data sheet will specify the sensitivity of the device in millivolts per degree (or radians) per second.
You know what voltage you're reading, so just do the arithmetic.


can you write me aritmethic equation ? i don't know how  :smiley-slim:



here is my code:

#include <Wire.h>   //knihovna I2C
#include <math.h>   //knihovna Math

unsigned long casovac=0;
unsigned long cas=0;
//kalibrace
long resultGyroX;//x-axis
long resultGyroY;//y-axis

//
//gyros
float gyroZeroX;//x-axis
int gyroXadc;
float gyroXrate;
float gyroXangle;

float gyroZeroY;//y-axis
int gyroYadc;
float gyroYrate;
float gyroYangle;

void setup(){
  Serial.begin(9600);
  gyroZeroX = calibrateGyroX();
  gyroZeroY = calibrateGyroY();
  delay(100);
 
  }
void loop(){
  cas = millis();
  gyroXadc = analogRead(2);
  gyroYadc = analogRead(3);
  gyroXrate = (gyroXadc-gyroZeroX)/1.0323;//(gyroXadc-gryoZeroX)/Sensitivity - in quids              Sensitivity = 0.00333/3.3*1023=1.0323
  gyroXangle += gyroXrate*cas/1000;//Without any filter
  gyroYrate = (gyroYadc-gyroZeroY)/1.0323;//(gyroYadc-gryoZeroX)/Sensitivity - in quids              Sensitivity = 0.00333/3.3*1023=1.0323
  gyroYangle += gyroYrate*cas/1000;//Without any filter
  cas = millis() - casovac;
  casovac = millis();
  Serial.print("cas = ");
  Serial.print(casovac);
  Serial.print("; osa x = ");
  Serial.print(gyroXangle);
  Serial.print(" ; ");
  Serial.print("osa y = ");
  Serial.println(gyroYangle);
 
  gyroXangle = 0;
  gyroYangle = 0;
}
 
int calibrateGyroX()
{
  for(int i=0;i<100;i++)
  {
    resultGyroX += analogRead(2);
    delay(1);
  }
  resultGyroX = resultGyroX/100;
  return resultGyroX;
}

int calibrateGyroY()
{
  for(int i=0;i<100;i++)
  {
    resultGyroY += analogRead(3);
    delay(1);
  }
  resultGyroY = resultGyroY/100;
  return resultGyroY;
}

Go Up