I'm trying to use i2c to exchange messages between 3 raspberry pi, all of them must receive a message do something and then send a response.
Raspberry as an I2C SLAVE From here I came up with a solution. First I tested with two raspberry pi and it worked by connecting the 2/3 pin from one raspberry pi to the 18/19 pin from the other and vice versa. This worked flawlessly.
When I tried to connect the third raspberry pi this is where things start to get weird. From two raspberry pi I can see all the other two and my slave address, but from the third, I can only see my address and another raspberry pi. In this case, I connected all the 2/3 and 18/19 together.
This is the code I'm running to make them slave:
import time import pigpio #SDA11=2 SDA=18 #SCL11=3 SCL=19 I2C_ADDR = 9 def i2c(id, tick): global pi s, b, d = pi.bsc_i2c(I2C_ADDR) if b: print("d", d) s1, b1, d1 = pi.bsc_i2c(I2C_ADDR) if b1: print("d1", d1) received = d + d1 print(received) pi = pigpio.pi() if not pi.connected: exit() # Add pull-ups in case external pull-ups haven't been added pi.set_pull_up_down(SDA, pigpio.PUD_UP) pi.set_pull_up_down(SCL, pigpio.PUD_UP) # Respond to BSC slave activity e = pi.event_callback(pigpio.EVENT_BSC, i2c) pi.bsc_i2c(I2C_ADDR) # Configure BSC as I2C slave time.sleep(600) e.cancel() pi.bsc_i2c(0) # Disable BSC peripheral pi.stop()
In order to check the address I use the i2cdetect -y 1 command. It is important to say that I change the I2C address from each script. Can anyone tell me what I am doing wrong?