9dof IMU won't initialize

I randomly bought a cheap ($7) "9 Axis IMU L3GD20 LSM303D Module 9DOF Compass Acceleration Gyroscope for Arduino" off eBay. It looks just like the Adafruit 9-DOF IMU Breakout - L3GD20H + LSM303 (now discontinued). However, running the example sketches from Adafruit and they fail to initialize. Just dies, sometimes mid println. I'd almost think the board is useless but running the Arduino I2C Scanner sketch gives me results:

16:33:11.866 -> Scanning...
16:33:11.866 -> I2C device found at address 0x19 !
16:33:11.933 -> I2C device found at address 0x1E !
16:33:11.970 -> I2C device found at address 0x69 !

So something is there? This topic, or similar, has been posted twice here, at
L3GD20H Sample Code not printing to Serial Monitor
and

L3GD20 gyroscope initializing not working

with no apparent resolution. Should I give up?

Below is the Adafruit Tester example, and it dies at the
/* Initialise the sensors */
if(!accel.begin())

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

  /* Assign a unique ID to the sensors */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_L3GD20_Unified       gyro  = Adafruit_L3GD20_Unified(20);

void displaySensorDetails(void)
{
  sensor_t sensor;
  
  accel.getSensor(&sensor);
  Serial.println(F("----------- ACCELEROMETER ----------"));
  Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" m/s^2"));
  Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" m/s^2"));
  Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" m/s^2"));
  Serial.println(F("------------------------------------"));
  Serial.println(F(""));

  gyro.getSensor(&sensor);
  Serial.println(F("------------- GYROSCOPE -----------"));
  Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" rad/s"));
  Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" rad/s"));
  Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" rad/s"));
  Serial.println(F("------------------------------------"));
  Serial.println(F(""));
  
  mag.getSensor(&sensor);
  Serial.println(F("----------- MAGNETOMETER -----------"));
  Serial.print  (F("Sensor:       ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:   ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:    ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:    ")); Serial.print(sensor.max_value); Serial.println(F(" uT"));
  Serial.print  (F("Min Value:    ")); Serial.print(sensor.min_value); Serial.println(F(" uT"));
  Serial.print  (F("Resolution:   ")); Serial.print(sensor.resolution); Serial.println(F(" uT"));  
  Serial.println(F("------------------------------------"));
  Serial.println(F(""));

  delay(500);
}

void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Adafruit 9DOF Tester")); 
  Serial.println("ghgj");
  
  /* Initialise the sensors */
  if(!accel.begin())
  Serial.println(F("Adafruit 9DOF Tester")); 
  {
    /* There was a problem detecting the ADXL345 ... check your connections */
    Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
    while(1);
  }
  if(!mag.begin())
  {
    /* There was a problem detecting the LSM303 ... check your connections */
    Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
    while(1);
  }
  if(!gyro.begin())
  {
    /* There was a problem detecting the L3GD20 ... check your connections */
    Serial.print("Ooops, no L3GD20 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
  
  /* Display some basic information on this sensor */
  displaySensorDetails();
}

void loop(void)
{
  /* Get a new sensor event */
  sensors_event_t event;
   
  /* Display the results (acceleration is measured in m/s^2) */
  accel.getEvent(&event);
  Serial.print(F("ACCEL "));
  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 (magnetic vector values are in micro-Tesla (uT)) */
  mag.getEvent(&event);
  Serial.print(F("MAG   "));
  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.print("  ");Serial.println("uT");

  /* Display the results (gyrocope values in rad/s) */
  gyro.getEvent(&event);
  Serial.print(F("GYRO  "));
  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.print("  ");Serial.println("rad/s ");  

  Serial.println(F(""));
  delay(1000);
}```

Cheap eBay items are very often mislabeled and/or use reject, recycled or counterfeit parts. If you buy three, consider yourself lucky if one or two have the correct parts and work.

Pololu, Adafruit and Sparkfun sell the same parts, but they buy genuine chips, and they guarantee and support their products.

Which Arduino board do you use and how is it connected ?
When you have a 5V Arduino board, then you should power the module with 5V, or else the level shifters don't work.
Do you use a flat ribbon cable for the I2C bus, then it will also not work.
Can you check the soldering with a magnifier ?
Do all the resistors have the text "103" ?

Hooked to an Uno, using 4 jumpers, 5V GND SCL SDA. Soldering looks good. All resistors seem to have 103, although there are a couple of things that are unlabeled.

I know, but for $4 (plus shipping) I was willing to gamble. The I2C scan says something is there, so I am still wondering. (Also, went 5 for 5 on time of flight sensors and 6 for 6 on ultrasonic sensors same shipment #winning)

Are all those I2C addresses the correct ones, matching the library code?

Oooh! From the library Adafruit_LSM303_U.h I find this:

/*====================================================
    I2C ADDRESS/BITS
    -----------------------------------------------------------------------*/
    #define LSM303_ADDRESS_ACCEL          (0x32 >> 1)         // 0011001x
    #define LSM303_ADDRESS_MAG            (0x3C >> 1)         // 0011110x

But my I2C scan says
16:33:11.866 -> I2C device found at address 0x19 !
16:33:11.933 -> I2C device found at address 0x1E !
16:33:11.970 -> I2C device found at address 0x69 !

Is one of those supposed to match? Also for library Adafruit_L3GD20_U.h, the addresses do not match my scan. Note that my scan is similar to what torbynator posted in "L3GD20 gyroscope initializing not working". (His was 10dof and had a 4th device).

Note the confusion about 8 bit versus 7 bit I2C addresses. These two lines result in 0x19 and 0x1E.

    #define LSM303_ADDRESS_ACCEL          (0x32 >> 1)         // 0011001x
    #define LSM303_ADDRESS_MAG            (0x3C >> 1)         // 0011110x

If the I2C addresses don't match, either you have the wrong part, or you need to change the library so that the addresses do match. Or use the library method to select the correct I2C address.

Check the data sheets to see the allowable range of I2C addresses for each one. Most of those ICs have one or more address selection pins.

I think this is the accel.begin(): https://github.com/adafruit/Adafruit_LSM303DLHC/blob/master/Adafruit_LSM303_U.cpp#L342
The only test is for the WHO_AM_I. If that would fail, then it would return an error and you would see a message.

If that crashes or halts the sketch, then there is something wrong with the I2C bus.

Can you check the jumper wires. Are they broken or bad ?
Do you use a breadboard ? Can you put everything in a other location on the breadboard ? Breadboards often have bad contacts.

Perhaps the module has a wrong component, or a shortcut somewhere, that makes that it does something bad to the I2C bus.
Since others have problems as well with this module, it is in my opinion not worth the effort to investigate what is wrong with the module. Buy something good that works.

Look closely at the statement controlled by the if.
Regardless of the result, you will hit the while(1) always.

1 Like

The sketch you posted does NOT match the "tester.ino" example from the Adafruit_9DOF library: https://raw.githubusercontent.com/adafruit/Adafruit_9DOF/master/examples/tester/tester.ino

Try downloading the source again and seeing if that helps.

The 'virgin' sketch fails same way. I added some additional println to see where the failure was.

It fails before that, never printing "oops, no...". Which is why I think the fault is so weird. Why would it just stop and not throw the error flag? Commenting out all the inits, we get to displaySensorDetails and the output is:

10:00:27.669 -> ----------- ACCELEROMETER ----------
10:00:27.669 -> Sensor:       LSM303
10:00:27.669 -> Driver Ver:   1
10:00:27.669 -> Unique ID:    30301
10:00:27.669 -> Max Value:    0.00 m/s^2
10:00:27.669 -> Min Value:    0.00 m/s^2
10:00:27.669 -> Resolution:   0.00 m/s^2
10:00:27.669 -> ------------------------------------
10:00:27.669 -> 
10:00:27.669 -> ------------- GYROSCOPE -----------
10:00:27.669 -> Sensor:       L3GD20
10:00:27.705 -> Driver Ver:   1
10:00:27.705 -> Unique ID:    20
10:00:27.705 -> Max Value:    0.00 rad/s
10:00:27.705 -> Min Value:    0.00 rad/s
10:00:27.705 -> Resolution:   0.00 rad/s
10:00:27.705 -> ------------------------------------
10:00:27.705 -> 
10:00:27.705 -> ----------- MAGNETOMETER -----------
10:00:27.705 -> Sensor:       LSM303
10:00:27.705 -> Driver Ver:   1
10:00:27.705 -> Unique ID:    30302
10:00:27.705 -> Max Value:    0.00 uT
10:00:27.705 -> Min Value:    0.00 uT
10:00:27.705 -> Resolution:   0.00 uT
10:00:27.705 -> ------------------------------------

Which says to me something is going on in the chip.

No data sheet for cheap eBay parts.

You did not present a copy of the output that is generated.

When this happens, be sure to call Serial.flush();after each debug message. If a library crashes your sketch, the Serial output that is still in the output buffer will never get sent and you will have an incorrect impression of when the failure occurred.