I have an python daemon running on Raspberry Pi. The daemon reads and writes value to chip connected with I2C bus. The chips are:

  • MCP23008 (digital IO)
  • MCP3428 (analog in)
  • MCP4728 (analog out)

The daemon has a monitoring thread that performs read on the chips, sleeps for some time and repeats. If any change occurs, it's notified to a remote host.

Some time ago I've encountered an issue. Monitoring thread stopped reporting any value change. I think that it was stuck on some I2C IO operation, since there is no other blocking operations in it.

I did some research and discovered that I2C specification does not have any timeout condition (http://www.i2c-bus.org/i2c-primer/obscure-problems/ and SMBus specs at page 58). The problem happened once and on prototype board, whose wiring is surely not perfect.

In addition, two different libraries are user for I2C communication. For MCP3428 python-smbus is used. For MCP4728 python-pigpio is used. This choice derives from the fact that MCP4728 need some commands that does not fit SMBUS transmission paradigm. I don't know if there can be a conflict of any kind.

I want to protect my daemon from such issue. So I have several questions:

  • how do I recover from such a blockage?
    • do I need to close/open I2C handle?
    • or reset I2C bus?
    • or reset the whole system?
  • do pigpio library has the possibility to set read/write timeouts?


1 Answer 1


You need to find out what, if anything, is blocking.

In my experience Linux driver I2C problems usually return IO error 5.

The pigpio i2c* functions use the Linux I2C driver.

The pigpio bb_i2c* functions use bit banging and there is a 10ms timeout per bit (which I will probably make considerably larger).

  • joan, so you are suggesting that I should look elsewhere to find the block, since Linux I2C driver returns error in case on problems? Is there any documentation for the error management in this driver? Sep 14, 2016 at 15:25
  • 1
    @DanTumaykin I don't know what might happen with the Linux driver. I don't know if it will timeout or not. I just mean to say you need to confirm the function which blocks, otherwise you might be solving the wrong problem. You probably need to add diagnostic prints.
    – joan
    Sep 14, 2016 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.