I tried to let my rpi3 with wiringPi as slave to receive data from master and data +1 send to master .

mater send 1 to slave (rpi3)

My rpi3 SDA is GPIO 18 ,SLC is GPIO 19

the code on my rpi3 :


int main(){
int fd;
fd = wiringPiI2CSetup(0x35); //0x35 is my slave address  
int cont=0;

cont = wiringPiI2CReadReg8(fd,0x55); //0x55 is my regaddress
printf("readValue:%d\n",cont);//receive data from my master 
wiringPiI2CWriteReg8(fd,0x55,cont++);//send data to master 

return 0;

However it only show -1 , mean error

I tried to change SDA,SCL pin to GPIO 3 (SDA),5 (SCL) it would show 0 ,but it couldn't receive data

Any help on what Im doing wrong will be appreciated.

1 Answer 1


wiringPi does not support I2C slave mode. It only supports using the Raspberry Pi as an I2C bus master.

This in part is because wiringPi uses the underlying Linux I2C driver which only supports master mode.

  • Can you recommend any libraries that support rpi use i2c to be slave ? I knew that python had the pigpio library and use the bsc_i2c , but I had tried it and failed
    – 林柏逸
    Commented Aug 15, 2019 at 19:13
  • As far as I am aware (my) pigpio is your only choice (unless you write your own software).
    – joan
    Commented Aug 15, 2019 at 19:57

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.