0

Is PCA9685 code thread safe?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Is PCA9685 code thread safe?

by tigrezno on Sat Feb 06, 2021 12:27 pm

I'm making a threaded app on a raspberry pi that access the i2c bus from several threads. I'm using a PCA9685 and an ADS1115 (circuitpython).

I'm getting i2c errors and I suspect it's due to concurrently accessing the i2c bus.

Anyone knows if I should use locks?
tigrezno
 
Posts: 9
Joined: Thu Jun 05, 2008 10:07 am

Re: Is PCA9685 code thread safe?

by adafruit_support_bill on Thu Feb 18, 2021 6:59 am

If you think about it, it is not possible to make libraries for i2c devices (or serial devices in general) thread-safe for the general case.

Assuming that you could make bus transactions atomic at the i2c level, what constitutes an atomic operation at the device level may not be limited to a single bus transaction.

Further assuming that you could get all library authors to play be the same synchronization rules, you would still have the issue that what constitutes an atomic operation at the application level may not be limited to what is atomic at the device level.

If you want to have multi-threaded access to bus devices, you will need to synchronize them at the application level.

adafruit_support_bill
 
Posts: 80361
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.