Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPU9250 Magnetometer Access Issue: [Errno 5] EIO on Passthrough Mode with Raspberry Pi Pico #30

Open
severus-sys opened this issue Nov 13, 2024 · 1 comment

Comments

@severus-sys
Copy link

severus-sys commented Nov 13, 2024

I'm currently trying to access the magnetometer on the MPU9250 using passthrough mode with a Raspberry Pi Pico. While I can establish communication with the MPU itself, I am unable to access the magnetometer (AK8963), which results in an [Errno 5] EIO (input/output error). Below, I've provided the details of my setup, the code I used, the steps I took, and the errors I encountered.

Hardware Setup

Microcontroller: Raspberry Pi Pico
Sensor: MPU9255 9-axis IMU module (with integrated AK8963 magnetometer)
Connections:
SCL: Connected to GPIO 27
SDA: Connected to GPIO 26
3.3V and GND: Connected to appropriate pins

Code

The code below aims to initialize the MPU9255, enable passthrough mode to access the AK8963 magnetometer, and continuously read magnetometer data:



from machine import I2C, Pin
from utime import sleep_ms

#Initialize I2C
i2c = I2C(1, scl=Pin(27), sda=Pin(26))

#MPU9255 and Magnetometer (AK8963) Addresses
MPU_ADDRESS = 0x68
MAG_ADDRESS = 0x0C

try:
    #Verify connection to MPU9255
    chip_id = i2c.readfrom_mem(MPU_ADDRESS, 0x75, 1)
    print("MPU9255 connected. Chip ID:", chip_id[0])

    #Wake up MPU9255
    i2c.writeto_mem(MPU_ADDRESS, 0x6B, b'\x00')
    sleep_ms(100)

    #Disable I2C Master Mode and Enable Passthrough
    i2c.writeto_mem(MPU_ADDRESS, 0x6A, b'\x00')
    i2c.writeto_mem(MPU_ADDRESS, 0x37, b'\x02')
    sleep_ms(100)

    #Attempt to initialize magnetometer in continuous reading mode
    i2c.writeto_mem(MAG_ADDRESS, 0x0A, b'\x16')  # 16-bit resolution, 100Hz continuous reading
    sleep_ms(100)

    #Reading magnetometer data in a loop
    while True:
        mag_data = i2c.readfrom_mem(MAG_ADDRESS, 0x03, 6)
        mag_x = int.from_bytes(mag_data[0:2], 'little', signed=True)
        mag_y = int.from_bytes(mag_data[2:4], 'little', signed=True)
        mag_z = int.from_bytes(mag_data[4:6], 'little', signed=True)
        print("Magnetometer X:", mag_x, "Y:", mag_y, "Z:", mag_z)
        sleep_ms(100)

except Exception as e:
    print("Communication error:", e)

Steps Taken

Verified the connection to the MPU9255, checking its Chip ID (0x68) at register 0x75.
Woke up the MPU9255 by writing 0x00 to register 0x6B (Power Management 1).
Disabled I2C Master Mode and enabled Passthrough mode by writing to registers 0x6A (USER_CTRL) and 0x37 (INT_PIN_CFG), respectively.
Attempted to initialize the magnetometer (AK8963) in continuous reading mode by writing 0x16 to register 0x0A.
Executed a loop to read magnetometer data from 0x03, expecting six bytes for the X, Y, and Z axes.

Issues Encountered

After following the above steps, the output shows that:

The MPU9255 is detected and successfully initialized: "MPU9255 connected. Chip ID: 112"
However, attempting to access the magnetometer in passthrough mode results in an [Errno 5] EIO error, indicating an input/output error.

Output:

MPY: soft reboot
MPU9255 connected. Chip ID: 112
Communication error: [Errno 5] EIO

Troubleshooting Attempts

I2C Scanning: After enabling passthrough mode, I used i2c.scan() but could not detect the expected magnetometer address (0x0C).
Alternative I2C Addresses: I also tested common magnetometer addresses (0x0D, 0x0E, 0x0F) in case of an addressing discrepancy, but these were also undetectable.
Hardware Connections: Verified that SDA, SCL, GND, and 3.3V connections are correct and stable.
Pull-up Resistors: Added 4.7kΩ pull-up resistors to the SDA and SCL lines, but this did not resolve the issue.
Request for Assistance
Are there any additional register configurations required to enable passthrough mode on the MPU9255?
Could this be a compatibility issue with certain MPU9255 modules that affects passthrough access to the AK8963 magnetometer?
Any known issues or solutions related to accessing the magnetometer on MPU9255 in passthrough mode?
Thank you for your assistance!

@peterhinch
Copy link
Contributor

This doesn't seem to be an issue with this driver: the sample code does not use the driver.

FWIW the driver engages passthrough mode here. It has been tested with the Pico.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants