// OLED 1 screen to STM32 I2C: PB7(SDA1), PB6(SCL1) // OLED 2 screen to STM32 I2C: PB11(SDA2), PB10(SCL2) #include TwoWire wire1(PB7, PB6); TwoWire wire2(PB11, PB10); // OLED I2C address 0x3C #include U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C oled1(U8G2_R0, U8X8_PIN_NONE); // U8G2_SSD1306_128X32_UNIVISION_F_2ND_HW_I2C oled2(U8G2_R0, U8X8_PIN_NONE); U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C oled2(U8G2_R0, PB10, PB11 , U8X8_PIN_NONE); int count = 1; void setup() { wire1.begin(); wire2.begin(); Serial.begin(115200); while (!Serial) {}; oled1.begin(); delay(10); oled2.begin(); } void loop() { delay(2000); Serial.print("oled 1 writing: "); Serial.println(count); oled1.clearBuffer(); oled1.setFont(u8g2_font_ncenB14_tr); oled1.setCursor(0, 15); oled1.print("OLED_1: "); oled1.print(count); oled1.sendBuffer(); Serial.print("oled 2 writing: "); Serial.println(count); oled2.clearBuffer(); oled2.setFont(u8g2_font_ncenB14_tr); oled2.setCursor(0, 15); oled2.print("OLED_2: "); oled2.print(count); oled2.sendBuffer(); count++; byte error1, error2, address; int n1Devices, n2Devices; Serial.println("I2C Scanning..."); n1Devices = 0; n2Devices = 0; for (address = 1; address < 127; address++ ) { wire1.beginTransmission(address); error1 = wire1.endTransmission(); // wire2.beginTransmission(address); // error2 = wire2.endTransmission(); if (error1 == 0) { Serial.print("I2C device found on I2C 1 at address 0x"); if (address < 16) Serial.print("0"); Serial.print(address, HEX); Serial.println(" !"); n1Devices++; } else if (error1 == 4) { Serial.print("Unknown error on I2C 1 at address 0x"); if (address < 16) Serial.print("0"); Serial.println(address, HEX); } /* if (error2 == 0) { Serial.print("I2C device found on I2C 2 at address 0x"); if (address < 16) Serial.print("0"); Serial.print(address, HEX); Serial.println(" !"); n2Devices++; } else if (error2 == 4) { Serial.print("Unknown error on I2C 2 at address 0x"); if (address < 16) Serial.print("0"); Serial.println(address, HEX); }*/ } if (n1Devices == 0) Serial.println("No I2C devices found on I2C 1"); else Serial.println("done I2C 1"); /*if (n2Devices == 0) Serial.println("No I2C devices found on I2C 2"); else Serial.println("done I2C 2");*/ }