Dual I2C DIsplays, Different Addrss- But can only push to 1 or other

Dont post to much usually can find the answers from other questions but I am stumped on this one.

I have two OLED Displays one 128x64 and a 128x32, using the adafruit SSD1306 library.
I have them setup on different addresses, but when I run the code only the first listed display in the setup will run. if i put display2 first that will run fine, or display1 that will run. Also if display2 is listed first in the setup but display1 in the loop first, display2 will show the logo but not the text, same visa versa.
Not sure what else I can do to trouble shoot, is the issue the 2 different screen sizes? i figured this wouldnt be an issue if I defined the different sizes.
Any suggestions or things I can do to troubleshoot or try would be appreciated.

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SoftwareSerial.h> 
#include <Wire.h>


#define SCREEN_WIDTH 128 // OLED display1 width, in pixels
#define SCREEN_HEIGHT 64 // OLED display1 height, in pixels
// Declaration for an SSD1306 display1 connected to I2C (SDA, SCL pins)
#define OLED_RESET    4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire,OLED_RESET);
Adafruit_SSD1306 display2(SCREEN_WIDTH, 32, &Wire,OLED_RESET);


void setup() {
  Serial.begin(115200);
  Serial.println("starting script");
    
    //SSD1306_SWITCHCAPVCC = generate display1 voltage from 3.3V internally
  if(!display1.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed 0x3D"));
   // for(;;); // Don't proceed, loop forever
  }


  if(!display2.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x32
      Serial.println(F("SSD1306 allocation failed 0x3C"));
     // for(;;); // Don't proceed, loop forever
    }
   
   
  
 
  
 
  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.

  display2.display();

  display1.display();

  // Clear the buffer
  display1.clearDisplay();
  display2.clearDisplay();

}

void loop() {
  
      
        
         display1.setTextSize(1);
        display1.setTextColor(SSD1306_WHITE,BLACK);
        display1.setCursor(0,0);
        display1.print("Display 1");
        display1.display();

          display2.setTextSize(1); 
        display2.setTextColor(SSD1306_WHITE,BLACK);
        display2.setCursor(0,0);
        display2.print("Display 2");
        display2.display();
  

}

Just do:

#define OLED_RESET    -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire,OLED_RESET);
Adafruit_SSD1306 display2(SCREEN_WIDTH, 32, &Wire,OLED_RESET);

I suspect that your displays do not even have a RES pin. i.e. regular 4-pin GND, VCC, SCL, SDA

I presume that you are using something bigger than a Uno. The two displays steal 1536 bytes of valuable SRAM.

David.

Yes the four pin oleds and I was not I was using a nano, i do have a mega and will give that a shot(that will do it though cause that only has 2k SRAM). Is there any other boards that are smaller that have more SRAM, I really dont need a mega for the project only running a GPS sensor other than the 2 displays?

_ I apologize I just googled it, found a few smaller boards that use the atmega2560, so ill grab one of those if it works.

You can use u8g2 library on your Nano. Select the small-page constructors. Then it does not use up all your SRAM.

You have to be very careful with SRAM use. Serial and SoftSerial will steal quite a bit.
Make sure that you have all the anonymous strings in Flash e.g. display.print(F("anonymous string")).
And the correct size and type of arrays.

David.

ok Taking a look at it now(U8g2 library). Opened the hello world example there is a bunch of boards here from the looks would this be the correct one to uncomment

//U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // All Boards without Reset of the Display

this is the display I have 128x64

//U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);  // Adafruit ESP8266/32u4/ARM Boards + FeatherWing OLED

and this one seems like the only approriate one for the 128x32 oled

thanks for your help, its much appreciated.

No, the F constructors use a Full size buffer like Adafruit_SSD1306.

You need the paged constructors 1 or 2 e.g.

U8G2_SSD1306_128X64_NONAME_1_HW_I2C(U8G2_R0);

There is no point in crippling yourself. Use HW_I2C pins.
Select the slave address as 0x3C for one and 0x3D for the other.

David.

ok got it now, read through the reference manual here and able to display on the Display with the 0x3C address as its first address, so to set the second address i tried using the u8g2.setI2CAddress(0x3D);

Here is what i have written

#include <Arduino.h>
#include <U8g2lib.h>


#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif



// Please UNCOMMENT one of the contructor lines below
// U8g2 Contructor List (Frame Buffer)
// The complete list is available here: https://github.com/olikraus/u8g2/wiki/u8g2setupcpp
// Please update the pin numbers according to your setup. Use U8X8_PIN_NONE if the reset pin is not connected


U8G2_SSD1306_128X64_NONAME_2_HW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // All Boards without Reset of the Display

U8G2_SSD1306_128X32_UNIVISION_2_HW_I2C u8g2_32(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED



void setup(void) {
  u8g2_32.begin();
  u8g2.setI2CAddress(0x3D);
  u8g2.begin();
  
}

void loop(void) {
  u8g2_32.clearBuffer();					// clear the internal memory
  u8g2_32.setFont(u8g2_font_ncenB08_tr);	// choose a suitable font
  u8g2_32.drawStr(0,10,"Hello World 32!");	// write something to the internal memory
  u8g2_32.sendBuffer();					// transfer internal memory to the display
  u8g2.clearBuffer();          // clear the internal memory 
  u8g2.setFont(u8g2_font_ncenB08_tr);  // choose a suitable font
  u8g2.drawStr(0,10,"Hello World 64!");  // write something to the internal memory
  u8g2.sendBuffer();
  delay(1000);  
}

Found the issue in a github post here states that it needs to be u8g2.setI2CAddress(0x3d*2);

and this worked both displays are working now.

Thanks so much david_prentice youve been a life saver