Pages: [1]   Go Down
Author Topic: ITG-3205 help understanding data  (Read 3841 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried all 3 of the examples attached in the Zip file below.  The results are the same.  I only get small numbers for x,y,z.  This noise I would expect to see when there is no rotational movement.  When I rotate the board, nothing changes.  When I tap the sensor lightly I can see the numbers change, especially the X value.  What am I doing wrong?

I don't see how it can be a problem in the Sketches, as these 3 are unrelated.
I don't see how it can be the hardware, because the chip is obviously talking, it returns correct ID in 1 sketch.
There are no jumpers to solder on my board.
The other 2 chips on the board are working fine.
It must be the way I'm interpreting the data. 
I've scaled it by dividing so the noise values are small, after calibrating (subtracting).
Shouldn't the data results x,y,z be larger than the noise when I rotate the board by hand?

Do I need to attach VCC_IN to 3.3v on my 9DOF board?

Please help I'm stuck!

* ITG3200x3 examples.zip (7.58 KB - downloaded 128 times.)
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Moderator can you move this to Project Guidance?
There's not as many active readers in Sensors...
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11694
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why do you think its not working, these devices are rate gyros. Am on mobile, cant read a .zip, post the code with code tags please rather than make people unpack archives, you'll get more responses
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please explain rate gyros.  I thought I understood.  When I turn them at a rate of 10-100 deg/sec by hand shouldn't the numbers change from the small noise they were displaying?

I don't think the code is the problem, I only included it because someone would of course ask.  I didn't write the code.  All 3 are popular examples.  The outputs are similar to each other before I modified them.  After I realized this, I changed them to help me interpret the data.  Don't waste your time looking at the code.  Here is the sample output I made up from memory:

1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 0 0 0 -1 -1 -1 -1 -1 2 1 2 1 2 1 2 1 43 45 23 65 12 32 36 1 2 3 1 2 1 0

The big numbers are where I tapped the sensor with my finger.  There is no change when I turn/rotate it by hand.

Code:
//Ricardo Arturo Cabral <ing dot cabral dot mejia at gmail
#include <Wire.h>
#include "itg3200.h"
ITG3200 gyro;
void setup(){
  Serial.begin(9600);
  gyro.begin(0x68);
  delay(1000);
}
int cnt=0;
void loop(){
  Serial.print(int(gyro.getX())/5);Serial.write(32);
  if(++cnt%40==0)Serial.write(10);
  delay(50);
}

I didn't change this part:

Code:
/*
 *   itg3200.cpp
 *
 *   Copyright (C) 2010  Ricardo Arturo Cabral <ing dot cabral dot mejia at gmail dot com>. All rights reserved.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  See <license.txt>, if not, see
 *   <http://www.gnu.org/licenses/>.
 */
#include <Wire.h>
//#include "WConstants.h"
#include "itg3200.h"


ITG3200::ITG3200()
{
  Wire.begin();
};

void ITG3200::begin(int address)
{
  _gyro_address = address;
  write(GYRO_REG_PWR_MGM, 0);
  write(GYRO_REG_SMPLRT_DIV, 0xFF);
  write(GYRO_REG_DLPF_FS, 0x1E);
  write(GYRO_REG_INT_CFG, 0);
}

void ITG3200::begin(int address,byte pwr_mgm, byte fs_lpf, byte smplrt_div, byte int_cfg) {
  // Power Management
  _gyro_address = address;
  write(GYRO_REG_PWR_MGM, pwr_mgm);
 
  // Sample rate divider
  //_smplrt_div = smplrt_div;
  write(GYRO_REG_SMPLRT_DIV, smplrt_div);
 
  //Frequency select and digital low pass filter
  //_fs_lpf = fs_lpf;
  write(GYRO_REG_DLPF_FS, 0x1F & fs_lpf);
 
  //Interrupt configuration
  //_int_cfg = int_cfg;
  write(GYRO_REG_INT_CFG, 0xF5 & int_cfg);
}

float ITG3200::getX() {
  return (float)(read(GYRO_REG_X_L) | read(GYRO_REG_X_H)<<8)/GYRO_SENSITIVITY;
}

float ITG3200::getY() {
  return (float)(read(GYRO_REG_Y_L) | read(GYRO_REG_Y_H)<<8)/GYRO_SENSITIVITY;
}

float ITG3200::getZ() {
  return (float)(read(GYRO_REG_Z_L) | read(GYRO_REG_Z_H)<<8)/GYRO_SENSITIVITY;
}

float ITG3200::getTemperature(){
  return (((float)((read(GYRO_REG_TEMP_L) | read(GYRO_REG_TEMP_H)<<8) + GYRO_TEMP_OFFSET))/GYRO_TEMP_SENSITIVITY) + GYRO_TEMP_OFFSET_CELSIUS;
}

void ITG3200::reset() {
  write(GYRO_REG_PWR_MGM, GYRO_RESET);
}

void ITG3200::sleep() {
  byte t = read(GYRO_REG_PWR_MGM);
  write(GYRO_REG_PWR_MGM, t | GYRO_SLEEP);
}

void ITG3200::wake(){
  byte t = read(GYRO_REG_PWR_MGM);
  write(GYRO_REG_PWR_MGM, t & ~GYRO_SLEEP);
}

void ITG3200::standBy(byte axis) {
  byte t = read(GYRO_REG_PWR_MGM);
  write(GYRO_REG_PWR_MGM, t & ~axis);
}

byte ITG3200::getAddress()
{
  return read(GYRO_REG_WHOAMI);
}

void ITG3200::setAddress(byte newAddress)
{
  write(GYRO_REG_WHOAMI, newAddress);
}

void ITG3200::setInterruptConfig(byte config)
{
  // bit 3 and 1 must be zero
  write(GYRO_REG_INT_CFG, 0xF5 & config);
}

bool ITG3200::isInterruptRawDataReady()
{
  byte result = read(GYRO_REG_INT_STS);
  return (result & GYRO_INT_DATA) == GYRO_INT_DATA;
}

bool ITG3200::isInterruptReady()
{
  byte result = read(GYRO_REG_INT_STS);
  return (result & GYRO_INT_READY) == GYRO_INT_READY;
}

byte ITG3200::getInterruptConfig()
{
  return read(GYRO_REG_INT_CFG);
}

void ITG3200::setClockSource(byte clockSource)
{
  if (clockSource >= 6) // 6 and 7 are reserved
    return;
  write(GYRO_REG_PWR_MGM, 0xF8 & clockSource);
}

void ITG3200::write(byte reg, byte val) {
  Wire.beginTransmission(_gyro_address);
  Wire.send(reg);
  Wire.send(val);
  Wire.endTransmission();
}

byte ITG3200::read(byte reg) {
  Wire.beginTransmission(_gyro_address);
  Wire.send(reg);
  Wire.endTransmission();
  Wire.beginTransmission(_gyro_address);
  Wire.requestFrom(_gyro_address,  1);
  while (Wire.available() ==0) {}; // block unil data is available
  byte buf = Wire.receive();
  Wire.endTransmission();
  return buf;
}
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

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

What's the value of GYRO_SENSITIVITY ?

Also you can use this processing code to display what happens exactly :

Code:
import processing.serial.*;
 import javax.media.opengl.*;
 import processing.opengl.*;
 
 Serial myPort;        // The serial port
 float[] values;
 int currentVal = 0;
 PGraphics pg;

 //Gestion du temps à rajouter
 
 void setup ()
 {
   // set the window size:
   size(450, 350, OPENGL);       
   
   // List all the available serial ports
   println(Serial.list());
   // I know that the first port in the serial list on my mac
   // is always my  Arduino, so I open Serial.list()[0].
   // Open whatever port is the one you're using.
   myPort = new Serial(this, Serial.list()[0], 9600);
   // don't generate a serialEvent() unless you get a newline character:
   myPort.bufferUntil('\n');
   // set inital background:
   background(0);
   
   pg = createGraphics(400,300, JAVA2D);
   
   values = new float[400];
   for (int i = 0; i < values.length-1; i++)
       values[i] = 150;
   
   delay(400);
 }
 void draw ()
 {
   
   background(0);
   pg.beginDraw();
   pg.background(35);
   DrawGraph(values, currentVal, color(127,34,255));
   pg.text("value :" + values[currentVal], 5,50);
   pg.endDraw();
   image(pg,25,25);
 }
 
 void serialEvent (Serial myPort)
 {
   // get the ASCII string:
   String inString = myPort.readStringUntil('\n');
   
   if (inString != null)
   {
     // trim off any whitespace:
     inString = trim(inString);
     // convert to an int and map to the screen height:
     float inByte = float(inString);
     if(currentVal < values.length-1)
     {
       currentVal++;
     }
     else
     {
       for (int i = 1 ; i < values.length ; i++)
       {
         values[i-1] = values[i];
       }
     }
     values[currentVal] = inByte;   
   }
 }
 
 void DrawGraph(float[] data, int drawUntil, color c)
 { 
   float tmp,tmp2;
   //Dessin du tableau
   if(drawUntil <= data.length)
   {
      for (int i = 1 ; i < drawUntil ; i++)
      {
        pg.stroke(c);
        pg.strokeWeight(1);
        tmp = map(data[i],-500,500,300,0);
        tmp2 = map(data[i-1],-500,500,300,0);
        pg.line(i-1,tmp2,i,tmp);
      }
   }
 }
 

You need to modify your arduino code like this :
Code:
//Ricardo Arturo Cabral <ing dot cabral dot mejia at gmail
#include <Wire.h>
#include "itg3200.h"
ITG3200 gyro;
void setup(){
  Serial.begin(9600);
  gyro.begin(0x68);
  delay(1000);
}
int cnt=0;
void loop(){
  Serial.print(int(gyro.getX())/5);
  delay(50);
}

If the processing program fails at starting, just relaunch it, the serial is not completely reliable at starting and makes the program crash.
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11694
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The first thing I would do is integrate the readings and display the integrated version - should be much clearer to see if its doing the right thing.

What is the full scale sensitivity and the number of bits - you may find the readings are quite small and the noise is making the signal hard to see (this is why you should integrate or low-pass filter).  Gyros in general won't be sensitive to knocks unless the knock turns the sensor so it does sound a bit suspicious but do realise the noise will easily mask the signal for low rates of turn (compared to full scale).
Logged

[ I won't respond to messages, use the forum please ]

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

I have to disagree with you Markt, noise won't mask a rotation done by hand. I have an itg 3205 and the noise is really small, if I just put it on a table, the gyro value stays at around the full scale without moving more than a couple of LSB. And it makes perfect sense because why encoding a sensor data on 16 bits if the significant value is on 13 bits and 3 lowest bits are waste ? Also, it detects really well a rotation by hand, no problem.
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you using one of the simple example sketches without integration?  Shouldn't I see the numbers change when I turn it?
I feel there is something wrong.  Finishing another project first before I focus on this...
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11694
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The visibility of the signal depends on the full scale setting - if its 2000 deg/s then simple hand movements are likely to be at a few percent at most of full-scale and if there is no low-pass filtering enabled there will definitely be noise...   It could easily be misbehaving, but it would be a shame to miss the signal by not looking carefully.  Programmable LPF and full scale settings on some MEMS chips mean they can be set up so the signal is not very obvious.

The integrated version of the signal is much easier to observe since it is not evanescent when you stop turning the device and noise is being averaged.
Logged

[ I won't respond to messages, use the forum please ]

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

Well with simple hand movement you reach easily 200° per second, that's not even a turn per second, but yet it's 10% of the fullscale. Really, it's not noise to blame here...If there was noise, he wouldn't get values like 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 0 0 0 -1 -1 -1 -1 -1 2 1 2 1 2 1 2 1, more like 10 15 0 2 -15 -19

Again, what's the value of GYRO_SENSITIVITY ? Also try reading the temperature, take a hair dryer and warm it a bit (not with a finger because of electrostatic discharge) and look if the value is correct.
Logged

Pages: [1]   Go Up
Jump to: