by kgraf » Mon Jan 07, 2013 12:43 am
1. since I am using I2C, I should comment out the defines and Adafruit_L3GD20 gyro(GYRO_CS, GYRO_DO, GYRO_DI, GYRO_CLK); ?
2. where should he constructor call be placed in the code? does the code in Adafruit_L3GD20.h
and/or Adafruit_L3GD20.cpp need to be adjusted?
"To use the L3GD20 in your sketch, you must first call a constructor to create a device object. There are two forms of the constructor:"
Adafruit_L3GD20(void);
//Adafruit_L3GD20_test current code
#include <Wire.h>
#include <Adafruit_L3GD20.h>
// By default, uses I2C
//Adafruit_L3GD20 gyro;
// Alternately, you can use SPI, but you have to define the pins
#define GYRO_CS 4 // labeled CS
#define GYRO_DO 5 // labeled SA0
#define GYRO_DI 6 // labeled SDA
#define GYRO_CLK 7 // labeled SCL
Adafruit_L3GD20 gyro(GYRO_CS, GYRO_DO, GYRO_DI, GYRO_CLK);
void setup()
{
Serial.begin(9600);
// Try to initialise and warn if we couldn't detect the chip
if (!gyro.begin(gyro.L3DS20_RANGE_250DPS))
//if (!gyro.begin(gyro.L3DS20_RANGE_500DPS))
//if (!gyro.begin(gyro.L3DS20_RANGE_2000DPS))
{
Serial.println("Oops ... unable to initialize the L3GD20. Check your wiring!");
while (1);
}
}
void loop()
{
gyro.read();
Serial.print("X: "); Serial.print((int)gyro.data.x); Serial.print(" ");
Serial.print("Y: "); Serial.print((int)gyro.data.y); Serial.print(" ");
Serial.print("Z: "); Serial.println((int)gyro.data.z); Serial.print(" ");
delay(100);
}