Having trouble with two I2c oleds

I am trying to get two 128x64 Ic2 OLEDs to work with a nano. I get errors and can't seem to find where they are. I have read several tutorials and still can't find it. I only need both OLEDs to display the same data, which will be changed as the rest of the sketch is done.
thanks


```cpp
#include "U8glib.h"
#include "DHT.h"
#define DHTPIN 2 
#define DHTTYPE DHT22 
#define mando_width 46
#define mando_height 64
#define I2C_SLA (0x3C)
#define I2C_SLA (0x3D)
int leds[4] = {3,4,5,6};

DHT dht(DHTPIN, DHTTYPE); 
U8GLIB_SSD1306_128X64 u8g1(U8G_I2C_OPT_NO_ACK);
U8GLIB_SSD1306_128X64 u8g2(U8G_I2C_OPT_NO_ACK);

static unsigned char mando_bits[] U8G_PROGMEM = {
   
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
   0x00, 0x00, 0xfb, 0x1f, 0x00, 0x00, 0x00, 0x80, 0xfb, 0x1f, 0x00, 0x00,
   0x00, 0xc0, 0xf9, 0x1f, 0x00, 0x00, 0x00, 0xc0, 0xf3, 0x1f, 0x00, 0x00,
   0x00, 0xc0, 0xf7, 0x0f, 0x00, 0x00, 0x00, 0x80, 0xf7, 0x2f, 0x00, 0x00,
   0x00, 0x00, 0xff, 0x27, 0x00, 0x00, 0x00, 0x60, 0xfe, 0x31, 0x00, 0x00,
   0x00, 0x60, 0xfc, 0x30, 0x00, 0x00, 0x00, 0x60, 0x78, 0x70, 0x00, 0x00,
   0x00, 0x30, 0x38, 0x78, 0x00, 0x00, 0x00, 0x70, 0x38, 0x3c, 0x00, 0x00,
   0x00, 0xf0, 0x38, 0x3e, 0x00, 0x00, 0x00, 0xe0, 0xb9, 0x9f, 0x01, 0x00,
   0x00, 0xe0, 0xb3, 0xcf, 0x03, 0x00, 0x00, 0xe0, 0xbf, 0xcf, 0x03, 0x00,
   0x00, 0xd8, 0xff, 0xef, 0x07, 0x00, 0x00, 0x9e, 0xff, 0xe7, 0x0f, 0x00,
   0x00, 0x7f, 0xfe, 0xe3, 0x1f, 0x00, 0x00, 0xff, 0xfe, 0xc3, 0x1f, 0x00,
   0x80, 0xff, 0xfe, 0x83, 0x3f, 0x00, 0xc0, 0x3f, 0xfe, 0x03, 0x3f, 0x00,
   0xc0, 0x1f, 0x7e, 0x03, 0x7e, 0x00, 0xc0, 0x0f, 0x64, 0x03, 0x7e, 0x00,
   0xe0, 0x07, 0x24, 0x03, 0x7c, 0x00, 0xe0, 0x07, 0x2c, 0x01, 0xf8, 0x00,
   0xe0, 0x03, 0x2c, 0x01, 0xf8, 0x00, 0xf0, 0x01, 0xac, 0x01, 0xf0, 0x00,
   0xf0, 0x00, 0xfc, 0x01, 0xf0, 0x00, 0xf0, 0x00, 0x9c, 0x01, 0xf0, 0x00,
   0xf0, 0x00, 0x9c, 0x01, 0xf0, 0x00, 0xf0, 0x00, 0xdc, 0x01, 0xf0, 0x00,
   0xf0, 0x00, 0x9c, 0x01, 0x78, 0x00, 0xe0, 0x00, 0x90, 0x01, 0x7c, 0x00,
   0xe0, 0x01, 0xa4, 0x82, 0x3f, 0x00, 0xc0, 0x03, 0xac, 0x02, 0x07, 0x00,
   0x80, 0x7f, 0xac, 0x02, 0x00, 0x00, 0x00, 0x3f, 0xac, 0x02, 0x00, 0x00,
   0x00, 0x00, 0xac, 0x06, 0x00, 0x00, 0x00, 0x00, 0xa8, 0x06, 0x00, 0x00,
   0x00, 0x00, 0xa8, 0x06, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x02, 0x00, 0x00,
   0x00, 0x00, 0xb8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x90, 0x02, 0x00, 0x00,
   0x00, 0x00, 0xb0, 0x02, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x04, 0x00, 0x00,
   0x00, 0x00, 0xb0, 0x02, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x02, 0x00, 0x00,
   0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00,
   0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

   void draw(void) {
  // graphic commands to redraw the complete screen should be placed here 
  u8g1.drawXBMP( 35, 0, mando_width, mando_height, mando_bits); 
}
 
void setup() {
  
  dht.begin(); 

u8g1.begin();
  u8g1.firstPage();  
  do {
       draw();
  } while( u8g1.nextPage() );
  delay(5000);  
  //delay(7500); 

u8g2.begin();
  u8g2.firstPage();  
  do {
       draw();
  } while( u8g2.nextPage() );
  delay(5000);  
  //delay(7500);   
   
}
void blinker(){
   for (int jj; jj<sizeof(leds)/sizeof(int);jj++){
    pinMode(leds[jj],OUTPUT);
    //delay(10);
  }
}
void loop() {
  float hum = dht.readHumidity(); 
  float temp = dht.readTemperature(true); 
  float fah = dht.readTemperature(true);
  if (isnan(hum) || isnan(temp) || isnan(fah)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  float heat_index = dht.computeHeatIndex(fah, hum);
  float heat_indexC = dht.convertFtoC(heat_index);    //Calculating the heat index in Celsius

  digitalWrite(leds[random(0,sizeof(leds)/sizeof(int))],HIGH);
  //delay(random(20,200));
  digitalWrite(leds[random(0,sizeof(leds)/sizeof(int))],LOW);
  
  u8g1.firstPage();  
  do {
    u8g1.setFont(u8g_font_helvR12);  
    u8g1.drawStr(1, 15, "Temp:");  
    u8g1.setPrintPos(75, 15);
    u8g1.print(temp, 0);
    u8g1.print((char)176);
    u8g1.print(" F");
    
    u8g1.drawStr(4, 35, "Humi:");
    u8g1.setPrintPos(75, 35);
    u8g1.print(hum, 0);
    u8g1.print("  %");
    
    u8g1.drawStr(4, 55, "Hi:");
    u8g1.setPrintPos(75, 55);
    u8g1.print(heat_index, 0);
    u8g1.print((char)176);
    u8g1.print(" F");
  } while( u8g1.nextPage() );
  //delay(2500);
  //delay(5000);
  //delay(63);
  delay(50);
  //delay(38); // change to chang led blink speed

}

  u8g2.firstPage();  
  do {
    u8g2.setFont(u8g_font_helvR12);  
    u8g2.drawStr(1, 15, "Temp:");  
    u8g2.setPrintPos(75, 15);
    u8g2.print(temp, 0);
    u8g2.print((char)176);
    u8g2.print(" F");
    
    u8g2.drawStr(4, 35, "Humi:");
    u8g2.setPrintPos(75, 35);
    u8g2.print(hum, 0);
    u8g2.print("  %");
    
    u8g2.drawStr(4, 55, "Hi:");
    u8g2.setPrintPos(75, 55);
    u8g2.print(heat_index, 0);
    u8g2.print((char)176);
    u8g2.print(" F");
  } while( u8g2.nextPage() );
  //delay(2500);
  //delay(5000);
  //delay(63);
  delay(50);
  //delay(38); // change to chang led blink speed

}

defining two times the same macro does not make sense

Where in your code to do you specify which OLED shall use which I2C-Adress?

Does the OLED (I mean the real hardware) offer changing the I2C-adress?

So minimum you have to do is proving the datasheet of exact your OLEDs to be able to lookup if and if yes how the I2C-adress can be changed

best regards Stefan

The two I2C defines were the first thing that jumped out at me as well........

If you want the same data on the 2 Oleds , just run them in parallel on the same address.

Julian Ilett did it in one of his videos......

https://www.youtube.com/watch?v=AOcsaWT-WjY

hm - - - -
The I2C bus relies on signal change that has to be tight in sync for the SDA/SCL-line
It will be interesting to see if two I2C-devices stay so close in sync with their signal-changes that this works.

The duplicate define for I2C_SLA should not be a problem, because it is never used.

I don't think the U8g library supports multiple displays (seems there are hacks to get around this, but I'm not going to look it up). The newer U8g2 library will support multiple displays, note that setI2CAddress() must be called before begin(). Be careful to use the constructor for a paged buffer, the full buffer for two displays would need the entire dynamic memory (ram) of a Nano.

If the displays have accessible address select pins, it would be easier to use those to dynamically change the display address, and only run one instance of the display in the code. The other common method is to use an I2C multiplexer.

You have an extra closing brace ( } ) between the display loop for u8g1 and u8g2, resulting in the code being outside a function.

Unfortunately it looks like you forget to post those errors... if you do so chances are someone here will be able to pinpoint it in a second, without having to study the code.

This assuming you're talking about compiler errors, which you also didn't specify.

Solved, went with the ss_oled library.

Well if you want to contribute to the community you should
explain what is the difference that makes it work
or at least post your finally working code

Then last but not least mark the thread as solved

best regards Stefan

See two OLED with same I2C address share same data.... at 19:23...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.