From 817f3b433b28af8288a0ffb3dfea94ed403eaceb Mon Sep 17 00:00:00 2001 From: "K.Townsend" Date: Tue, 1 Jan 2013 21:52:41 +0100 Subject: [PATCH 1/3] Added DPS compensation + bug fixes --- Adafruit_L3GD20.cpp | 23 +++++++++++++++++++++++ Adafruit_L3GD20.h | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/Adafruit_L3GD20.cpp b/Adafruit_L3GD20.cpp index 9a22ad2..72d4ffb 100644 --- a/Adafruit_L3GD20.cpp +++ b/Adafruit_L3GD20.cpp @@ -112,6 +112,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; @@ -180,6 +183,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; + } } /*************************************************************************** diff --git a/Adafruit_L3GD20.h b/Adafruit_L3GD20.h index 047165d..ef13df6 100644 --- a/Adafruit_L3GD20.h +++ b/Adafruit_L3GD20.h @@ -28,6 +28,11 @@ #define L3GD20_POLL_TIMEOUT (100) // Maximum number of read attempts #define L3GD20_ID (0b11010100) +#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: From e4e9397fb68b5f119c61444b8da51c7d9e100ab5 Mon Sep 17 00:00:00 2001 From: "K.Townsend" Date: Wed, 2 Jan 2013 23:49:20 +0100 Subject: [PATCH 2/3] Clarified I2C/SPI selection --- .../Adafruit_L3GD20_test.ino | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/examples/Adafruit_L3GD20_test/Adafruit_L3GD20_test.ino b/examples/Adafruit_L3GD20_test/Adafruit_L3GD20_test.ino index 84c88ba..7864437 100644 --- a/examples/Adafruit_L3GD20_test/Adafruit_L3GD20_test.ino +++ b/examples/Adafruit_L3GD20_test/Adafruit_L3GD20_test.ino @@ -18,14 +18,20 @@ #include #include -// 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() { @@ -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); -} \ No newline at end of file +} From 02cfce0c26b1e3747e54f7690f17af2b52083722 Mon Sep 17 00:00:00 2001 From: Kevin Townsend Date: Thu, 28 Nov 2013 19:10:58 +0100 Subject: [PATCH 3/3] Fixed binary address --- Adafruit_L3GD20.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_L3GD20.h b/Adafruit_L3GD20.h index ef13df6..55fa475 100644 --- a/Adafruit_L3GD20.h +++ b/Adafruit_L3GD20.h @@ -24,7 +24,7 @@ #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 (0b11010100)