Some I2C trouble with the TCT40 Ultrasonic sensor

I’ve been trying to trigger this sensor every 10ms and it often results in a bunch of I2C errors. Some deeper investigation determined that at 10ms the ultrasonic pulse has only traveled ~3.4m (so it would have returned only of there was an object 1.7m away), so it’s likely that the device was still waiting for a previous echo to return when I triggered it again.

After unplugging the device and resetting the polling rate to 20ms it performs more smoothly but still occasionally locks up.

I’ve looked at the product page, but I haven’t found any docs explaining what the max polling rate is or if there’s any way to control the timeout. Are there SparkFun employees on this forum who might be able to provide the answers?

Relevant product page: https://www.sparkfun.com/sparkfun-ultrasonic-distance-sensor-tct40-qwiic.html

If you’d be so kind, I’d also like to know exactly how “triggerAndRead” works, because it seems to return instantly, but as demonstrated above it takes some ms for a pulse to return so clearly there’s something going on under the hood. Is the device continuously polling and just returning the last known value?

It’d depend on the use-case…20ms is pretty quick, considering the travel time of the pulse (as you’ve mentioned), ~50Hz is impressive

As far as I can tell, triggerAndRead() attempts to read the last-filled buffer and trigger a new reading that should reset the currently-unfilled buffer to clear it for the newly requested reading…the instantly returned one should be the last full buffer, you can try testing to confirm