Trouble installing library for ICM20948 DoF Motion Sensor

Hi, I’ve so far been able to install all other Breakout Garden modules (five or six of them), but it seems that no matter how I install the libraries for the ICM20948 I get a response like:

  File "./magnetometer.py", line 21, in <module>
  imu = ICM20948()
  File "/usr/local/lib/python3.7/dist-packages/icm20948-0.0.1-py3.7.egg/icm20948/__init__.py", line 224, in __init__
RuntimeError: Unable to find ICM20948

This either by installing via a download from github (either zip or clone) and using its install.sh, or “sudo pip3 install icm20948”. As I mentioned, other modules (like the VL53L1X, 5x5 LED matrix, the 10A switch or ADS1015) work fine. I’ve uninstalled and reinstalled several times to no avail.

I’ve tried running the magnetometer.py example either from the ./examples directory or from my own work directory, using either python 2 or 3 (I’m generally using Python 3). Always the same result, as above. The ICM20948 module does show up at 0x68 when queried using i2cdetect, so this seems entirely to be a software issue.

This is on a Raspberry Pi B+. Curiously, I also have a Pi Zero W and it works fine on that.

Thanks!

If you take the Micro SD card from the Pi Zero, and swap that into the B+ does it work?

That was a good suggestion, and I was optimistic. I have two robots, so as you suggested I swapped the SD card from the robot with the functional ICM20948 to the robot without, but unfortunately I (curiously) got the same error message as previously described.

I looked into the contents of the dist-packages directory to see if there was anything different, but of the two icm20948-related directories, the files and file sizes are all the same. Same versions of python 2 and 3 on both robots, and I’m not doing anything unusual like setting PYTHONPATH.

I hate to think I’d have to start from scratch on a new Raspbian… I’ve got a fair investment in time on that installation, but the 20948 is part of the plan for this robot’s navigation system so I guess I’ll keep trying to find out what’s up with this.

First let me just say I’m far from being any kind of software expert Linux wise.
Does the “Unable to find ICM20948” mean it can’t actually see it detect it? The hardware, or?
That it can find it software wise? It sounds like you might have a wiring error or something?
If the sensor was good and wired correctly I would have expected it to work with the Micro SD from the Pi Zero, why else wouldn’t it? You don’t maybe have two i2c devices with an 0x68 address or something going on?

This isn’t related to Linux expertise, it’s Python expertise, so far as I understand. I’ve been a software developer for many years, but part of my robotics exploration is learning Python, so I’m hardly an expert in that department. But apparently the import path on Python can be a rather tricky beast.

I would have hoped the default install (“sudo pip3 install icm20948”) would simply work in most cases, and my Raspbian installation isn’t custom or unusual in any way – I just installed Python 2 and 3 using the normal methods, and other Breakout Garden sensors seem to work fine.

So far as I know my I2c bus is functioning fine, and there’s only one device at 0x68 (I’ve just got a 5x5 matrix LED plugged in right now). The functional Pi Zero is obviously a curiosity. I’d simply replace the OS on the larger robot except it’s actually running on an SSD (rather than an SD card) so that’s a bit trickier, but it sounds like a fresh install might (at least as an experiment) be necessary.

Thanks!

Ok, my Python skills are self taught, and about average or maybe a little below average, lol. Give me a working example and I can usually bend it to do what I want. Or add to it to get where I need to go. With lots of head scratching on the way.
I’m a retired electronic technician, the wiring side is usually easy peasy for me. It’s the coding side of things that slows me down.
Either way, right now, I have no idea what is messing things up for you. All I can say is I’ve been there and its really frustrating. I’ll keep watching and mulling over though.

Okay, here’s more information: today I just downloaded and installed a fresh copy of Raspbian Buster on an SD card, got it up and running on the Raspberry Pi 3 B+ robot (as described above), and installed the ICM20948 software using pip3. I downloaded the examples from the github site and tried running magnetometer.py and sad to say, I’m getting the same error message as before (“Unable to find ICM20948”). I then installed pip and tried it with python 2, same result.

No idea what to do now. I’d have thought a fresh install would have been the solution. The Raspberry Pi 3 B+ is unmodified, the Raspbian OS is basically new, i2cdetect can see the board at 0x68 (so it’s not an I2C bus issue).

I note that the Adafruit BNO055 (which is also a 9 DoF sensor, I think based on the same chip) is known to be incompatible with the Raspberry Pi, which is one reason I’m using the Pimoroni product. The Adafruit pages state: “Raspberry Pi computers do not have I2C clock stretching support so they don’t work well with the BNO055 - you can try slowing down I2C”, but I don’t think this is related, i.e., the inability to find a Python library seems to be entirely a software issue.

Be careful using somebody else’s library, if thats what your doing? Double check that its looking at the correct address for said device. Adafriut’s version of item X may be using a different i2c address than Pimoroni’s item X. If you use Adafruit’s code on a the Pimoroni one it may not be able to find it, and vise versa. Thats caught me out once or twice.
I buy almost as much stuff at Adafruit as I buy here. Adafruit are more Arduino / Microcontroller orientated, and Pimoroni are well more Pi orientated. That gets me looking for code from other sources to get it working on a Pi. That usualy means double checking and some editing to make it work.

My plan as regards the BNO055 has been to actually install it onto a separate daughterboard and run it via an ItsyBitsy M4 Express, using the M4’s own I2C bus. But I haven’t gotten anywhere near starting on that. I was hoping to use the Pimoroni ICM20948 as that looks a lot easier than using a slave processor (though this would be a learning process in itself).

So no, I only mention the BNO055 as regards the clock-stretching issue. As I wrote, the new Raspbian OS is clean except for installation of the ICM20948 library via pip3. I hadn’t installed the Adafruit library on the earlier OS either, so that’s not an issue. But thanks for the notice, I agree. The address I’m seeing and looking for is 0x68, which is the one for the ICM20948.

I found these on Amazon. I’m going to pick up a set for small projects.

I’d kinda given up on ever getting the ICM20948 to work, but finally found this solution, which is basically to append the location of its library to the system path:

sys.path.append('/home/pi/Pimoroni/icm20948-python/library')
from icm20948 import ICM20948

While this isn’t very portable (it only works when the specified path is correct), I hope this helps anyone who runs into a similar issue (this solution can work for any library that can’t be found).