Problem using OLED and Fingerprint sensor at the same time

Hi, I've been trying to use an OLED display with a Fingerprint sensor, both of them are working well individually, but when I try to work with them in the same code, It is impossible to detect the OLED. What am I doing wrong? Also, It shows that the oled is working correctly If i just run the "tryoled" even if it is not connected

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

SoftwareSerial sensorSerial(2, 3); // RX, TX
Adafruit_Fingerprint finger(&sensorSerial);

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  Serial.begin(9600);
  sensorSerial.begin(57600);  // Start communication with the fingerprint sensor
  delay(100);  // Small delay before initializing the OLED
  tryoled();   // Initialize the OLED display
  delay(200);  // Small delay after OLED before initializing the fingerprint sensor
  tryfinger(); // Initialize the fingerprint sensor
}

void loop() {
  // You can add more logic here if needed
}

void tryfinger() {
  if (finger.verifyPassword()) {
    Serial.println("Fingerprint sensor detected!");
  } else {
    Serial.println("Error: Fingerprint sensor not detected");
  }
}

void tryoled() {
  Serial.println("Searching for OLED...");

  // Try to initialize the OLED
  if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDRESS)) {
    Serial.println("❌ OLED NOT detected.");
    // Do not stop the program, simply exit the function
    return;
  }

  Serial.println("✅ OLED detected successfully.");

  // Display message on the OLED
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("OLED OK!");
  display.display();
}

Hi, @juaaaaaaaaan22 !

From your code, it seems you are using an ARDUINO.
But what Arduino? Are you sure it has the resources to run the fingerprint and the OLED simultaneously?

The printed response is not accurate. There is not even any way to actually detect the SSD1306; the modules are write only. What a false return from being really means is that there wasn't 1K of RAM free to allocate as a screen buffer. That's what's failing; your sketch doesn't have enough free RAM after whatever your fingerprint sensor and SoftwareSerial have gobbled up.

It is an Arduino UNO. I'm not sure about it. I thought that it should have the enough resources, but now I'm considering using another board.
Also, the answer from @van_der_decken says that the sketch doesn't have enough RAM

I've seen projects of people using both components connected at the same arduino Uno, so I would expect it to work properly

The only way begin returns false is if it can't allocate 1K of RAM. That's based on reading the library source code, not on "what I expect it do it." But suit yourself. It's your time you're wasting, not mine.

It can easily be done with a different library for the display, that does not need the 1024 bytes of ram for the buffer. Just using the F() macro for the print() statements in your code saves enough memory to get past the "OLED NOT detected" point, although with that little spare memory I doubt the code would work once you actually start using the fingerprint reader.

Where?