Adafruit_L3GD20_U icon indicating copy to clipboard operation
Adafruit_L3GD20_U copied to clipboard

Returns bad data if getEvent called immediately after begin

Open jackw01 opened this issue 6 years ago • 0 comments

  • Arduino board: Uno and Pro Mini

  • Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.5

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_L3GD20_U.h>

/* Assign a unique ID to this sensor at the same time */
Adafruit_L3GD20_Unified gyro = Adafruit_L3GD20_Unified(20);

void setup(void) 
{
  Serial.begin(115200);
  Serial.println("Gyroscope Test"); Serial.println("");
  
  /* Enable auto-ranging */
  gyro.enableAutoRange(false);
  
  /* Initialise the sensor */
  if(!gyro.begin())
  {
    /* There was a problem detecting the L3GD20 ... check your connections */
    Serial.println("Ooops, no L3GD20 detected ... Check your wiring!");
    while(1);
  }
}

void loop(void) 
{
  /* Get a new sensor event */ 
  sensors_event_t event; 
  gyro.getEvent(&event);
 
  /* Display the results (speed is measured in rad/s) */
  Serial.print("X: "); Serial.print(event.gyro.x); Serial.print("  ");
  Serial.print("Y: "); Serial.print(event.gyro.y); Serial.print("  ");
  Serial.print("Z: "); Serial.print(event.gyro.z); Serial.println("  ");
  delay(50);
}
Gyroscope Test

X: 2.73  Y: 3.12  Z: -5.00  
X: -0.13  Y: 0.20  Z: 0.12  
X: 0.00  Y: 0.06  Z: 0.02  
X: -0.00  Y: 0.07  Z: -0.00  
X: -0.00  Y: 0.05  Z: 0.01  
X: -0.00  Y: 0.08  Z: 0.01  
X: -0.00  Y: 0.07  Z: 0.02  
X: -0.00  Y: 0.08  Z: 0.05  
X: -0.00  Y: 0.06  Z: 0.01  
X: 0.00  Y: 0.05  Z: 0.00  
X: -0.00  Y: 0.06  Z: 0.03  
X: -0.00  Y: 0.05  Z: 0.01  
X: -0.00  Y: 0.05  Z: 0.01

When running this, the x,y,z values returned the first time getEvent is called are an order of magnitude higher than the rest, which is obviously incorrect.

This issue only occurs if getEvent is called immediately after begin. If a delay is added before the loop starts, this works as expected.

jackw01 avatar Oct 23 '18 03:10 jackw01