Pages: [1]   Go Down
Author Topic: L3G4200D gyroscope  (Read 776 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,

I am trying to hook up a L3G4200D gyroscope with an Arduino UNO system. I found some code online that is specific for this gyroscope but am having some difficulties. I can't seem to get an output other than "000". I think there is a problem with the I2C communication between the the gyro and Arduino but I am not sure. Does anyone know what might be the problem with our code or something we could try to fix our problem.


The code we are using is below:
Code:
#define GYROSCOPE 0x69
#include <L3G.h>
#include <Wire.h>

L3G gyro;
int x, y, z;
int L3G4200D_Address = 107;
byte buff[6];

void setup() {
  
    Serial.begin(9600);
    Wire.begin();
  
 if (!gyro.init(L3G4200D_DEVICE, L3G_SA0_LOW))
  {
    Serial.println("Failed to autodetect gyro type!");
    while (1);
  }

  gyro.enableDefault();
}

void loop() {
    // Delay the flow
    delay(500);
    Wire.beginTransmission(107);
    Wire.print(0x1D);
    Wire.endTransmission();
    
    Wire.requestFrom(107,6);
    int i = 0;
    while(Wire.available()) {
       buff[i] = Wire.read();
       i++;
    }
    
    // Convert to ints
    x = (((int)buff[1]) << 8) | buff[0];  
    y = (((int)buff[3]) << 8) | buff[2];
    z = (((int)buff[5]) << 8) | buff[4];
    
    Serial.print(x);
    Serial.print(" ");
    Serial.print(y);
    Serial.print(" ");
    Serial.print(z);
    Serial.print("\n");
}

Thx!
« Last Edit: January 18, 2013, 03:31:23 pm by asmehta » Logged

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

There are several example programs for accessing this device.
Just be aware that some of them don't actually work. 
I suggest you download several of them and compare them carefully
with your code.   
I find the whole scheme of when to use beginTransmission() and
endTransmission(),  and when not to use them,   to be highly
counter-intuitive  and needs a bit of tinkering to get it to work.
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1015
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Are you communicating with the sensor at all ?
First things first, use the i2c_scanner : http://playground.arduino.cc/Main/I2cScanner

At the sparkfun page https://www.sparkfun.com/products/10612
is a link to a bildr tutorial.
You could try that, but I think the code is wrong.
There is a small error in that code, since it waits for Wire.available() and that is not how it should be used.
« Last Edit: January 20, 2013, 04:18:55 am by Krodal » Logged

Pages: [1]   Go Up
Jump to: