Pages: [1]   Go Down
Author Topic: Convert ITG-3200's raw readings into degrees/sec  (Read 1165 times)
0 Members and 1 Guest are viewing this topic.
Dallas, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 170
Check out my blog on your smartphone!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have been scouring the internet for solutions to this question for a long time.I can read the raw signals using this code here:
Code:
void itgWrite(char address, char registerAddress, char data){
  Wire.beginTransmission(address);
  Wire.write(registerAddress);
  Wire.write(data);
  Wire.endTransmission();
}
unsigned char itgRead(char address, char registerAddress){
  unsigned char data=0;
  Wire.beginTransmission(address);
  Wire.write(registerAddress);
  Wire.endTransmission();
  Wire.beginTransmission(address);
  Wire.requestFrom(address, 1);
  if(Wire.available()){
    data = Wire.read();
  }
  Wire.endTransmission();
  return data;
}
int readX(void){
  int data=0;
  data = itgRead(itgAddress, GYRO_XOUT_H)<<8;
  data |= itgRead(itgAddress, GYRO_XOUT_L); 
  return data;
}
int readY(void){
  int data=0;
  data = itgRead(itgAddress, GYRO_YOUT_H)<<8;
  data |= itgRead(itgAddress, GYRO_YOUT_L); 
  return data;
}
int readZ(void){
  int data=0;
  data = itgRead(itgAddress, GYRO_ZOUT_H)<<8;
  data |= itgRead(itgAddress, GYRO_ZOUT_L); 
  return data;
}

in the 3200 datasheet it says: Digital-output X-, Y-, and Z-Axis angular rate sensors (gyros) on one integrated circuit with a sensitivity of 14.375 LSBs per °/sec and a full-scale range of ±2000°/sec.
Im not sure how to use the 14.375 LSBs per degrees/sec to give me my converted reading. can somebody please help me get and understanding of how to convert my readings.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12524
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

in the 3200 datasheet it says: Digital-output X-, Y-, and Z-Axis angular rate sensors (gyros) on one integrated circuit with a sensitivity of 14.375 LSBs per °/sec and a full-scale range of ±2000°/sec.
Im not sure how to use the 14.375 LSBs per degrees/sec to give me my converted reading. can somebody please help me get and understanding of how to convert my readings.

It means that the value it supplies is in units of 1/14.375 degrees per second. So take the value it supplies, divide that by 14.375, and that is the number of degrees per second.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Dallas, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 170
Check out my blog on your smartphone!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried that but it goes over 2000 degrees per second, which is its maximum... and I can spin the board about the x or y axis approximately 360 degrees per second and itll read ~1000 degrees/sec.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12524
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not sure what the code you posted is. Do you have an example or demo sketch from a reliable source (such as the hardware supplier) showing how to read from the sensor?

Logged

I only provide help via the forum - please do not contact me for private consultancy.

Dallas, TX
Offline Offline
Full Member
***
Karma: 0
Posts: 170
Check out my blog on your smartphone!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, in my first post I gave you all the subroutines because in the loop I would just call the readY, readX, readZ subroutines over and over.

Here is an example code from SparkFun:
Code:
/*
3/16/11
Basic Example Sketch for the ITG-3200 (http://www.sparkfun.com/products/9801)
SparkFun Electronics 2011
Ryan Owens

This code is public domain buy you buy me a beer if you use this and we meet someday (Beerware license).

To use this example code, attach:
Arduino  :  ITG-3200 Breakout
3.3V  :  VDD
3.3V  :  VIO
GND   :  GND
SDA   :  A4
SCL   :  A5

Load the sketch and open the serial window at 9600 bps. Arduino will output the raw X,Y and Z axis data being read from the gyroscope.

*/

//The Wire library is used for I2C communication
#include <Wire.h>

//This is a list of registers in the ITG-3200. Registers are parameters that determine how the sensor will behave, or they can hold data that represent the
//sensors current status.
//To learn more about the registers on the ITG-3200, download and read the datasheet.
char WHO_AM_I = 0x00;
char SMPLRT_DIV= 0x15;
char DLPF_FS = 0x16;
char GYRO_XOUT_H = 0x1D;
char GYRO_XOUT_L = 0x1E;
char GYRO_YOUT_H = 0x1F;
char GYRO_YOUT_L = 0x20;
char GYRO_ZOUT_H = 0x21;
char GYRO_ZOUT_L = 0x22;

//This is a list of settings that can be loaded into the registers.
//DLPF, Full Scale Register Bits
//FS_SEL must be set to 3 for proper operation
//Set DLPF_CFG to 3 for 1kHz Fint and 42 Hz Low Pass Filter
char DLPF_CFG_0 = (1<<0);
char DLPF_CFG_1 = (1<<1);
char DLPF_CFG_2 = (1<<2);
char DLPF_FS_SEL_0 = (1<<3);
char DLPF_FS_SEL_1 = (1<<4);

//I2C devices each have an address. The address is defined in the datasheet for the device. The ITG-3200 breakout board can have different address depending on how
//the jumper on top of the board is configured. By default, the jumper is connected to the VDD pin. When the jumper is connected to the VDD pin the I2C address
//is 0x69.
char itgAddress = 0x69;

