Getting stuck or failing imuBegin() for LSM9DS1 breakout

Started by jdheinzmann, March 08, 2024, 06:03:04 PM

jdheinzmann

I have a LPL LSM9DS1 IMU breakout board connected directly to a Moteino M0 that came with a RFM69HCW - 868/915Mhz transceiver installed.  Have adapted the example code Felix posted here: https://lowpowerlab.com/forum/low-power-techniques/lsm9ds1-power-consumption/msg29804/#msg29804 to specify USB for the serial port and add some Serial.prints for debug:

The important part of the code is this:

#if defined (MOTEINO_M0) && defined(SERIAL_PORT_USBVIRTUAL)
  #define Serial SERIAL_PORT_USBVIRTUAL // Required for Serial on Zero based boards
#endif

void setup() 
{
  pinMode(LED_BUILTIN,OUTPUT);
  Serial.begin(115200);
  delay(2000);
  Serial.println("Done with setup().");
}

byte imuSetup() {
  // Before initializing the IMU, there are a few settings
  // we may need to adjust. Use the settings struct to set
  // the device's communication mode and addresses:
  imu.settings.device.commInterface = IMU_MODE_I2C;
  imu.settings.device.mAddress = LSM9DS1_M;
  imu.settings.device.agAddress = LSM9DS1_AG;
  // The above lines will only take effect AFTER calling
  // imu.begin(), which verifies communication with the IMU
  // and turns it on.
  Serial.println("About to call imu.begin()...");
  if (!imu.begin())
  {
    Serial.println("Failed to communicate with LSM9DS1.");
    /*
    Serial.println("Double-check wiring.");
    Serial.println("Default settings in this sketch will " \
                  "work for an out of the box LSM9DS1 " \
                  "Breakout, but may need to be modified " \
                  "if the board jumpers are.");
    */
    return false;
  }
  Serial.println("Succeeded in communicating with LSM9DS1.");
  return true;
}

void loop()
{
  if (imuSetup()) {
    printGyro();  // Print "G: gx, gy, gz"
    printAccel(); // Print "A: ax, ay, az"
    printMag();   // Print "M: mx, my, mz"
   


Using version 2.0.0 of the SparkFunLSM9DS1 library I get only this:

Done with setup().
About to call imu.begin()...


which tells me that imu.Begin is getting stuck.

I reverted the library to version 1.2.0 and now I get this:

About to call imu.begin()...
Failed to communicate with LSM9DS1.
About to call imu.begin()...
Failed to communicate with LSM9DS1.
About to call imu.begin()...
Failed to communicate with LSM9DS1.
About to call imu.begin()...

etc


In this case imu.Begin appears to be returning false.

Does anyone know what might be causing this?  Any suggestions for troubleshooting it?

Thanks!  -JD

Felix

So with the unmodified sample sketch, you're not getting anything out of it?
That sketch is what I use to test these. I do the testing using a simple spring loaded probe JIG that's installed on a MoteinoM0, I press each board against the jig to init the connection, and wait until I can see the expected output on the serial port, that's it.

So software aside I would ensure solid correct connections. If possibly try with just the M0 and the IMU board alone, nothing else.

PS. The code blocks in the posts can be finicky depending what is pasted in the box, I think the multiline comments could sometimes be a problem.

jdheinzmann

#2
Hi, Felix,

No, first I added my comment block at the beginning and updated the declination numbers before trying it and got nothing.  Then I added the Serial.println() in setup and still got nothing.  Then I added:

#if defined (MOTEINO_M0) && defined(SERIAL_PORT_USBVIRTUAL)
  #define Serial SERIAL_PORT_USBVIRTUAL // Required for Serial on Zero based boards
#endif


and the print in setup() started working but nothing else.  Then I continued to add prints elsewhere to determine that imu.setup() wasn't returning.  Then I reverted to the earlier Sparkfun library to get imu.setup() to at least return false.  I also took a similar approach with the LSM9DS1_Basic_I2C.ino code on Sparkfun's GitHup repository and got essentially the same results.

By "try with just the M0 and the IMU board alone, nothing else" I assume you mean with the M0 not installed in my custom PCB?  I only have M0s with RFM69HCW transceivers installed.  Okay to keep that in place?

I'm trying to think of a good way to temporarily install the 9 DOF breakout on an M0.  Perhaps on a spare M0 I can install the same male headers I installed on the M0 before soldering it to my PCB, then using the same FM sockets on the backside of the breakout plug them together.  I have a spare breakout, so I can also try subbing that in.  I'll let you know how it goes.

Thanks for your help.

P.S. Actually I think the code blocks failed at the // comment I had included on the DECLINATION line I had modified.  It looks like maybe you cleaned up my posting struggles to make this thread easier to follow?  Well done!  Thank you for that! -JD

jdheinzmann

Well, the obvious thing to try first was the spare LSM9DS1 IMU breakout board.  It works just fine!  Swapping the old one back in, it doesn't work, the new one again and it works.  Problem solved.  Goodness only knows what I did to the old one to make it not work.

I should have thought to try that before opening this post. 

If I can get this IMU working as fast as the LIS3DH I was using, I will be interested in purchasing a few more.  Right now you have none in stock.  Should I expect to get the same throughput with this hard wired as an I2C device compared to the SPI configured LIS3DH?  The reason I want to switch to the LSM9DS1 is the anti-alias filter options it has.  I need to filter out the high frequency vibrations sometimes present even in the slowly idling giant steam engines I am monitoring.

Thank you for engaging with me on this, Felix. -JD

Felix

The LSM9DS1 was a pain to work with. And I think it was some other customer request that made it into a breakout.
I have worked with LIS3DH before. Would a breakout with that instead be of interest?

jdheinzmann

The LSM9DS1 does look like it will be a pain to interface but I want to try it because of the anti-alias filter options it has, and it interfaces directly with the M0 so I can use it with the PCB I made.  I hope I will be able to figure out how to enable the filters at the frequency I need without too much pain.

At this point, having a LIS3DH breakout that can be soldered directly to the M0 doesn't really matter to me because my PCB is laid out to interface with the SparkFun LIS3DH breakout.  But it was a simple board to work with and may be useful to others. Of course it is only a 3-axis accelerometer chip vs the 9D LSM9DS1 so it will not satisfy some applications.

Plus, the LIS3DH breakout can be accessed via SPI whereas your LSM9DS1 breakout is wired for I2C only (as far as I can tell).  I wish it could be used via SPI.  I hope the I2C interface will be fast enough for my purposes.

Back to the original issue, interestingly, I got the LSM9DS1 working using the SparkFun example code that I found on Github (not the code you posted on the LPL forum.)  Just to make sure it wasn't something I had done to the LPL code, I copied and pasted your code again without making any mods to the code.  It does not work for me.  Are you sure it still works for you, Felix?  I am using Sparkfun's version 2.0.0 of their library.

The approach in their example is a little different so I will proceed with theirs.

-JD 

Felix

Perhaps my compiled code that lives on that M0 tester is from many years ago and lib changes since then have done something to it. I'm out of stock with these so I have no way to test new code. Not planning to make more at this time, the eye watering prices makes this sensor dead to me.

jdheinzmann

Uh-oh, I better scrap my plans to source more of these breakouts from you then.  I see what you mean, Digi-key's unit price for qty 10 of the IMU chip is $22.24.  Maybe it's time for me to stop trying to make this work.  I should probably reconsider an analog 2 or 3 channel accelerometer and wire in my own analog LP filters.

Thank you again for your help, Felix.  -JD

Felix

It's my pleasure.
Once I free up from my current monster project I will plan to get back and develop more LPL storefront projects and products, it's been a while. And a nice well rounded IMU is in order to have in my lineup. Suggestions are welcome.