Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    Reading the Chip ID of BMX 160 Sensor via I2C using Python Application

    Reading the Chip ID of BMX 160 Sensor via I2C using Python Application

    Karthik_NT
    New Poster

    Hello All ,

    I am trying to write a python application which could read the Chip ID of the BMX 160 sensor. However i am not able to read the version.

    We have an Hardware (Xilinx Zynq) Tec0204 hardware which also has an integrated BMX160 sensor for reading the 3-axis information.

    To begin with I wanted to write an application and copy this python application in the target (TEC0204) and then read the BMX160 chip ID version via I2C by running the command python {filename}.py. However everytime i run this command i am getting the error message as no such device or address.

    Note i have checked the /dev/i2c* to see the i2c stuff and both i2c-0 and i2c-1 could be seen.

    Could someone please provide inputs to resolve this error.

    Attached is the data sheet of BMX160 sensor and also my python application code.

    Python Code :

    import os
    import fcntl

    # I2C device file
    I2C_DEV = "/dev/i2c-1" # Use '/dev/i2c-0' for older Raspberry Pi boards

    # I2C address of the BMX160 IMU sensor
    BMX160_ADDR = 0x68

    # Register addresses for chip ID
    CHIP_ID_ADDR = 0x00

    def read_i2c_byte_data(i2c_fd, register_addr):
    os.write(i2c_fd, bytes([register_addr]))
    return os.read(i2c_fd, 1)

    # Open the I2C bus
    i2c_fd = os.open(I2C_DEV, os.O_RDWR)

    # Set the I2C slave address
    fcntl.ioctl_arg = BMX160_ADDR
    fcntl.ioctl(i2c_fd, 0x0703, fcntl.ioctl_arg)

    # Read chip ID
    chip_id_data = read_i2c_byte_data(i2c_fd, CHIP_ID_ADDR)


    # Close the I2C bus
    os.close(i2c_fd)

    # Extract chip ID and version
    chip_id = int.from_bytes(chip_id_data, "big")


    # Print the chip ID
    print(f"Chip ID: 0x{chip_id:02X}")

    Thank you

    3 REPLIES 3

    BSTRobin
    Community Moderator
    Community Moderator

    Hi Karthik_NT,

    You can set BMX160 address according your hardware design.

    2023-05-24_11h34_13.png

    There was official BMX160 sensor API and exmaple which was written by C language on github https://github.com/boschsensortec/BMI160_driver for your reference.

    Hi Robin,

    This is an Hardware Step 1 Xilinx Zynq processor target with BMX160 sensor integrated.

    I updated the python application code as below and now I am able to get the response from the register 0x00 , however it is not reading the Chip ID as 0xD8 which is an expected Chip ID. Instead it is always reading 0x00.

    In addition when i check the drivers in /sys/bus/i2c/drivers path in linux debian OS , i could see that bmg160_i2c drivers are their and i tried binding them to the channel 0 and address 0x69 (0-0069). However currenty the issue still persisting where my chip id is always 0x00.

    Could you suggest me any inputs in this regard on where possibly we are going wrong or any specific checks which we need to do here.

    Python Code Snippet:

    import os
    import fcntl
    import time

    # I2C device file
    I2C_DEV = "/dev/i2c-0"

    # I2C address of the BMX160 IMU sensor
    BMX160_ADDR = 0x69

    # Register addresses for chip ID and version
    CHIP_ID_ADDR = 0x00

    def read_i2c_byte_data(i2c_fd, register_addr):
    os.write(i2c_fd, bytes([register_addr]))
    return os.read(i2c_fd, 1)

    # Open the I2C bus
    i2c_fd = os.open(I2C_DEV, os.O_RDWR)

    # Set the I2C slave address
    fcntl.ioctl(i2c_fd, 0x0703, BMX160_ADDR)

    #Add a delay
    time.sleep(1)

    # Read chip ID
    chip_id_data = read_i2c_byte_data(i2c_fd, CHIP_ID_ADDR)

    # Close the I2C bus
    os.close(i2c_fd)

    # Extract chip ID and version
    chip_id = int.from_bytes(chip_id_data, "big")

    # Print the chip ID
    print(f"Chip ID: 0x{chip_id:02X}")

    Output in Target:

    Karthik_NT_0-1684901875980.png

    Drivers seen in Tagret i2c:

    Karthik_NT_1-1684901925818.png

    Any inputs on this would be helpful

     

     

     

    BSTRobin
    Community Moderator
    Community Moderator

    Hi Karthik_NT,

    We are not familiar with the software environment of the Xilinx Zynq processor platform.
    I upload BMX160 example code for your reference. I hope it will be helpful for you.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist