# MPU 6050/9250 not working only in klipper

**URL:** <https://klipper.discourse.group/t/mpu-6050-9250-not-working-only-in-klipper/20943>\
**Category:** General Discussion\
**Created:** [December 27, 2024, 1:16am UTC](https://klipper.discourse.group/t/mpu-6050-9250-not-working-only-in-klipper/20943 "2024-12-27T01:16:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nightyly](https://avatars.discourse-cdn.com/v4/letter/n/e9a140/32.png) [@Nightyly](https://klipper.discourse.group/u/Nightyly)\
**Post date:** [December 27, 2024, 1:16am UTC](https://klipper.discourse.group/t/mpu-6050-9250-not-working-only-in-klipper/20943/1 "2024-12-27T01:16:47Z")

</div>

### Basic Information:

Printer Model: Ender 3 v2  
 MCU / Printerboard: SKR Mini e3 v3  
 Host / SBC: Rpi 4  
 [klippy.log](https://klipper.discourse.group/uploads/short-url/kOJzk9oQw5Yr2q7VtvG9BH5wLZ0.log) (454.2 KB)

### Describe your issue:

I am trying to get Input Shaping working in my printer, but found out that neither the MPU 6050 nor MPU 9250 work properly in klipper. I tested both sensors with the same cable in the same RPi that is running klipper with the following python script:

```auto
import smbus #import SMBus module of I2C

#some MPU6050 Registers and their Address
PWR_MGMT_1 = 0x6B
SMPLRT_DIV = 0x19
CONFIG = 0x1A
GYRO_CONFIG = 0x1B
INT_ENABLE = 0x38
ACCEL_XOUT_H = 0x3B
ACCEL_YOUT_H = 0x3D
ACCEL_ZOUT_H = 0x3F
GYRO_XOUT_H = 0x43
GYRO_YOUT_H = 0x45
GYRO_ZOUT_H = 0x47

def MPU_Init():
        #write to sample rate register
        bus.write_byte_data(Device_Address, SMPLRT_DIV, 7)

        #Write to power management register
        bus.write_byte_data(Device_Address, PWR_MGMT_1, 1)

        #Write to Configuration register
        bus.write_byte_data(Device_Address, CONFIG, 0)

        #Write to Gyro configuration register
        bus.write_byte_data(Device_Address, GYRO_CONFIG, 24)

        #Write to interrupt enable register
        bus.write_byte_data(Device_Address, INT_ENABLE, 1)

def read_raw_data(addr):
        #Accelero and Gyro value are 16-bit
        high = bus.read_byte_data(Device_Address, addr)
        low = bus.read_byte_data(Device_Address, addr+1)

        #concatenate higher and lower value
        value = ((high << 8) | low)

        #to get signed value from mpu6050
        if(value > 32768):
                value = value - 65536
        return value

bus = smbus.SMBus(1) # or bus = smbus.SMBus(0) for older version boards
Device_Address = 0x68 # MPU6050 device address

MPU_Init()

print (" Reading Data of Gyroscope and Accelerometer")

while True:

        #Read Accelerometer raw value
        acc_x = read_raw_data(ACCEL_XOUT_H)
        acc_y = read_raw_data(ACCEL_YOUT_H)
        acc_z = read_raw_data(ACCEL_ZOUT_H)

        #Read Gyroscope raw value
        gyro_x = read_raw_data(GYRO_XOUT_H)
        gyro_y = read_raw_data(GYRO_YOUT_H)
        gyro_z = read_raw_data(GYRO_ZOUT_H)

        #Full scale range +/- 250 degree/C as per sensitivity scale factor
        Ax = acc_x/16384.0
        Ay = acc_y/16384.0
        Az = acc_z/16384.0

        Gx = gyro_x/131.0
        Gy = gyro_y/131.0
        Gz = gyro_z/131.0

        print ("Gx=%.2f" %Gx, u'\u00b0'+ "/s", "\tGy=%.2f" %Gy, u'\u00b0'+ "/s", "\tGz=%.2f" %Gz, u'\u00b0'+ "/s", "\tAx=%.2f g" %Ax, "\tAy=%.2f g" %Ay, "\tAz=%.2f g" %Az)

```

Both sensors seem to work just fine with the script, but when running MEASURE\_AXES\_NOISE in klipper, the noise is an enormous value, upwards of 100,000. ACCELEROMETER\_QUERY gives nonsensical values as well.  
I noticed that after running either of the commands on klipper, the python script will not work (it will just keep “reading” the same values over and over), until I disconnect and reconnect the sensor from the RPi.

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![koconnor](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@koconnor](https://klipper.discourse.group/u/koconnor)\
**Post date:** [December 30, 2024, 11:34pm UTC](https://klipper.discourse.group/t/mpu-6050-9250-not-working-only-in-klipper/20943/2 "2024-12-30T23:34:05Z")

</div>

One suggestion I can make is to avoid mixing Klipper’s sensor code with any other Linux sensor code. That is, if you’ve attempted to access the sensor in any way with any tool other than Klipper, be sure to perform a full power-down of the RPi (and sensor) prior to running Klipper. I’ve seen cases where either the sensor or the system i2c interfaces get set to unexpected modes which can confuse both the Klipper code and external tools.

Otherwise, I can’t offer much help why the sensor would not be performing adequately.

Cheers,  
-Kevin

---

<div class="post-metadata">

**Author:** ![Nightyly](https://avatars.discourse-cdn.com/v4/letter/n/e9a140/32.png) [@Nightyly](https://klipper.discourse.group/u/Nightyly)\
**Post date:** [December 31, 2024, 1:08am UTC](https://klipper.discourse.group/t/mpu-6050-9250-not-working-only-in-klipper/20943/3 "2024-12-31T01:08:33Z")

</div>

Unfortunately that didn’t seem to work. The behaviour of both sensors is still the same after power cycling the RPi before each attempt.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/klipper/original/1X/64419bf2aac6639e6ef5cef200dcd456b0a01ac3.png) [@system](https://klipper.discourse.group/u/system)\
**Post date:** [March 1, 2025, 1:08am UTC](https://klipper.discourse.group/t/mpu-6050-9250-not-working-only-in-klipper/20943/4 "2025-03-01T01:08:34Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
