Conflict Between RadioHead and SH1106 Libraries

I’d like to get both RadioHead and SH1106 OLED libraries working together on a classic Nano v3.0, but test code I’ve written produces a conflict in setup(). Test sketches using RadioHead, and the SH1106 libraries separately work fine. The problem shows up when I combine them into a single sketch. The problem is different depending on the baud rate i set for Serial.begin(). 9600 Baud causes a crash, and any Baud rate above that causes an endless loop in Setup(). I do have the same result using an UNO R3. The modules I have attached are a SRX882 transmitter, and a 1.3” OLED 128x64 SH1106. The code below documents the problems.

/**
  24Mar2026 - Test RadioHead and SH1106 libraries working together. There appears to be a conflict, because
              both work independently, but not together. 
*/

#include <RH_ASK.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>

#define SRX882_PIN     9

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // Reset pin not used with I2C

Adafruit_SH1106G display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
RH_ASK rf_driver(2000, SRX882_PIN, 0);

void setup() {
  Serial.begin(115200);
  delay(1000);  //<<<< tried no delay, 100, 500, 1000

  Serial.println(F("SH1106 OLED Test"));   //<<<<<< CRASHES HERE AT 9600 BAUD AFTER PRINTING SH1106
  Serial.println(F("AAA"));
  Serial.println(F("BBB"));
  Serial.println(F("CCC"));
  Serial.println(F("DDD"));

  if(!display.begin(0x3C, true)) { //<<<<<< ABOVE 9600 BAUD IT ENTERS A CONTINUOUS SETUP CYCLE 
    Serial.println(F("FAILURE - SH1106 allocation"));
//    for(;;);
  } else {
    Serial.println(F("SUCCESS - SH1106 allocation"));
  }
  Serial.println(F("EEE"));

  // never gets this far - continuously prints the first five log lines:
  //SH1106 OLED Test
  //AAA
  //BBB
  //CCC
  //DDD


  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SH110X_WHITE);
  display.setCursor(0, 10);
  display.println("Hello World");
  display.display();

}

void loop() {
}

Describe that in more detail please.

This is a misleading clue. Characters sent to the serial monitor first go into a buffer in the Arduino's memory and are then sent to serial monitor as a 'background task'. At low baud rates, those characters stay in the buffer for longer before they actually get sent to serial monitor. Meanwhile, your code continues executing. So the "crash" may be happening on some later line of code than it might appear. You can prove this to yourself by adding a Serial.flush(); after each Serial.print(). That forces the Arduino to wait until all the text has been sent to serial monitor before moving on to the next line of code.

There are no loops in your setup() code. So you mean setup() runs over and over? That would mean that the Arduino is continually resetting.

The compile results for an Uno

Sketch uses 17156 bytes (53%) of program storage space. Maximum is 32256 bytes.
Global variables use 999 bytes (48%) of dynamic memory, leaving 1049 bytes for local variables. Maximum is 2048 bytes.

The Adafruit library uses dynamic memory allocation for the display so you have to add 128x64x8 bits = 1024 bytes of RAM to the global variables.
And only having 25 bytes left for a running sketch is usually not enough for stable operation; you're running out of memory.

@bobc02 you could try switching from Adafruit library to U8G2 library. This library can be configured to use much less memory (at the cost of lower performance, which may not be an issue here).

What do you plan to use the OLED for, in the completed project? Graphics or just text?

Yes, you are running out of dynamic memory. One solution is to use a text-only display library, which does not allocate memory at runtime.

Better, use a modern Arduino-compatible MCU with more memory.

I’ll answer the accumulated questions from all of you responders here. I appreciate you all looking into this!

I didn’t realize that the compile results don’t include the 1024 bytes for the Adafruit lib - that solves it, and thanks for pointing that out!

I only need text display, no graphics. I will switch to U8G2 and see how that goes.

I am using the ancient NANO v3.0 to keep costs to a minimum. I am researching the feasibility of providing a low-cost (sub USD $50) TX/RX system for our 120 household, 50 year old, community well system for semi-automatic monthly meter readings. Members are facing mounting monthly costs, so everything we can do to reduce the costs is a benefit. I do realize that existing systems exist for automated readings, but the per member costs for acquisition and installation is steep. With a system of our age, we have large infrastructure costs that have doubled our monthly bills during the past four years, and we expect another doubling over the next four.

Thanks again - you guys are great!

Have you tried your out-of-memory sketch using u8x8 (text only) library? I was having memory issues with a Nano R3 using OLED and NeoPixel and Adafruit, so I tried u8x8 and had no problem with out-of-memory. I used "underline" and "pipe" to draw lines on the OLED. u8x8reference · olikraus/u8g2 Wiki · GitHub

Or, any ESP32 and have no memory problem (but has a different logic level than Nano R3).

All is working fine now with the U8G2 library running in Page Buffer Mode 1.