LSM303/L3GD20 Accelerometer Not working right

I've been working on a project that uses an accelerometer and my progress has been.... weird. I'm using an accelerometer from aliexpress that so far has seemed to be a solid clone of the adafruit 9dof accelerometer.

I'm currently using the Adafruit libraries because I like that they gave values with usable units as opposed to raw readings like the pololu libraries.

I've gotten everything all hooked up, but I'm first and foremost having issues with my gyro. When I try the

    if(!gyro.begin()){

It always fails the test.

I've also noticed that when I try to read the accel data, I seem to be getting gyro data. I've noticed this just from rocking the sensor back and fourth. When I expected accel data, it seemed to be based on the orientation and not the rate of the movement. For example, I could get consistent results when the device was at rest in different positions, something that is clearly gyro data and not acceleration.

I've wired my device as so...

ESP32 -- Accelerometer
5v -- Vin
Gnd -- Gnd
SCL -- SCL
SDA -- SDA

I'm posting some of my basic code below. When I try to get a gyro event, everything fails. I am guessing my problems are starting with the gyro but currently, they've being displayed when I try to get accel data. I'm not sure if something is addressed incorrectly, but I'm at the point where I'm officially at a dead end and not sure what to try next. Does anyone have any theories on what's up with my accelerometer?

    #include <SPI.h>
    #include <Wire.h>
    
    #include <Adafruit_Sensor.h>
    #include <Adafruit_L3GD20_U.h>
    #include <Adafruit_LSM303_U.h>
    #include <Adafruit_9DOF.h>
    
    /* Assign a unique ID to these sensors at the same time */
    Adafruit_L3GD20_Unified            gyro      =      Adafruit_L3GD20_Unified(10001);
    Adafruit_LSM303_Accel_Unified      accel     =      Adafruit_LSM303_Accel_Unified(10002);
    Adafruit_LSM303_Mag_Unified        mag       =      Adafruit_LSM303_Mag_Unified(10003);
    Adafruit_9DOF                      dof       =      Adafruit_9DOF();
    
    void setup() {
      //Serial Port begin
      Serial.begin (9600);
      
      /* Initialise the sensor */
      if(!accel.begin()){
        /* There was a problem detecting the ADXL345 ... check your connections */
        Serial.println("Ooops1, no LSM303 detected ... Check your wiring!");
        while(1);
      }
    
      /* Enable auto-gain */
      mag.enableAutoRange(true);
    
      /* Initialise the sensor */
      if(!mag.begin()){
        /* There was a problem detecting the LSM303 ... check your connections */
        Serial.println("Ooops2, no LSM303 detected ... Check your wiring!");
        while(1);
      }
    
      gyro.enableAutoRange(true);
      gyro.begin();
    }
    
    void loop(){
    
        /* Get a new sensor event */ 
        sensors_event_t event; 
        //gyro.getEvent(&event);
        accel.getEvent(&event);
        mag.getEvent(&event);
        
        sensors_vec_t   orientation;
      
        /* Display the results (acceleration is measured in m/s^2) */
        Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print("  ");
        Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print("  ");
        Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print("  ");Serial.println("m/s^2 ");
        
        /* Display the results */
        //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("  ");
        
        /* Display the results */
        Serial.print("X: "); Serial.print(event.magnetic.x); Serial.print("  ");
        Serial.print("Y: "); Serial.print(event.magnetic.y); Serial.print("  ");
        Serial.print("Z: "); Serial.print(event.magnetic.z); Serial.println("  ");
    
    }

so far has seemed to be a solid clone of the adafruit 9dof accelerometer.

Your report suggests otherwise.

I suggest to take advantage of the money back guarantee on the product page and buy the genuine item, from a reputable supplier.

By the way: if the device actually worked, it would be called an IMU, not an accelerometer.

jremington:
Your report suggests otherwise.

I suggest to take advantage of the money back guarantee on the product page and buy the genuine item, from a reputable supplier.

By the way: if the device actually worked, it would be called an IMU, not an accelerometer.

Thanks for the help. Maybe it is a defective unit that's failing in the most graceful way, but ordering components from aliexpress doesn't automatically make them defective, and this feels like something happening with the programming.

Try GitHub - pololu/l3g-arduino: Arduino library for Pololu L3G4200D and L3GD20 boards or use instead of the L3GD20 address and id:

#define L3G4200D_ADDRESS (0x69) // 1101001
#define L3G4200D_ID (0xD3)

Note that the data rate and bandwidth settings between the libraries are different.