I2C bus error when using _threading



  • Hi! I'm reading a couple of sensors using a function I call sensor_read() that then updates some global variables. When running it non-threaded, reading one bus at a time, I get no errors. However, when trying to read two buses (on the same pins) at once, I get I2C Bus Error from both of the devices I am trying to read data from.

    How can I solve this? Is there any particular reason for why the function works non-threaded but not threaded?



  • @robert-hh said in I2C bus error when using _threading:

    @techykermit I assume that both threads try to use the bus at the same time. That is not possible. So you must serialize the access, e.g. by using a semaphore. For that, the _thread class provides the lock methods. Note that the acquired lock has to be a global object visible to both threads.

    Aha, I see. I will look into the lock method then, thank you for your help!



  • @techykermit I assume that both threads try to use the bus at the same time. That is not possible. So you must serialize the access, e.g. by using a semaphore. For that, the _thread class provides the lock methods. Note that the acquired lock has to be a global object visible to both threads.


Log in to reply
 

Pycom on Twitter