Inconsistent connectivity (Optical Tracking Sensor)

Hello all - I’m playing with the SparkFun Optical Tracking Sensor and trying to test it with an XRP robot running MicroPython

I’ve read the setup documentation and found a post on this Community Forum and have been able to connect to the I2C bus and verify (by pinging) that the sensor is online.

However, I get inconsistent results. Sometimes my program works and i can see the output of the scan and the code indicts that the sensor is connected. At other times, however, the code indicates that there are no devices on the bus and that the sensor is not online.

Power cycling my XRP/Raspberry Pi does not seem to reliably fix the problem.

Does anyone have tips on how I can improve the reliability of my connection to the I2C device?

Here’s my code

import qwiic_i2c
import qwiic_otos

my_bus = qwiic_i2c.get_i2c_driver(sda=4, scl=5, frequency=100000)

myOtos = qwiic_otos.QwiicOTOS(23, my_bus)

scan_list = my_bus.scan()
print(“Bus scan:”, scan_list)

ping_result = my_bus.ping(23)
print(“Device is connected:”, ping_result) 

Sometimes this works, and it is pretty consistent (i.e., I can run the program multiple times in a row with success)

Bus scan: [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119]
Device is connected: True

Other times the device is offline and power cycling the board and disconnecting and reconnecting the USB connection between my laptop and the device does not help clear the issue.

Bus scan: []
Device is connected: False

Is there something that I need to do to improve the consistency of my connections?

Thanks in advance.

It might be worth inspecting the qwiic cable for any potential defects, or swap a couple of them around and see if the issue moves/disappears

Are there any other devices on the i2c bus?

Hello - I don’t think there are any other devices on the Qwiic bus. I only have the one I2C device plugged in to the Qwiic port on the XRP’s controller board.

I can try and switch cables and retest it but it seems like a soft issue.

If I run my little sample program where I scan the bus and then ping the I2C device, it often works until it doesn’t. I think the problem comes when I try running an example program that I downloaded/cloned from the GitHub repo for the sample code for this sensor.

It seems like when I run the sample code, the controller fails to connect to the device, even when I specify the data and clock channels and clock frequency to use like I do in my little sample program.

When the sensor stops running, i have a hard time getting it to start working again.

I’m not sure how to troubleshoot this one.

Weird Observation. If I turn of the main power of the XRP, the sample code that I wrote seems to run pretty reliably. I I turn on the main power of the XRP (which connects it to the AA battery pack) it no longer works. At least this is the behavior that I’m observing at the moment.

Figured out issue. i had the wrong values for the data and clock lines. if i used lines 18 and 19 for the data and clock lines it seems to work and I can poll the device and get, for example, heading info.

X: 0.3844726 Y: -3.171899 Heading: 104.079

I think the problem has been solved. If I use 18 and 19 for my data and clock lines, the example problems now seem to work and the Optical Tracking Sensor now seems to provide me with correct data.

Here’s what I had to modify in the Qwiic_OTS_Py example program to communicate with the sensor,

my_bus = qwiic_i2c.get_i2c_driver(sda=18, scl=19, freq=100000)
myOtos = qwiic_otos.QwiicOTOS(i2c_driver=my_bus)

Once I modified this at the beginning of the example program, I was able to run the example program successfully. The code calibrated the sensor and then started displaying the pose info from the sensor.