2 OLED screens, script runs but at wrong resolution

Hi all, super new to all this, I am doing a little project, I am running to OLED displays, 128 x 64

one is in 3C and other in 3D, that much I know, when I run the script with resolution 128 x 32 it will run both screens steadily but when I try to run it in full resolution, the script stalls and the 2 screens flicker back and forth, can not get passed this, I’m posting a portion of what I need to fix, my final script has much more stuff in it but I need this working first, any thoughts?? / thanks for the help

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <math.h>

#define OLED_RESET 4
#define SCREEN_WIDTH 128            // OLED display width, in pixels
#define SCREEN_HEIGHT 64            // OLED display height, in pixels
#define thermistor_output A0        // What pin to connect thermistor
#define NUM_SAMPLES 20             // number of analog samples to take per reading

// Setting value types
  int sensorPin = A0;
  int sensorValue = 0;
  int thermistor_adc_val;

//Adafruit_SSD1306 display1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display1(OLED_RESET);
Adafruit_SSD1306 display2(OLED_RESET);



void setup()   {
  //Serial.begin(9600);

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display1.begin();
  display2.begin();
  display1.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display2.begin(SSD1306_SWITCHCAPVCC, 0x3D);  // initialize with the I2C addr 0x3D (for the 128x64)
  // init done

  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  //display2.display();
 // display1.begin();
  //delay(50);
  display1.clearDisplay();
  display2.clearDisplay();
}

 void loop() {

  
  double output_voltage, thermistor_resistance, therm_res_ln, temperature, tempf; 
  
  thermistor_adc_val = analogRead(thermistor_output);
  output_voltage = ( (thermistor_adc_val * 5.0) / 1024.0 );
  thermistor_resistance = ( ( 5 * ( 10.0 / output_voltage ) ) - 10 ); /* Resistance in kilo ohms */
  thermistor_resistance = thermistor_resistance * 1000 ; /* Resistance in ohms   */
  therm_res_ln = log(thermistor_resistance);
    /*  Steinhart-Hart Thermistor Equation: */
  /*  Temperature in Kelvin = 1 / (A + B[ln(R)] + C[ln(R)]^3)   */
  /*  where A = 0.001129148, B = 0.000234125 and C = 8.76741*10^-8  */
  temperature = ( 1 / ( 0.001129148 + ( 0.000234125 * therm_res_ln ) + ( 0.0000000876741 * therm_res_ln * therm_res_ln * therm_res_ln ) ) ); /* Temperature in Kelvin */
  temperature = temperature - 273.15; /* Temperature in degree Celsius */
  //temperature = (temperature * 1.8) + 32; // uncomment to convert temperature to F
  tempf = (temperature * 1.8) + 32; // uncomment to convert temperature to F
  float temp2graph = temperature * 3.2; // conversion scale to make 0 - 40 degrees = 0 - 128 on OLED display


  display1.clearDisplay();
  display1.drawRect(0, 0, temp2graph, 10, WHITE);  // draw rectangle ( start point x,start point y, end point x,endpoint y, color)
  display1.setTextColor(WHITE);
  display1.setTextSize(1);
  display1.setCursor(26,20);
  display1.print("10C");
  display1.setCursor(58,20);
  display1.print("20C");
  display1.setCursor(90,20);
  display1.print("30C");
  display1.setCursor(0,48);
  display1.print("Temperature:"); 
  display1.setCursor(78,10);
  display1.print(temperature,2);                    // reading is the answer but the 0 is decimal places, (reading, 1) would display the tenths (reading) would display hundreths
  delay(10);                                    // Small delay for stability

  display2.clearDisplay();
  display2.drawRect(0, 0, temp2graph, 10, WHITE);  // draw rectangle ( start point x,start point y, end point x,endpoint y, color)
  display2.setTextColor(WHITE);
  display2.setTextSize(1);
  display2.setCursor(26,20);
  display2.print("10C");
  display2.setCursor(58,20);
  display2.print("20C");
  display2.setCursor(90,20);
  display2.print("30C");
  display2.setCursor(0,48);
  display2.print("Temperature:"); 
  display2.setCursor(78,10);
  display2.print(tempf,2);                    // reading is the answer but the 0 is decimal places, (reading, 1) would display the tenths (reading) would display hundreths
  delay(10);                                    // Small delay for stability

  display1.display();
  display2.display();
  }

I've not used two OLEDs at one time but I'm current using an OLED and a Sensor on the same I2C with no issues.

I would suggest two troubleshooting approaches:

  1. add long delays (200 ms?) between any display1 and display2 statements.

  2. write something to display1 in the setup and write only to display2 in the loop.

What I2C speed are you using? I'm using 100k (default). Could you be trying to go too fast?

It is quite simple. 128x32 requires 512 bytes for its buffer. 128x64 requires 1024 bytes. Two 128x64 screens will use all 2048 bytes of SRAM in a Uno.

I would expect your program to work fine on Zero or Due or even Mega2560.

If you want to run on an Arduino with 2kB SRAM look at U8g2lib.
U8g2lib can work with small buffers but has different names for its methods.

So you would need to re-write your sketch to suit U8g2lib style.

David.

If you’re just drawing text, my multi_oled library can do what you want without needing much RAM. You can find it here:

Larry’s Multi-OLED library

Special thanks to David_prentice, although I tried many of all suggestions received the culprit in this case was a memory issue, I searched far and wide to solve this but always overlooked buffer capabilities, I loaded the script onto my Mega2560 and it runs as I intended or thought it would run from a programming stand point, Thanks again to all,

Have you considered an ESP?

Not sure what ESP is thanks

An ESP8266 module:

Plenty of memory, not so many I/O but easily expandable via I2C and I presume adequate for your purpose. Uses little power unless you want to use its WiFi capability.