Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added DPS compensation + bug fixes

  • Loading branch information...
commit 817f3b433b28af8288a0ffb3dfea94ed403eaceb 1 parent 72bb2d2
K.Townsend authored
Showing with 28 additions and 0 deletions.
  1. +23 −0 Adafruit_L3GD20.cpp
  2. +5 −0 Adafruit_L3GD20.h
View
23 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;
+ }
}
/***************************************************************************
View
5 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:
Please sign in to comment.
Something went wrong with that request. Please try again.