MPU9250 I2C bus failure



  • I update the driver for the MPU9250
    I managed to make it work only calibration doesn't work when I uuse this portion of code once i initialize the button it fails the I2C bus

    if i don't do any calibration i see the 9 values cahnging when i star moving the sensor

    >>> execfile("irqtest.py")
    You should see slightly different values on each pair of readings.
                Accelerometer                               Gyro                                Magnetometer
    Interrupt: [0.0, 0.0, 0.0] [0.0, 0.0, 0.0] [0.0, 0.0, 0.0]
    Normal:    (0.08520508, 0.9992676, 0.1296387) (-0.8091603, 0.6946565, 1.061069) (20.03906, -19.04766, -10.53516)
    
    Interrupt: [0.08520508, 0.9992676, 0.1296387] [-0.8091603, 0.6946565, 1.061069] [20.03926, -19.04785, -10.53526]
    Normal:    (0.08764648, 0.998291, 0.1298828) (-1.229008, 0.6259542, 1.290076) (19.33594, -19.40039, -11.89453)
    
    Interrupt: [0.08764648, 0.998291, 0.1298828] [-1.229008, 0.6259542, 1.290076] [19.33613, -19.40059, -11.89465]
    Normal:    (0.08422852, 1.002441, 0.1325684) (-0.9083969, 0.7633588, 1.129771) (18.10547, -18.51855, -9.005859)
    
    
    >>> button = Pin("G17",  mode=Pin.IN,  pull=Pin.PULL_UP)
    >>> imu.mag.calibrate(button)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/flash/lib/vector3d.py", line 66, in calibrate
      File "/flash/lib/mpu9250.py", line 174, in _mag_callback
    MPUException: I2C failure when communicating with IMU
    
    

    original code

    >>> from  mpu9250 import MPU9250
    >>> a = MPU9250('x')
    >>> a.mag.cal
    (0, 0, 0)
    >>> import pyb
    >>> sw = pyb.Switch()
    >>> a.mag.calibrate(sw) # User rotates unit about each axis then presses the Pyboard switch
    >>> a.mag.cal
    (35.30567, 18.92022, -9.428905)
    >>>
    

    any idea why button init will fail the I2C ?



  • @gas
    will be good to see exact error message and place
    try change exception handling

    try:      
                where = 1                  
                # If read fails, returns last valid data and
                self._read(self.buf1, 0x02, self._mag_addr)  # increments mag_stale_count
                where = 2  
                if self.buf1[0] & 1 == 0:
                    where = 3  
                    return self._mag                # Data not ready: return last value
                where = 4
                self._read(self.buf6, 0x03, self._mag_addr)
                where = 5  
                self._read(self.buf1, 0x09, self._mag_addr)
                where = 6
    except OSError as e:
                raise MPUException(self._I2Cerror + str(e) + 'where: ' + str(where))


  • I forked the master and the modified code is on

    https://github.com/gesaleh/micropython-mpu9x50
    I think I was calbiration was conflicting with the previous execution of the code

    main modification are delay, pyb to time,machine classes



  • @gas said in MPU9250 I2C bus failure:

    without detail about code - really hard to tell
    do you use this?
    https://github.com/micropython-IMU/micropython-mpu9x50/blob/master/mpu9250.py
    https://github.com/micropython-IMU/micropython-mpu9x50/blob/master/imu.py

    and how looks like your modifications?


Log in to reply
 

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.