First post here on the forum! Been getting a lot of help here from all the past posts and I am grateful for such a great community.

I have been trying to use Repeated Start by using the PIGPIO library using bitbanging.

However, I have not been able to get it working and I keep getting:

-82 error: i2c write failed.

For example, when I try to initialize the RGB sensor using the following line:

err = bbI2CZip(2,RGB_init_buf,sizeof(RGB_init_buf),NULL,0);

with the following initialization buffer:

char RGB_init_buf[] = {4, RGB_ADDR,  // set up Chip address
                   2, 7, 2, (RGB_COMMAND_BIT | TCS34725_ATIME), 0xEB, 3,   // 
                   2, 7, 2, (RGB_COMMAND_BIT | TCS34725_CONFIG), 0x00, 3, // 
                   2, 7, 2, (RGB_COMMAND_BIT | TCS34725_CONTROL), 0x01, 3, // 
           2, 7, 2, (RGB_COMMAND_BIT | TCS34725_ENABLE), TCS34725_ENABLE_PON,3, //power on
                   0 // EOL

I get an error code of -82, corresponding to a failed I2C write.

I set up my I2C bus as follows:

if (gpioInitialise() < 0) {
     printf("Pigpio library initialization failed\n");
     return -1;

if (bbI2COpen(2,3,100000) != 0){
     printf("Bit Banging initialization failed\n");
     return -1;

Anyone have any idea what could be problem?

  • 2
    There are no repeated starts being used. Each start (2) is followed by a stop (3) with an intervening write of two bytes to the device (7 2 x y). Try sending the individual commands with pigs i2cwd as that will achieve the same affect and may show which write is failing. This assumes the device is visible to i2cdetect.
    – joan
    Feb 1, 2016 at 9:08
  • 2
    Hi Thomas, welcome to Raspberry PI SE! Just to warn you, as I was told many moons ago, this is a Q&A site, not a forum... :-) Feb 1, 2016 at 9:12
  • Why are you trying to bitbang I2C when there is an I2C port on the Raspberry Pi?
    – NomadMaker
    Jan 28, 2018 at 23:22

1 Answer 1


Are you sure that you have the right value for RGB_ADDR? Whenever I have seen a -82 error with pigpio it has been because the I2C chip is not responding. This is usually because you are using the wrong address. Another possibility is that SCL/SDA are swapped. Note that the data array expects a 7 bit address and pigpio automatically appends the correct read/write bit to create the 8 bit address/RW value used to access the slave.

Also, as joan noted above, you do not have any actual repeated starts in your array.

Typically a repeated start is used to read a register after writing the register number. It is specified by byte array data in the format shown below:

  ...   2, 7, 1, regnum, 2, 6, nbytes, 3, ...

The initial "2, 7, 1" is start, write, byte count 1, followed by the 1 byte register number. The "2, 6, nbytes, 3" is a repeated start followed by a read of nbytes followed by a stop.

Note that you must specify an address of a buffer to receive the read data.

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.