MPU9250/6500 high noise on Debian 13 Trixie

Basic Information:

Printer Model: Sunlu S8
MCU / Printerboard: Stock (Atmega2560) moded with TMC2209
Host / SBC: Raspberry Pi Zero 2W, RPi OS Lite x64 Trixie
klippy(7).log (93.2 KB)

Describe your issue:

Hi.
I use MPU9250 as accelerometer for Input shaper.
I noticed that when I query noise in Klipper, I get very high value.
Also query of accelerometer return very varying values:

0:46

accelerometer values (x, y, z): -9217.676392, -52131.346948, 9859.322437

0:46

ACCELEROMETER_QUERY

0:46

accelerometer values (x, y, z): 10041.281763, -6306.327173, -8125.920435

0:46

ACCELEROMETER_QUERY

0:46

accelerometer values (x, y, z): -69295.378650, 9251.195215, -6062.118604

0:46

ACCELEROMETER_QUERY

0:46

Axes noise for xy-axis accelerometer: 1009981.508942 (x), 983840.261497 (y), 1149799.548981 (z)

0:46

MEASURE_AXES_NOISE

So I wrote a small python program which query data from accelerometer and do statistics, and it looks pretty normal over 1min and 64379 samples:

       N                     Baseline[g]                     Avg|dev|[g]                     Max|dev|[g]
     566  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0113,  +0.0108)  ( +0.0362,  +0.0410,  +0.0377)
    1629  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0113,  +0.0109)  ( +0.0384,  +0.0422,  +0.0428)
    2693  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0113,  +0.0107)  ( +0.0384,  +0.0422,  +0.0487)
    3756  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0094,  +0.0114,  +0.0110)  ( +0.0384,  +0.0462,  +0.0487)
    4819  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0114,  +0.0113)  ( +0.0391,  +0.0608,  +0.0487)
    5882  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0115,  +0.0114)  ( +0.0391,  +0.0608,  +0.0501)
    6945  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0114,  +0.0114)  ( +0.0391,  +0.0608,  +0.0501)
    8009  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0114)  ( +0.0391,  +0.0608,  +0.0501)
    9073  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0091,  +0.0114,  +0.0114)  ( +0.0391,  +0.0608,  +0.0501)
   10137  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0113)  ( +0.0391,  +0.0608,  +0.0501)
   11201  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0113,  +0.0113)  ( +0.0413,  +0.0608,  +0.0501)
   12265  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0113)  ( +0.0413,  +0.0608,  +0.0501)
   13329  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0113)  ( +0.0413,  +0.0608,  +0.0560)
   14392  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0113,  +0.0112)  ( +0.0413,  +0.0608,  +0.0560)
   15456  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0113,  +0.0112)  ( +0.0413,  +0.0608,  +0.0560)
   16519  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0112)  ( +0.0451,  +0.0608,  +0.0560)
   17583  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0112)  ( +0.0451,  +0.0608,  +0.0560)
   18646  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0112)  ( +0.0451,  +0.0608,  +0.0560)
   19710  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0112)  ( +0.0451,  +0.0608,  +0.0560)
   20774  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0112)  ( +0.0451,  +0.0608,  +0.0560)
   21837  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0112)  ( +0.0451,  +0.0608,  +0.0560)
   22901  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0112)  ( +0.0451,  +0.0608,  +0.0560)
   23964  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0112)  ( +0.0451,  +0.0608,  +0.0560)
   25027  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0114,  +0.0112)  ( +0.0451,  +0.0608,  +0.0560)
   26091  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0114,  +0.0112)  ( +0.0451,  +0.0608,  +0.0560)
   27156  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0114,  +0.0112)  ( +0.0451,  +0.0608,  +0.0560)
   28219  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0114,  +0.0112)  ( +0.0540,  +0.0608,  +0.0560)
   29283  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0112)  ( +0.0540,  +0.0608,  +0.0560)
   30347  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0112)  ( +0.0540,  +0.0608,  +0.0560)
   31410  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0112)  ( +0.0540,  +0.0608,  +0.0560)
   32474  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0114,  +0.0112)  ( +0.0540,  +0.0608,  +0.0560)
   33537  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0112)  ( +0.0540,  +0.0608,  +0.0675)
   34601  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0112)  ( +0.0540,  +0.0608,  +0.0675)
   35664  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0112)  ( +0.0540,  +0.0608,  +0.0675)
   36727  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0112)  ( +0.0540,  +0.0608,  +0.0675)
   37790  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0112)  ( +0.0540,  +0.0608,  +0.0675)
   38854  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0112)  ( +0.0540,  +0.0608,  +0.0675)
   39917  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0112)  ( +0.0540,  +0.0608,  +0.0675)
   40981  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   42044  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0112)  ( +0.0540,  +0.0684,  +0.0675)
   43107  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   44171  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0112)  ( +0.0540,  +0.0684,  +0.0675)
   45235  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   46299  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   47362  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   48426  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   49490  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   50553  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   51617  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   52680  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   53743  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   54807  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   55870  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   56934  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   57998  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   59060  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   60123  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0092,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   61187  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   62251  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   63315  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)
   64379  ( -0.0050,  +0.0001,  +0.9850)  ( +0.0093,  +0.0115,  +0.0113)  ( +0.0540,  +0.0684,  +0.0675)

Any idea?
I have the MPU connected using USB 3.0 cable, which is shielded and both I2C lines are twisted pairs with GND.
The measuring is done when the printer is still (motors inactive, fans inactive) and the MPU is mounted directly on the nozzle.

