9dof Breakout ICM-20948 (Qwiic) slow data sampling

Hi all!

I’ve got the qwiic 9dof (ICM-20948) hooked up to a raspberry pi zero. I was hoping to use it along with a magnet to control an LED ring. Other functions will also be used.

I’m using python, and can upload my code later if it’s needed for scrutiny.

Everything seems to be working at a basic level, except the data sampling is very slow. It updates at best once per second, but on average maybe about once every 2 or 3 seconds. I need it to update multiple times per second, if not effectively real-time speeds.

Is this fixable?

Does the 9dof default to a non-continuous sampling, and should I change it? And how?

Should I bite the bullet and try porting to c++?

Thanks!

Share your code - that sensor can run in the MHz range :smiley:

Also check out the hookup guide for RPi here https://learn.sparkfun.com/tutorials/qw … okup-guide which might help shed some light on things

Usually I’d be trying to light up an LED, but simply printing runs slowly too.

Mind the choppiness, wanted to share the relevant bits, and the code is a work in progress.

Thanks again!

#!/usr/bin/python3

#Dotstar Board Stuff

import time

import board

import adafruit_dotstar as dotstar

from gpiozero import Button

import os

import qwiic_icm20948 as ninedof

from subprocess import check_call

import math

import random

#Dotstar Setup=========================================================================================

IMU = ninedof.QwiicIcm20948()

#IMU.setSampleMode(ICM_20948_Internal_Mag, ICM_20948_Sample_Mode_Continuous)

numPixels = 120

order = dotstar.BGR # I think this is right?

strip = dotstar.DotStar(board.SCK, board.MOSI, numPixels,

brightness=0.25, auto_write=False, pixel_order=order)

#Predefined Colors========================================================================================

black = 0x000000

white = 0xffffff

red0 = 0xff0000

green0 = 0x00ff00

blue0 = 0x0000ff

magenta0 = 0xff00ff

yellow0 = 0xffff00

cyan0 = 0x00ffff

gold0 = 0xffd700

orange0 = 0xff4400

orange1 = 0xff3300

orange2 = 0xff2200

orange3 = 0xff1100

#Interface Setup (1 button)=============================================================================================

trigger = Button(12, hold_time = 3)

triggerState=0

ninedofState=0

#Interface========================================================================================

while True:

IMU.begin()

if triggerState == 0:

if trigger.is_pressed:

ninedofState = 1

if ninedofState == 1:

if IMU.dataReady():

IMU.getAgmt()

Mx=IMU.mxRaw

My=IMU.myRaw

Mz=IMU.mzRaw

p=int(30+30*(math.atan2(Mx,My))/math.pi)

print(p)

Hmmm…nothing obvious sticks out, so I’d re-suggest running through the hookup guide https://learn.sparkfun.com/tutorials/qw … okup-guide and verifying the examples all work properly, then try the ‘Portable C’ version of the code found in the https://github.com/sparkfun/SparkFun_IC … master.zip - and modify that code for your use?

Got it working!

I ended up modifying some code directly from the python examples, and rewriting some of the math. Between the two, it’s working great now!

Thanks for the help!