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