Whoops, I2C Slave & OLED via I2C problem...

I believe I know the problem I’m running into… but don’t yet know a workaround.

I have two Nanos
A) Handle GPS and display(s) (set up as i2C slave sender)
B) Manage Neopixels (i2c master reader)

Nanos A and B were communicating successfully via i2c. **Then I added an i2C OLED display to A. **

The i2c interactions between A and B don’t seem to happen. I have not traced the code, but it seems apparent that I’m running into this problem because I have A set up as a i2C slave.

Would this incompatibility make sense?

The objectives here are:

  • Nano B request bytes from A, handle neopixels accordingly
  • Nano A drive i2C OLED, and respond to A

relevant code:

Nano A

byte sp[2] = {0,0};


U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST);	// Fast I2C / TWI 

void setup(){
  
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event  

}

void loop(){

}

void requestEvent() {
  sp[0] = (byte)iMph;
  sp[1] = (byte)speedLimit;  
  Wire.write(sp,2);
}

Nano B

byte sp[2] = {0,0}; // sp[0] = MPH, sp[1] = Limit

void setup() {
  Wire.begin();        // join i2c bus 	
  delay(1000);  
}

void loop() {
  Wire.requestFrom(8, 2);    // request 6 bytes from slave device #8
  int i=0;
  while (Wire.available()) { // slave may send less than requested
    sp[i] = Wire.read(); // receive a byte as character
    i++;
  }
  delay(100);
}

You can have multiple masters on an I2C bus. Every master can act as a slave, too, on the given address, when an onRequest handler is added.

Does the display have the same signal levels (Vcc) than the Nanos? Pullups installed?

You haven't showed us all of the code from Nano A. Where are 'iMph' and 'speedLimit' declared and initialised?

And how do you determine that no communication is happening? Nano B doesn't do anything with the received data in the code you posted.

You don't show your includes in either file, either.

Can we see all of your code please? (Or at least minimal compileable examples that illustrate your problem.)

Hey, thanks for the replies. I ended up swapping the slave/master around after realizing that my basis for using slave-writer/master-requester (instead of the other way around) was possibly flawed and unnecessary. All is good in this new master-writer/slave-reader configuration.