Error in using i2c bus 1 for addressing devices on jetson nx

Hi,

I am trying to inferace compass LSM303(Mag+Accel) on Jetson NX at the i2c bus 1. The compass has i2c address 0x1e which the i2cdetect command indicates on Jetson NX.

As Jetson NX has 2 default i2c buses, 8 and 1, I connected the compass to i2c bus 8 and the compass worked - gave headings. But since the i2c bus 8 in my project is occupied by PCA 9685, I want compass to work at bus 1. This bus 1 gives error, “ValueError: No I2C device at address: 0x1e”.



Interestingly, when pins are probed using i2cdetect -y -r [bus address] to check for compass when connected to i2c bus 1 or 8, both times the compass is detected accurately.
sc1 sc2

For the compass lsm303 to work I installed, pip3 install adafruit-circuitpython-lsm303dlh-mag from the link and pip3 install adafruit-circuitpython-lsm303-accel link

Also running code using the PCA board at bus 1 throws error “ValueError: No I2C device at address: 0x40”. Both devices compass and PCA when connected to bus 8 get detected but give error when utilized during a code run.

I tried a raspberry pi technique but did not work mostly due to bcm2708

dtparam=i2c_arm=on
dtoverlay=i2c0-bcm2708,sda0_pin=28,scl0_pin=29,pin_func=4

And
Will changing the dts file and compiling help, although I have never worked on them before. What is the recommended operation to make use of i2c bus 1 for devices to work.

Thanks

If i2cdetect/i2cget working well I think there’s no dts problem. You may need to check the python code to figure it out.

Sure I will look into it @ShaneCCC , if there is anything specifically given with respect to the i2c buses in the library of these sensors.
Because I am using an example code for these sensors which work on bus 8 and my code in jupyter cells suggest that right after the i2c variable picks address from board.I2C() bus and forwards it to the library to parse data at
mag = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)
it throws an error.

I also wanted to know, is the bus 8 on Jetson NX or bus 0 on Jetson Nano a primary/default i2c bus which is always enabled. Is there any difference between the two i2c buses?

Thanks

Suppose they are always enable without any different.

I tried the suggestions @ShaneCCC but the python code did not give any leads to fixing the issue.
I checked the i2c acknowledgements with
dmesg
and I think the result might be helpful hence sharing the text file of log mydmesg.log (128.9 KB)
and part of the screenshots below:




skipped some lines here
i2c3

While i2cdetect is still gives the same outputs.

I have also tried MCP2221a (usb to i2c converter) to bypass the issue of i2c pins but the results are the same.
I also experimented with a barometer MPL3115A2 to see whether the cause of the issue earlier was the device or its library specific. But no success with the change in devices over the i2c bus-1 as well as with the usb to i2c converter.

I also came across another post which had faced some similar issues with TX2 (Link). I am not sure if the methods suggested there will be useful in my case since I do not have multiple devices on an i2c bus instead I have a device on each bus. I hope the dmesg message will be of help in resolving this.

Thanks

Do you check i2cget to access those address have the same message?

Again after using i2cdetect command I used i2cget and the device gets detected but the issue persists, sharing screenshot @ShaneCCC
i2cget

Finally got the issue resolved @ShaneCCC
On deeper looker into the libraries used in the example python code the issue lied in the return values for i2c pins, only bus 8 was considered by the board module.
For those who face similar issues in future, the solution for such issue was to bring changes to the (board · PyPI) library in .local folder and make changes to the i2c return variables based on device and the assigned buses which was bus 1 in Jetson NX for me.

An alternative is to use the adafruit-extended-bus library, which allows you to set the specific I2C bus.

$ sudo pip3 install adafruit-extended-bus

Then in your Python script:

i2c=I2C(1)

if you want to use bus 1. This avoids having to change the board library.

1 Like