//In the setup section of the sketch the serial port will be configured, the i2c communication will be initialized, and the itg-3200 will be configured.
void setup()
{
  //Create a serial connection using a 9600bps baud rate.
  Serial.begin(9600);
 
  //Initialize the I2C communication. This will set the Arduino up as the 'Master' device.
  Wire.begin();
 
  //Read the WHO_AM_I register and print the result
  char id=0;
  id = itgRead(itgAddress, 0x00); 
  Serial.print("ID: ");
  Serial.println(id, HEX);
 
  //Configure the gyroscope
  //Set the gyroscope scale for the outputs to +/-2000 degrees per second
  itgWrite(itgAddress, DLPF_FS, (DLPF_FS_SEL_0|DLPF_FS_SEL_1|DLPF_CFG_0));
  //Set the sample rate to 100 hz
  itgWrite(itgAddress, SMPLRT_DIV, 9);
}

//The loop section of the sketch will read the X,Y and Z output rates from the gyroscope and output them in the Serial Terminal
void loop()
{
  //Create variables to hold the output rates.
  int xRate, yRate, zRate;

  //Read the x,y and z output rates from the gyroscope.
  xRate = readX();
  yRate = readY();
  zRate = readZ();

  //Print the output rates to the terminal, seperated by a TAB character.
  Serial.print(xDegrees);
  Serial.print('\t');
  Serial.print(yDegrees);
  Serial.print('\t');
  Serial.println(zDegrees); 

  //Wait 10ms before reading the values again. (Remember, the output rate was set to 100hz and 1reading per 10ms = 100hz.)
  delay(10);
}

//This function will write a value to a register on the itg-3200.
//Parameters:
//  char address: The I2C address of the sensor. For the ITG-3200 breakout the address is 0x69.
//  char registerAddress: The address of the register on the sensor that should be written to.
//  char data: The value to be written to the specified register.
void itgWrite(char address, char registerAddress, char data)
{
  //Initiate a communication sequence with the desired i2c device
  Wire.beginTransmission(address);
  //Tell the I2C address which register we are writing to
  Wire.send(registerAddress);
  //Send the value to write to the specified register
  Wire.send(data);
  //End the communication sequence
  Wire.endTransmission();
}

//This function will read the data from a specified register on the ITG-3200 and return the value.
//Parameters:
//  char address: The I2C address of the sensor. For the ITG-3200 breakout the address is 0x69.
//  char registerAddress: The address of the register on the sensor that should be read
//Return:
//  unsigned char: The value currently residing in the specified register
unsigned char itgRead(char address, char registerAddress)
{
  //This variable will hold the contents read from the i2c device.
  unsigned char data=0;
 
  //Send the register address to be read.
  Wire.beginTransmission(address);
  //Send the Register Address
  Wire.send(registerAddress);
  //End the communication sequence.
  Wire.endTransmission();
 
  //Ask the I2C device for data
  Wire.beginTransmission(address);
  Wire.requestFrom(address, 1);
 
  //Wait for a response from the I2C device
  if(Wire.available()){
    //Save the data sent from the I2C device
    data = Wire.receive();
  }
 
  //End the communication sequence.
  Wire.endTransmission();
 
  //Return the data read during the operation
  return data;
}

//This function is used to read the X-Axis rate of the gyroscope. The function returns the ADC value from the Gyroscope
//NOTE: This value is NOT in degrees per second.
//Usage: int xRate = readX();
int readX(void)
{
  int data=0;
  data = itgRead(itgAddress, GYRO_XOUT_H)<<8;
  data |= itgRead(itgAddress, GYRO_XOUT_L); 
 
  return data;
}

//This function is used to read the Y-Axis rate of the gyroscope. The function returns the ADC value from the Gyroscope
//NOTE: This value is NOT in degrees per second.
//Usage: int yRate = readY();
int readY(void)
{
  int data=0;
  data = itgRead(itgAddress, GYRO_YOUT_H)<<8;
  data |= itgRead(itgAddress, GYRO_YOUT_L); 
 
  return data;
}

//This function is used to read the Z-Axis rate of the gyroscope. The function returns the ADC value from the Gyroscope
//NOTE: This value is NOT in degrees per second.
//Usage: int zRate = readZ();
int readZ(void)
{
  int data=0;
  data = itgRead(itgAddress, GYRO_ZOUT_H)<<8;
  data |= itgRead(itgAddress, GYRO_ZOUT_L); 
 
  return data;
}
Logged

Offline Offline
Faraday Member
**
Karma: 57
Posts: 2775
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First thing to check.

That device may have several different ranges,    and the best resolution of 14.7 LSB's per degree may be
applicable to one range,    and the peak angular velocity of 2000 deg/sec  may be applicable to a different range.
Do you have to send some command at startup to select the range ?

Check what type of number you are getting back.   If it is 16 bits long,   you could have a range of about -32000 to +32000,

or you could have a range of roughly  0 to 64000

What sort of value do you get when it is not spinning ?

Take into account that spinnning is inherently a bi-directional number because you can spin it either way.

If you have a resolution of 14.7 LSB's per second,   and you spin the thing at 2000 degrees per second,   then you
would expect to get a reading of about 14.7 x 2000   which is about 29000  which,  lo and behold,  is in the ballpark
of the maximum value you can get in a signed 2-byte number.

So  the first answer is probably right,   take the number you get,  and divide by 14.7  to get degrees per second.


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a arduimu v3, and I'm trying to do the conversion for my Gyro ITG3200 in ° / s. How can I perform? Thank you.
Logged

Pages: [1]   Go Up
Jump to: