ZaneL / Teensy-ICM-20948

Arduino library for the ICM-20948 motion tracking sensor -- with DMP support
62 stars 17 forks source link

some feedbacks #6

Closed nakeze closed 3 years ago

nakeze commented 3 years ago

Hi, I mostly want to thank you for this amazing library, so convenient ! There are some feedbacks I want to share with you, might also help future users.
1) In order to get the proper WhoAmI value : I had to change to change the SPI Frequency, which is hardcoded as 4Mhz. It might be interesting to set this value through a variable of the init function. Furthermore I don't know how much it is related to my config, but I had to set the digitalWrite calls between the SPI.beginTransaction() and SPi.transfert() of the idd_io_hal_read_reg and idd_io_hal_write_reg functions. Otherwise, impossible see the end of the init.

2) Sometimes, I experience a "Putting Icm20948 in sleep mode... Initialization failed. Error loading DMP3...". I didn't try to fix this yet, might be related to the mentioned modifications I made. Not occurring all the time, (1/4 uploads maybe).

Best Regards, Nicolas

M-Schrapel commented 3 years ago

I am trying to connect this sensor for DMP. How do I connect it to my microcontroller to get the DMP functionality? Is SPI enough or do I have to connect the FIFO? The picture on the breadboard was not helpful for me.

Thanks in advance!

Best, Max

ZaneL commented 3 years ago

Hi, I mostly want to thank you for this amazing library, so convenient ! There are some feedbacks I want to share with you, might also help future users.

  1. In order to get the proper WhoAmI value : I had to change to change the SPI Frequency, which is hardcoded as 4Mhz. It might be interesting to set this value through a variable of the init function. Furthermore I don't know how much it is related to my config, but I had to set the digitalWrite calls between the SPI.beginTransaction() and SPi.transfert() of the idd_io_hal_read_reg and idd_io_hal_write_reg functions. Otherwise, impossible see the end of the init.
  2. Sometimes, I experience a "Putting Icm20948 in sleep mode... Initialization failed. Error loading DMP3...". I didn't try to fix this yet, might be related to the mentioned modifications I made. Not occurring all the time, (1/4 uploads maybe).

Best Regards, Nicolas

Thanks for the feedback! I'll have some free time in the next couple weeks so I'll look into these two issues and clean up the library a bit more. I've also experienced #2 where it only initializes properly maybe 75% of the time, unless I completely unplug the power and reconnect everything. Wasn't sure what was causing the problem, but I'll look into it more.

ZaneL commented 3 years ago

I am trying to connect this sensor for DMP. How do I connect it to my microcontroller to get the DMP functionality? Is SPI enough or do I have to connect the FIFO? The picture on the breadboard was not helpful for me.

Thanks in advance!

Best, Max

All you need to do is connect the hardware SPI pins on your board to the ICM-20948 SPI pins, as well as power and GND. You can pick whatever pin you want for CS and you specify that in the settings structure. For example:

TeensyICM20948Settings icmSettings =
{
  .cs_pin = 10,                  // SPI chip select pin
  .mode = 1,                     // 0 = low power mode, 1 = high performance mode
  .enable_gyroscope = true,      // Enables gyroscope output
  .enable_accelerometer = true,  // Enables accelerometer output
  .enable_magnetometer = true,   // Enables magnetometer output
  .enable_quaternion = true,     // Enables quaternion output
  .gyroscope_frequency = 1,      // Max frequency = 225, min frequency = 1
  .accelerometer_frequency = 1,  // Max frequency = 225, min frequency = 1
  .magnetometer_frequency = 1,   // Max frequency = 70, min frequency = 1
  .quaternion_frequency = 50     // Max frequency = 225, min frequency = 50
};

So to clarify, you need to connect the following: VIN (3.3V) GND MOSI MISO SCK CS

...and you'll probably need to use a board like a Teensy that has much more RAM + flash than an Arduino Uno.

ZaneL commented 3 years ago

Hi, I mostly want to thank you for this amazing library, so convenient ! There are some feedbacks I want to share with you, might also help future users.

  1. In order to get the proper WhoAmI value : I had to change to change the SPI Frequency, which is hardcoded as 4Mhz. It might be interesting to set this value through a variable of the init function. Furthermore I don't know how much it is related to my config, but I had to set the digitalWrite calls between the SPI.beginTransaction() and SPi.transfert() of the idd_io_hal_read_reg and idd_io_hal_write_reg functions. Otherwise, impossible see the end of the init.
  2. Sometimes, I experience a "Putting Icm20948 in sleep mode... Initialization failed. Error loading DMP3...". I didn't try to fix this yet, might be related to the mentioned modifications I made. Not occurring all the time, (1/4 uploads maybe).

Best Regards, Nicolas

Okay, so to address 1, I've added a setting in the settings structure where you can set the SPI speed. Look at the examples to see how it's done...pretty straightforward.

To address 2, I added a function call that does a soft-reset on the ICM-20948 before initializing it. As far as I can tell this fixed the issue.

I also removed the unnecessary initialization messages.