Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    I2C bus error when using _threading

    Scheduled Pinned Locked Moved WiPy 2&3
    3 Posts 2 Posters 64 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • techykermitT Offline
      techykermit
      last edited by

      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-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @techykermit
        last edited by

        @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.

        1 Reply Last reply Reply Quote 1
        • techykermitT Offline
          techykermit
          last edited by

          @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!

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom