Navigation Menu

Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:adafruit/Adafruit_L3GD20
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Oct 1, 2014
2 parents 275369f + 02cfce0 commit 7e93fa8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
23 changes: 23 additions & 0 deletions Adafruit_L3GD20.cpp
Expand Up @@ -114,6 +114,9 @@ bool Adafruit_L3GD20::begin(l3gd20Range_t rng, byte addr)
/* Adjust resolution if requested */
switch(range)
{
case L3DS20_RANGE_250DPS:
write8(L3GD20_REGISTER_CTRL_REG4, 0x00);
break;
case L3DS20_RANGE_500DPS:
write8(L3GD20_REGISTER_CTRL_REG4, 0x10);
break;
Expand Down Expand Up @@ -182,6 +185,26 @@ void Adafruit_L3GD20::read()
data.x = (xlo | (xhi << 8));
data.y = (ylo | (yhi << 8));
data.z = (zlo | (zhi << 8));

// Compensate values depending on the resolution
switch(range)
{
case L3DS20_RANGE_250DPS:
data.x *= L3GD20_SENSITIVITY_250DPS;
data.y *= L3GD20_SENSITIVITY_250DPS;
data.z *= L3GD20_SENSITIVITY_250DPS;
break;
case L3DS20_RANGE_500DPS:
data.x *= L3GD20_SENSITIVITY_500DPS;
data.y *= L3GD20_SENSITIVITY_500DPS;
data.z *= L3GD20_SENSITIVITY_500DPS;
break;
case L3DS20_RANGE_2000DPS:
data.x *= L3GD20_SENSITIVITY_2000DPS;
data.y *= L3GD20_SENSITIVITY_2000DPS;
data.z *= L3GD20_SENSITIVITY_2000DPS;
break;
}
}

/***************************************************************************
Expand Down
7 changes: 6 additions & 1 deletion Adafruit_L3GD20.h
Expand Up @@ -24,11 +24,16 @@
#endif
#include "Wire.h"

#define L3GD20_ADDRESS (0x6B) // 1101001
#define L3GD20_ADDRESS (0x6B) // 1101011
#define L3GD20_POLL_TIMEOUT (100) // Maximum number of read attempts
#define L3GD20_ID 0xD4
#define L3GD20H_ID 0xD7

#define L3GD20_SENSITIVITY_250DPS (0.00875F) // Roughly 22/256 for fixed point match
#define L3GD20_SENSITIVITY_500DPS (0.0175F) // Roughly 45/256
#define L3GD20_SENSITIVITY_2000DPS (0.070F) // Roughly 18/256
#define L3GD20_DPS_TO_RADS (0.017453293F) // degress/s to rad/s multiplier

class Adafruit_L3GD20
{
public:
Expand Down
24 changes: 15 additions & 9 deletions examples/Adafruit_L3GD20_test/Adafruit_L3GD20_test.ino
Expand Up @@ -18,14 +18,20 @@
#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);
// Comment this next line to use SPI
//#define USE_I2C

#ifdef USE_I2C
// The default constructor uses I2C
Adafruit_L3GD20 gyro;
#else
// To use SPI, 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);
#endif

void setup()
{
Expand All @@ -48,4 +54,4 @@ void loop()
Serial.print("Y: "); Serial.print((int)gyro.data.y); Serial.print(" ");
Serial.print("Z: "); Serial.println((int)gyro.data.z); Serial.print(" ");
delay(100);
}
}

0 comments on commit 7e93fa8

Please sign in to comment.