Thanks

In Klipper accelerometer data is used in the frequency domain. Seismic accelerometers are 10x as expensive as vibration accelerometers. The only use your static measurements have is to do a FFT and verify the NOISE is spread across the frequency spectrum. If the FFT shows a distinct peak(s) then you have INTERFERINCE not noise.

As far as identifying resonance frequencies noise and linearity of the accelerometer are of surprisingly little concern. If you want a ODS (opperational deflection shape) then you are going to need several much better accelerometers and a MUCH higher sample rate.

Found mpu-6500 with id 70

It is possible that there are scaling math errors, or something.
You can utilize this example to stream data from the accelerometer:

#!/usr/bin/env python3

import json
import socket
import statistics
from websocket import create_connection

ws = create_connection("ws://localhost:7125/klippysocket")
ws.send(json.dumps({"id": "1", "method": "adxl345/dump_adxl345", "params": {"sensor": "adxl345"}}))

freqs = []
while True:
    params = json.loads(ws.recv()).get("params")
    if params:
        d = params["data"]
        for row in d:
            print(row)

You only need to change the endpoint.

Assuming everything is fine with the wiring, your best bet is to check the host-side code against the MPU6500 datasheet.

Just for referece normal accelerometer output would look like so:

$ ACCELEROMETER_QUERY
// accelerometer values (x, y, z): -148.041188, 0.000000, -9030.512492

So, small noise at X, Y, and around G acceleration at Z. If axis are set correctly and the accelerometer is alligned.

Hope that helps a little.

-Timofey.

Thanks for replies.
@cardoc So the value ACCELEROMETER_QUERY is not accel value, but it’s already this “vibration” calculation?

@nefelim4ag Thanks. Here is output of the script running for a while:

mpu_output.txt (3.0 MB)

The MPU is mounted in correct axis, except it’s upside down

It is in fact the acceleration value. BUT that data is not directly used by the input shaper. The input shaper routine converts the acceleration data into the frequency domain.

Even if the source data is noisy the process still yields an accurate resonance frequency of the structure on which the accelerometer is mounted.

Are you having a situation where the recommended input shaper values are not yielding good results?

Understood, but what I mean is, that these readings should be similar to what I can read from the MPU manually (I used mpu9250-jmdev library).
I tried to make measurements and it looks that it still somehow works, but I’m not sure if the data are correct. Because the main resonant frequency looks too low for me and it’s also pretty same in all 3 axis…

As already mentioned above, implementation can have errors.
Only person who have the device can do something with it.
You can compare library output with klipper sensor output for example.
You can validate that output data rate is as expected (sanity check, if ODR is correct, at least this part is working).

I doubt that you have resonance at 10Hz, unless you have enormous machine.

Ah, and again, at least klipper thinks it is MPU-6500 according to the logs.

Datasheet: https://invensense.tdk.com/wp-content/uploads/2020/06/PS-MPU-6500A-01-v1.3.pdf
Register map: https://invensense.tdk.com/wp-content/uploads/2015/02/MPU-6500-Register-Map2.pdf

-Timofey.

I will try to do some investigation.
The MPU type is OK, MPU9250 is in reality MPU6500 with added AK8963 magnetometer in one package, the registers should be the same :slight_smile:

Update: It looks like I got really MPU6500 instead of MPU9250 (marking on the chip is MP65M). Which still should not be a problem, we don’t use magnetometer anyway.
Klipper doesn’t have even special config for 6500.

I also found that use @Nightyly already encountered this problem, but it wasn’t solved:

OK, I found probably the source of the problem.

I booted old SD card with Mainsail OS bullseye and the MPU is working fine even with the latest Klipper:

20:01
Axes noise for xy-axis accelerometer: 72.018556 (x), 70.856982 (y), 104.714691 (z)
20:01
MEASURE_AXES_NOISE
20:01
accelerometer values (x, y, z): -13158.532324, -7800.309009, -1479.616626
20:01
ACCELEROMETER_QUERY
20:01
accelerometer values (x, y, z): -12971.784595, -7857.769849, -1623.268726
20:01
ACCELEROMETER_QUERY
20:01
accelerometer values (x, y, z): -12938.265771, -7829.039429, -1522.712256
20:00
ACCELEROMETER_QUERY
20:00
accelerometer values (x, y, z): -12952.630981, -7738.059766, -1503.558643
20:00
ACCELEROMETER_QUERY
20:00
accelerometer values (x, y, z): -13105.859888, -7718.906152, -1450.886206
20:00
ACCELEROMETER_QUERY

So the problem is with the latest Debian 13 Trixie (or with the Python 3.13)

Unless your printer is sitting on a folding table or a similar wobbly surface.

I have it on a massive table and the printer is sitting on a concrete block :slight_smile:

Now the measuring looks more legit:

1 Like

I don’t know why, but it still happens that I have this 9.5Hz peak on all axis.
I first though that it’s problem of mounting, as after remounting on Y axis I was able to measure the previous graph.
But now even on the same place with the same mounting I’m still not able to get valid result.
What is weird, that it doesn’t happen on X axis.
Maybe it has something to do with the orientation of the accelerometer? On X axis I have it on the nozzle upside down, but on Y I have it on the build plate with opposite (correct) Z direction.

Y axis

X axis

I have suspicion that it has something to do with the last changes in Klipper in Input shaper.
I will try rollback…

Update: Rollback didn’t help, so it’s probably some problem with sensor or printer.
I ordered new ADXL345 to compare.