05-19-2023 06:13 PM
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
05-24-2023 05:36 AM
Hi Karthik_NT,
You can set BMX160 address according your hardware design.
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.
05-24-2023 06:19 AM
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:
Drivers seen in Tagret i2c:
Any inputs on this would be helpful
07-05-2023 09:40 AM