5

History

I have an Adafruit 10DOF IMU Breakout which has been working on my Mega for some time. This morning my program did not run so I starting troubleshooting.

Scenario

I eventually plugged the IMU breakout into my Uno with the *out-of-the-box accelerometer reader program from Adafruit. That's when I started seeing

Ooops, no LSM303 detected ... Check your wiring!

And upon close inspection have verified all wires are in the correct spot.


Question

How do I troubleshoot this further? Also, I'm starting to think that my IMU may be fried. How can I test this?


* AHRS out-of-the-box Program from Adafruit:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_BMP085_U.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_10DOF.h>

/* Assign a unique ID to the sensors */
Adafruit_10DOF                dof   = Adafruit_10DOF();
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_BMP085_Unified       bmp   = Adafruit_BMP085_Unified(18001);

/* Update this with the correct SLP for accurate altitude measurements */
float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;

/**************************************************************************/
/*!
    @brief  Initialises all the sensors used by this example
*/
/**************************************************************************/
void initSensors()
{
  if(!accel.begin())
  {
    /* There was a problem detecting the LSM303 ... 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(!bmp.begin())
  {
    /* There was a problem detecting the BMP180 ... check your connections */
    Serial.println("Ooops, no BMP180 detected ... Check your wiring!");
    while(1);
  }
}

/**************************************************************************/
/*!

*/
/**************************************************************************/
void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Adafruit 10 DOF Pitch/Roll/Heading Example")); Serial.println("");
  
  /* Initialise the sensors */
  initSensors();
}

/**************************************************************************/
/*!
    @brief  Constantly check the roll/pitch/heading/altitude/temperature
*/
/**************************************************************************/
void loop(void)
{
  sensors_event_t accel_event;
  sensors_event_t mag_event;
  sensors_event_t bmp_event;
  sensors_vec_t   orientation;

  /* Read the accelerometer and magnetometer */
  accel.getEvent(&accel_event);
  mag.getEvent(&mag_event);

  /* Use the new fusionGetOrientation function to merge accel/mag data */  
  if (dof.fusionGetOrientation(&accel_event, &mag_event, &orientation))
  {
    /* 'orientation' should have valid .roll and .pitch fields */
    Serial.print(F("Orientation: "));
    Serial.print(orientation.roll);
    Serial.print(F(" "));
    Serial.print(orientation.pitch);
    Serial.print(F(" "));
    Serial.print(orientation.heading);
    Serial.println(F(""));
  }

  /* Previous code removed handling accel and mag data separately */
  //  /* Calculate pitch and roll from the raw accelerometer data */
  //  Serial.print(F("Orientation: "));
  //  accel.getEvent(&accel_event);
  //  if (dof.accelGetOrientation(&accel_event, &orientation))
  //  {
  //    /* 'orientation' should have valid .roll and .pitch fields */
  //    Serial.print(orientation.roll);
  //    Serial.print(F(" "));
  //    Serial.print(orientation.pitch);
  //    Serial.print(F(" "));
  //  }
  //  
  //  /* Calculate the heading using the magnetometer */
  //  mag.getEvent(&mag_event);
  //  if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &orientation))
  //  {
  //    /* 'orientation' should have valid .heading data now */
  //    Serial.print(orientation.heading);
  //  }
  //  Serial.println(F(""));

  /* Calculate the altitude using the barometric pressure sensor */
  bmp.getEvent(&bmp_event);
  if (bmp_event.pressure)
  {
    /* Get ambient temperature in C */
    float temperature;
    bmp.getTemperature(&temperature);
    /* Convert atmospheric pressure, SLP and temp to altitude */
    Serial.print(F("Alt: "));
    Serial.print(bmp.pressureToAltitude(seaLevelPressure,
                                        bmp_event.pressure,
                                        temperature)); 
    Serial.println(F(""));
    /* Display the temperature */
    Serial.print(F("Temp: "));
    Serial.print(temperature);
    Serial.println(F(""));
  }
  
  delay(100);
}

-- EDIT --

I'm pretty sure the board is dead. The program stops at accel.begin(), mag.begin(), or bmp.begin(); I've tried each individually.

2
  • same issues, ordered board from AliExpress. Using this code however, I can report that in my case, the board is not dead an reports some values - it just is not recognized somehow. int yAxis = analogRead(A4); // Yout pin of accelerometer Serial.print(","); Serial.print(yAxis); Commented Sep 7, 2020 at 7:42
  • @user2305193 Fascinating. Please let me know how it turns out!
    – Jacksonkr
    Commented Sep 7, 2020 at 15:47

3 Answers 3

1

Check each of your conditional statement at

if(!accel.begin())
  {
    /* There was a problem detecting the LSM303 ... 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(!bmp.begin())
  {
    /* There was a problem detecting the BMP180 ... check your connections */
    Serial.println("Ooops, no BMP180 detected ... Check your wiring!");
    while(1);
  }

by commenting the others.

1

I had a similar issue. Turns out it was faulty wiring, probably due to a cheap breadboard (as a noob you would expect perfect connectivity from something like a breadboard! Turns out: not at all!)

Here's how I went about debugging it, using an i2c scanner to debug connectivity (find library + example here).

  1. remove the while(1) loops that halt your program, so the program doesn't 'stop' on error
  2. Use an 'error variable' e.g. fail. Initialize e.g. as fail=0 at start of script so it's global. Add fail=1 for every oops case in initSensors()
  3. in loop(), check if fail==0, if yes, continue with outputting the 10DOF sensor values, if there is an error (fail==1) call initSensors() and the i2cscanner() so you get a debugging view of your connectivity. This would look like below, and will keep calling the debug function until you connected it properly.

Hope this was useful or at least interesting to you, good luck.

Screenshot of i2c scanner:

enter image description here

0

I this one of many Arduino invented terminology ? Normally function returns ZERO on success and -1 or positive number identifying the error.

if(!accel.begin())

{ /* There was a problem detecting the LSM303 ... check your connections */ Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!")); while(1); }

1
  • 1
    Different functions return different things. Functions that handle buffers supplied by the caller typically return the caller's buffer pointer on success or a NULL pointer on failure, for one of many counter-examples. You can't assume what choices another author made without reading the description or the code itself. The author of this library wrote the .begin() function to return a bool; TRUE on success, and FALSE otherwise. It is not uncommon.
    – JRobert
    Commented Sep 20, 2018 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.